title: C++ Lambda Generated ASM code
body: <p>I have below initial C++ code:</p>
  
  <pre><code>class Lambda
  {
  public:
      int compute(int &amp;value){
          auto get = [&amp;value]() -&gt; int {
              return 11 * value;
          };
          return get();
      }
  };
  
  int main(){
      Lambda lambda;
      int value = 77;
      return lambda.compute(value);
  }
  </code></pre>
  
  <p>which compiled (using -O1) with clang generates below ASM:</p>
  
  <pre><code>main: # @main
    push rax
    mov dword ptr [rsp + 4], 77
    mov rdi, rsp
    lea rsi, [rsp + 4]
    call Lambda::compute(int&amp;)
    pop rcx
    ret
  Lambda::compute(int&amp;): # @Lambda::compute(int&amp;)
    push rax
    mov qword ptr [rsp], rsi
    mov rdi, rsp
    call Lambda::compute(int&amp;)::{lambda()#1}::operator()() const
    pop rcx
    ret
  Lambda::compute(int&amp;)::{lambda()#1}::operator()() const: # @Lambda::compute(int&amp;)::{lambda()#1}::operator()() const
    mov rax, qword ptr [rdi]
    mov eax, dword ptr [rax]
    lea ecx, [rax + 4*rax]
    lea eax, [rax + 2*rcx]
    ret
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>What is the <code>{lambda()#1}</code> which appears in the ASM? To my knowledge it might be an closure which encapsulates the function object (i.e. lambda body).
  Please confirm if so.</li>
  <li>Is a new closure generated every time <code>compute()</code> is triggered? Or is the same instance?</li>
  </ol>