// File: /workspace/github_cpp_makefile_star2_O3/silverneko[P]Lambda-calculus-interpreter/src/main.cpp
// Function: normalForm(Expression const&, Context const&)
Object normalForm(const Expression& expr, const Context& env){
  switch( expr.type ){
    case Expression::Constant:
      return makeNormalForm( expr );
      break;
    case Expression::Var:
      if( env.exist(expr.name) ){
        Object &res = env[expr.name];
        if( res.isNormalForm() )
          return res;
        if( res.isPrimitive() )
          return res;
        return res = normalForm( res.expr(), res.env() );
      }else{
        return makeNormalForm( expr );
      }
      break;
    case Expression::Lambda:
      {
        Expression expr2(expr);
        expr2.body = new Expression(normalForm(*expr.body, env.erase( expr.name )).expr());
        return makeNormalForm( expr2 );
      // return Object(expr2, env);
      }
      break;
    case Expression::Ap:
      {
        const Expression& body = *expr.body;
        const Expression& arg = *expr.arg;
        Object callee(weakNormalForm(body, env));
        if( callee.callable() ){
          Object res = callee.call(arg, env);
          if( res.isNormalForm() )
            return res;
          if( res.isPrimitive() )
            return res;
          return normalForm(res.expr(), res.env());
        }else{
          Expression expr2(Expression::Ap);
          expr2.body = new Expression(callee.expr());
          expr2.arg = new Expression(normalForm(arg, env).expr());
          return makeNormalForm( expr2 );
        }
      }
      break;
    case Expression::Nothing:
      cerr << "[Normal form] Unexpected expression type: " << expr.type << endl;
      exit(1);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movl (%rsi), %eax
leaq 0xa06b(%rip), %rcx      # 0xf018
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rdi
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
callq 0x46a0
testb %al, %al
je 0x505c
addq $0x8, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x45bc
movq %rax, %r14
movl (%rax), %eax
testl %eax, %eax
je 0x53af
cmpl $0x2, %eax
jne 0x5416
movl $0x2, (%rbx)
movq 0x8(%r14), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %r15
leaq 0x20(%rbx), %r12
movq %r12, 0x10(%rbx)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f6e
movups 0x30(%r14), %xmm0
movups %xmm0, 0x30(%rbx)
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rax
movq %rcx, 0x40(%rbx)
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x5657
movq 0xff75(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x5653
incl 0x8(%rax)
jmp 0x5657
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0x9ab0
jmp 0x563e
movq 0x28(%r12), %rsi
movq 0x30(%r12), %r15
leaq 0x80(%rsp), %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x4899
cmpl $0x0, (%r12)
sete %al
movl 0x8(%r12), %ebp
cmpl $0x3, %ebp
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x525a
leaq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x473a
movl 0x8(%rsp), %eax
testl %eax, %eax
je 0x54f6
cmpl $0x2, %eax
jne 0x5554
movl $0x2, (%rbx)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %rdi
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rbx)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
jmp 0x5523
leaq 0x10(%rsp), %rdi
movl $0x3, -0x8(%rdi)
movl 0x4(%r12), %eax
movl %eax, -0x4(%rdi)
leaq 0x20(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
addq %rsi, %rdx
callq 0x9f6e
movq 0x28(%r12), %r13
movq %r13, 0x10(%rbp)
movq 0x30(%r12), %rax
movq %rax, 0x18(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %r15
addq $0x8, %r12
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x4522
leaq 0x80(%rsp), %rdi
leaq 0xf0(%rsp), %rdx
movq %r13, %rsi
callq 0x4f8a
movq 0x88(%rsp), %rax
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
movups 0xb0(%rsp), %xmm0
movups %xmm0, 0x28(%r15)
movq %r15, 0x30(%rsp)
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x51eb
leaq 0xd0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x51fd
callq 0x9e7a
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x521e
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x31d0
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0x5230
callq 0x9e7a
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x9ab0
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x563e
movq 0x20(%rsp), %rsi
jmp 0x5636
leaq 0x108(%rsp), %r13
movl $0x4, -0x18(%r13)
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r13)
movl $0x38, %edi
callq 0x31c0
movq %rax, %r12
movl %ebp, (%rax)
movl 0x8c(%rsp), %eax
movl %eax, 0x4(%r12)
leaq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
movq %rax, 0x8(%r12)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
movups 0xb0(%rsp), %xmm0
movups %xmm0, 0x28(%r12)
movq %r12, 0x118(%rsp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %r12
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4f8a
movq 0x10(%rsp), %rax
movq %rax, (%r12)
leaq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
movq %rax, 0x8(%r12)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x28(%r12)
movq %r12, 0x120(%rsp)
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x5352
leaq 0x58(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x5361
callq 0x9e7a
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x537c
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31d0
leaq 0xf0(%rsp), %rdx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x9ab0
movq 0xf8(%rsp), %rdi
cmpq %r13, %rdi
je 0x55ec
movq 0x108(%rsp), %rsi
jmp 0x55e4
movl $0x0, (%rbx)
movq 0x8(%r14), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %r15
leaq 0x20(%rbx), %r12
movq %r12, 0x10(%rbx)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f6e
movups 0x30(%r14), %xmm0
movups %xmm0, 0x30(%rbx)
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rax
movq %rcx, 0x40(%rbx)
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x566d
movq 0xfbbb(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x5669
incl 0x8(%rax)
jmp 0x566d
leaq 0x8(%r14), %rsi
leaq 0x40(%r14), %r12
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
callq 0x4f8a
movl (%r15), %eax
movl %eax, (%r14)
movq 0x8(%r15), %rax
movq %rax, 0x8(%r14)
leaq 0x10(%r14), %rdi
leaq 0x90(%rsp), %rsi
callq 0x30f0
leaq 0xc8(%rsp), %rsi
movups -0x18(%rsi), %xmm0
movups %xmm0, 0x30(%r14)
movq -0x8(%rsi), %rax
movq %rax, 0x40(%r14)
leaq 0x48(%r14), %r15
movq %r15, %rdi
callq 0x9e30
leaq 0x50(%r14), %rbp
leaq 0xd0(%rsp), %rsi
movq %rbp, %rdi
callq 0x9eea
movl (%r14), %eax
movl %eax, (%rbx)
movq 0x8(%r14), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %r13
leaq 0x20(%rbx), %rax
movq %rax, 0x78(%rsp)
movq %rax, 0x10(%rbx)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x9f6e
addq $0x30, %r14
movups (%r14), %xmm0
movups %xmm0, 0x30(%rbx)
movq (%r12), %rcx
movq (%r15), %rax
movq %rcx, 0x40(%rbx)
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x5683
movq 0xfadb(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x567f
incl 0x8(%rax)
jmp 0x5683
movl $0x0, (%rbx)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %rdi
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rbx)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x30(%rbx)
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x40(%rbx)
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x5585
movq 0xfa76(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x5581
incl 0x8(%rax)
jmp 0x5585
leaq 0x10(%rsp), %rsi
leaq 0x48(%rsp), %rdx
movq %rbx, %rdi
callq 0x4f8a
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x55c2
leaq 0x58(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x55c2
lock
incl 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rbx)
movq $0x0, 0x60(%rbx)
movq 0x70(%rsp), %rax
movq %rax, 0x68(%rbx)
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x55c2
leaq 0x50(%rbx), %rdx
leaq 0x68(%rsp), %rcx
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rdx)
movq %rax, 0x60(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x55d1
callq 0x9e7a
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x55ec
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31d0
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x560b
leaq 0xd0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x561d
callq 0x9e7a
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x563e
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x31d0
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
lock
incl 0x8(%rax)
leaq 0x50(%rbx), %rdi
addq $0x50, %r14
movq %r14, %rsi
callq 0x9dd2
jmp 0x563e
lock
incl 0x8(%rax)
leaq 0x50(%rbx), %rdi
addq $0x50, %r14
movq %r14, %rsi
callq 0x9dd2
jmp 0x563e
lock
incl 0x8(%rax)
leaq 0x50(%rbx), %rdi
movq %rbp, %rsi
callq 0x9dd2
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x560b
leaq 0xd0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x560b
movq 0xf932(%rip), %rdi      # 0x14ff0
leaq 0x9d30(%rip), %rsi      # 0xf3f5
callq 0x31b0
movl (%r12), %esi
movq %rax, %rdi
callq 0x32c0
movq %rax, %rdi
callq 0x30d0
movl $0x1, %edi
callq 0x3200
jmp 0x5784
jmp 0x5784
movq %rax, %r14
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x5703
callq 0x9e7a
movq (%r13), %rdi
cmpq 0x78(%rsp), %rdi
je 0x57e7
movq 0x78(%rsp), %rax
movq (%rax), %rsi
jmp 0x57df
jmp 0x5721
movq %rax, %r14
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x5732
callq 0x9e7a
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x5810
movq (%r12), %rsi
jmp 0x5808
jmp 0x5784
jmp 0x577d
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x9a64
jmp 0x576e
jmp 0x576b
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x9a64
jmp 0x57e7
movq %rax, %r14
movl $0x38, %esi
movq %r12, %rdi
callq 0x31d0
jmp 0x57ca
movq %rax, %r14
jmp 0x57e7
jmp 0x5784
movq %rax, %rdi
callq 0x9c1b
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x9a64
jmp 0x57a1
movq %rax, %r14
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0x57b8
callq 0x9e7a
jmp 0x57b8
movq %rax, %r14
movl $0x38, %esi
movq %r15, %rdi
callq 0x31d0
jmp 0x57f9
movq %rax, %r14
movq 0xf8(%rsp), %rdi
cmpq %r13, %rdi
je 0x57e7
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x31d0
leaq 0x80(%rsp), %rdi
callq 0x9a64
jmp 0x5810
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5810
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x31d0
movq %r14, %rdi
callq 0x32d0