Why does this stateful lambda function compile to assembly code