// File: /workspace/github_cpp_makefile_star2_O3/silverneko[P]Lambda-calculus-interpreter/src/main.cpp
// Function: weakNormalForm(Expression const&, Context const&)
Object weakNormalForm(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 = weakNormalForm( res.expr(), res.env() );
      }else{
        return makeNormalForm( expr );
      }
      break;
    case Expression::Lambda:
      return Object(expr, 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 weakNormalForm(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 << "[Weak 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, %r15
movq %rdi, %rbx
movl (%rsi), %eax
leaq 0xa748(%rip), %rcx      # 0xf004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rdi
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdx
callq 0x46a0
testb %al, %al
je 0x4969
addq $0x8, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x45bc
movq %rax, %r14
movl (%rax), %eax
testl %eax, %eax
je 0x4b7a
cmpl $0x2, %eax
jne 0x4be1
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 0x4e22
movq 0x10668(%rip), %rcx     # 0x14fc0
cmpb $0x0, (%rcx)
je 0x4e1e
incl 0x8(%rax)
jmp 0x4e22
movq %rbx, %rdi
movl $0x2, %esi
movq %r15, %rdx
callq 0x9ab0
jmp 0x4e09
movq 0x28(%r15), %rsi
movq 0x30(%r15), %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 0x4a25
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x473a
movl 0x10(%rsp), %eax
testl %eax, %eax
je 0x4cc1
cmpl $0x2, %eax
jne 0x4d1f
movl $0x2, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %rdi
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rbx)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
jmp 0x4cee
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x99ea
jmp 0x4e09
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 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4f8a
movq 0x18(%rsp), %rax
movq %rax, (%r12)
leaq 0x8(%r12), %rdi
movq %r12, %rax
addq $0x18, %rax
movq %rax, 0x8(%r12)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
movups 0x40(%rsp), %xmm0
movups %xmm0, 0x28(%r12)
movq %r12, 0x120(%rsp)
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0x4b1d
leaq 0x60(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x4b2c
callq 0x9e7a
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4b47
movq 0x30(%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 0x4db7
movq 0x108(%rsp), %rsi
jmp 0x4daf
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 0x4e38
movq 0x103f0(%rip), %rcx     # 0x14fc0
cmpb $0x0, (%rcx)
je 0x4e34
incl 0x8(%rax)
jmp 0x4e38
leaq 0x8(%r14), %rsi
leaq 0x40(%r14), %r12
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
callq 0x4899
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, 0x8(%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 0x4e4e
movq 0x10310(%rip), %rcx     # 0x14fc0
cmpb $0x0, (%rcx)
je 0x4e4a
incl 0x8(%rax)
jmp 0x4e4e
movl $0x0, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %rdi
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rbx)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
callq 0x9f6e
movups 0x40(%rsp), %xmm0
movups %xmm0, 0x30(%rbx)
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x40(%rbx)
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x4d50
movq 0x102ab(%rip), %rcx     # 0x14fc0
cmpb $0x0, (%rcx)
je 0x4d4c
incl 0x8(%rax)
jmp 0x4d50
leaq 0x18(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x4899
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0x4d8d
leaq 0x60(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4d8d
lock
incl 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rbx)
movq $0x0, 0x60(%rbx)
movq 0x78(%rsp), %rax
movq %rax, 0x68(%rbx)
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0x4d8d
leaq 0x50(%rbx), %rdx
leaq 0x70(%rsp), %rcx
movups 0x60(%rsp), %xmm0
movups %xmm0, (%rdx)
movq %rax, 0x60(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x4d9c
callq 0x9e7a
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4db7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x31d0
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x4dd6
leaq 0xd0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x4de8
callq 0x9e7a
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4e09
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 0x4e09
lock
incl 0x8(%rax)
leaq 0x50(%rbx), %rdi
addq $0x50, %r14
movq %r14, %rsi
callq 0x9dd2
jmp 0x4e09
lock
incl 0x8(%rax)
leaq 0x50(%rbx), %rdi
movq %rbp, %rsi
callq 0x9dd2
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x4dd6
leaq 0xd0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4dd6
movq 0x10167(%rip), %rdi     # 0x14ff0
leaq 0xa535(%rip), %rsi      # 0xf3c5
callq 0x31b0
movl (%r15), %esi
movq %rax, %rdi
callq 0x32c0
movq %rax, %rdi
callq 0x30d0
movl $0x1, %edi
callq 0x3200
jmp 0x4f4d
jmp 0x4f4d
movq %rax, %r14
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x4ecd
callq 0x9e7a
movq (%r13), %rdi
cmpq 0x8(%rsp), %rdi
je 0x4f75
movq 0x8(%rsp), %rax
movq (%rax), %rsi
jmp 0x4f6d
jmp 0x4eeb
movq %rax, %r14
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x4efc
callq 0x9e7a
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x4f82
movq (%r12), %rsi
incq %rsi
callq 0x31d0
jmp 0x4f82
jmp 0x4f4d
jmp 0x4f48
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x9a64
jmp 0x4f39
jmp 0x4f36
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x9a64
jmp 0x4f75
movq %rax, %r14
movl $0x38, %esi
movq %r12, %rdi
callq 0x31d0
jmp 0x4f58
movq %rax, %r14
jmp 0x4f75
movq %rax, %rdi
callq 0x9c1b
movq %rax, %r14
movq 0xf8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4f75
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x31d0
leaq 0x80(%rsp), %rdi
callq 0x9a64
movq %r14, %rdi
callq 0x32d0