President insists polling suggests he could have bested Republican rival and secured second term as he ponders legacy ahead of White House exit