In the presence of alkylation happens at the secondary amine. This denotes that compound Y comprises a secondary amine group that gets subjected to alkylation leading to the formation of cocaine. The possible structure of Y and the chemical reaction can be given as:

Possible structure of Y
The PhCOOCOPh acquires acidic proton from the alcoholic group leading to the formation of benzoic anhydride. Hence, compound X contains an alcoholic group. The structure of X and the chemical reaction can be given as:

Structure of X
The reaction for the formation of cinnamoylcocaine can be given as:

Reaction for the formation of cinnamoylcocaine