AMD interview question

optimize the code given