Federer falls to Thiem in 3-set marathon in Madrid