How to remove the automated code posted in functions.php?

You could always diff your most recent working backup with the infected website. You do have a backup don’t you?