// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movl (%rsi), %eax
leaq 0xa276(%rip), %rcx      # 0xf018
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
leaq 0x8(%r12), %r15
movq (%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x778c
testb %al, %al
je 0x4e56
movq %r14, %rdi
movq %r15, %rsi
callq 0x449e
movq %rax, %r14
movl (%rax), %eax
testl %eax, %eax
je 0x51bf
cmpl $0x2, %eax
jne 0x522f
movl %eax, (%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%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 0xa0a0
movq 0x30(%r14), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%r14), %rax
movq %rax, 0x38(%rbx)
movq 0x40(%r14), %rax
movq %rax, 0x40(%rbx)
movq 0x48(%r14), %rax
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x547d
movq 0x1017b(%rip), %rcx     # 0x14fc0
cmpb $0x0, (%rcx)
je 0x5479
incl 0x8(%rax)
jmp 0x547d
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0x9bd4
jmp 0x5464
movq 0x28(%r12), %rsi
movq 0x30(%r12), %r15
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x4677
cmpl $0x0, (%r12)
sete %al
movl 0x8(%r12), %ebp
cmpl $0x3, %ebp
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x5052
movq %rsp, %rdi
leaq 0x70(%rsp), %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x4518
movl (%rsp), %eax
testl %eax, %eax
je 0x5312
cmpl $0x2, %eax
jne 0x537a
movl %eax, (%rbx)
movl 0x8(%rsp), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0xc(%rbx)
leaq 0x10(%rbx), %rdi
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rbx)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
callq 0xa0a0
jmp 0x5340
leaq 0x8(%rsp), %rdi
movl %eax, -0x8(%rdi)
movl 0x4(%r12), %eax
movl %eax, -0x4(%rdi)
leaq 0x18(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
addq %rsi, %rdx
callq 0xa0a0
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 0xe0(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x440c
leaq 0x70(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
movq %r13, %rsi
callq 0x4d7f
movl 0x78(%rsp), %eax
movl %eax, (%r15)
movl 0x7c(%rsp), %eax
movl %eax, 0x4(%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
callq 0xa0a0
movq 0xa0(%rsp), %rax
movq %rax, 0x28(%r15)
movq 0xa8(%rsp), %rax
movq %rax, 0x30(%r15)
movq %r15, 0x28(%rsp)
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0x4fe5
leaq 0xc0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x4ff7
callq 0x9f9e
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5018
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x31d0
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x502a
callq 0x9f9e
movq %rsp, %rdx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x9bd4
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5464
movq 0x18(%rsp), %rsi
jmp 0x545c
leaq 0xf8(%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 0x7c(%rsp), %eax
movl %eax, 0x4(%r12)
leaq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
movq %rax, 0x8(%r12)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
callq 0xa0a0
movq 0xa0(%rsp), %rax
movq %rax, 0x28(%r12)
movq 0xa8(%rsp), %rax
movq %rax, 0x30(%r12)
movq %r12, 0x108(%rsp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %r12
movq %rsp, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4d7f
movl 0x8(%rsp), %eax
movl %eax, (%r12)
movl 0xc(%rsp), %eax
movl %eax, 0x4(%r12)
leaq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
movq %rax, 0x8(%r12)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
callq 0xa0a0
movq 0x30(%rsp), %rax
movq %rax, 0x28(%r12)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%r12)
movq %r12, 0x110(%rsp)
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x5162
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x5171
callq 0x9f9e
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x518c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x31d0
leaq 0xe0(%rsp), %rdx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x9bd4
movq 0xe8(%rsp), %rdi
cmpq %r13, %rdi
je 0x5412
movq 0xf8(%rsp), %rsi
jmp 0x540a
movl %eax, (%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%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 0xa0a0
movq 0x30(%r14), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%r14), %rax
movq %rax, 0x38(%rbx)
movq 0x40(%r14), %rax
movq %rax, 0x40(%rbx)
movq 0x48(%r14), %rax
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x5493
movq 0xfda2(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x548f
incl 0x8(%rax)
jmp 0x5493
leaq 0x8(%r14), %rsi
leaq 0x40(%r14), %rdx
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x4d7f
movl (%r15), %eax
movl %eax, (%r14)
movq 0x8(%r15), %rax
movq %rax, 0x8(%r14)
leaq 0x10(%r14), %rdi
leaq 0x80(%rsp), %rsi
callq 0x30f0
leaq 0xb8(%rsp), %rsi
movups -0x18(%rsi), %xmm0
movups %xmm0, 0x30(%r14)
movq -0x8(%rsi), %rax
movq %rax, 0x40(%r14)
leaq 0x48(%r14), %rdi
callq 0x9f58
movq %r14, %r13
addq $0x50, %r13
leaq 0xc0(%rsp), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0xa00e
movl (%r14), %eax
movl %eax, (%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%rbx)
leaq 0x10(%rbx), %r12
leaq 0x20(%rbx), %rbp
movq %rbp, 0x10(%rbx)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xa0a0
movq 0x30(%r14), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%r14), %rax
movq %rax, 0x38(%rbx)
movq 0x40(%r14), %rax
movq %rax, 0x40(%rbx)
movq 0x48(%r14), %rax
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x54a9
movq 0xfcbf(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x54a5
incl 0x8(%rax)
jmp 0x54a9
movl %eax, (%rbx)
movl 0x8(%rsp), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0xc(%rbx)
leaq 0x10(%rbx), %rdi
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rbx)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
callq 0xa0a0
movq 0x30(%rsp), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x38(%rbx)
movq 0x40(%rsp), %rax
movq %rax, 0x40(%rbx)
movq 0x48(%rsp), %rax
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x5392
movq 0xfc50(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x538e
incl 0x8(%rax)
jmp 0x5392
leaq 0x8(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x4d7f
jmp 0x53cf
lock
incl 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rbx)
movq $0x0, 0x60(%rbx)
movq 0x68(%rsp), %rax
movq %rax, 0x68(%rbx)
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x53cf
leaq 0x50(%rbx), %rdx
leaq 0x60(%rsp), %rcx
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rdx)
movq %rax, 0x60(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x53e8
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x53f7
callq 0x9f9e
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5412
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x31d0
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0x5431
leaq 0xc0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x5443
callq 0x9f9e
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5464
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x31d0
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
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 0x9ef2
jmp 0x5464
lock
incl 0x8(%rax)
leaq 0x50(%rbx), %rdi
addq $0x50, %r14
movq %r14, %rsi
callq 0x9ef2
jmp 0x5464
lock
incl 0x8(%rax)
leaq 0x50(%rbx), %rdi
movq %r13, %rsi
callq 0x9ef2
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0x5431
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5431
movq 0xfb11(%rip), %rdi      # 0x14ff0
leaq 0x9f3f(%rip), %rsi      # 0xf425
callq 0x31b0
movl (%r12), %esi
movq %rax, %rdi
callq 0x32c0
movq %rax, %rdi
callq 0x30d0
movl $0x1, %edi
callq 0x3200
jmp 0x5598
movq %rax, %r14
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x551f
callq 0x9f9e
movq (%r12), %rdi
cmpq %rbp, %rdi
je 0x55f8
movq (%rbp), %rsi
jmp 0x55f0
jmp 0x5537
movq %rax, %r14
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x5548
callq 0x9f9e
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x561e
movq (%r12), %rsi
jmp 0x5616
jmp 0x5598
jmp 0x5598
jmp 0x5591
movq %rax, %r14
movq %rsp, %rdi
callq 0x9b88
jmp 0x5582
jmp 0x557f
movq %rax, %r14
movq %rsp, %rdi
callq 0x9b88
jmp 0x55f8
movq %rax, %r14
movl $0x38, %esi
movq %r12, %rdi
callq 0x31d0
jmp 0x55db
movq %rax, %r14
jmp 0x55f8
jmp 0x5598
movq %rax, %rdi
callq 0x9d49
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x9b88
jmp 0x55b2
movq %rax, %r14
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x55c9
callq 0x9f9e
jmp 0x55c9
movq %rax, %r14
movl $0x38, %esi
movq %r15, %rdi
callq 0x31d0
jmp 0x5607
movq %rax, %r14
movq 0xe8(%rsp), %rdi
cmpq %r13, %rdi
je 0x55f8
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x31d0
leaq 0x70(%rsp), %rdi
callq 0x9b88
jmp 0x561e
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x561e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x31d0
movq %r14, %rdi
callq 0x32d0