// File: /workspace/github_cpp_makefile_star2_O2/pfnet-research[P]pml/src/evaluator.cpp
// Function: calc_int_binop(ast::expr_t const&, ast::expr_t const&, ast::expr_kind_t)
ptr<ast::expr_t> calc_int_binop(
        ast::expr_t const& lhs,
        ast::expr_t const& rhs,
        ast::expr_kind_t kind) {
    using namespace ast;
    assert(is_value(lhs));
    assert(is_value(rhs));
    switch (kind) {
    case expr_kind_t::Eq:
        return make<bool_expr_t>(lhs == rhs);
    case expr_kind_t::Neq:
        return make<bool_expr_t>(lhs != rhs);
    case expr_kind_t::Leq:
        return make<bool_expr_t>(cast<int_expr_t>(lhs).n <= cast<int_expr_t>(rhs).n);
    case expr_kind_t::Geq:
        return make<bool_expr_t>(cast<int_expr_t>(lhs).n >= cast<int_expr_t>(rhs).n);
    case expr_kind_t::Add:
        return make<int_expr_t>(cast<int_expr_t>(lhs).n + cast<int_expr_t>(rhs).n);
    case expr_kind_t::Sub:
        return make<int_expr_t>(cast<int_expr_t>(lhs).n - cast<int_expr_t>(rhs).n);
    case expr_kind_t::Mul:
        return make<int_expr_t>(cast<int_expr_t>(lhs).n * cast<int_expr_t>(rhs).n);
    case expr_kind_t::Div:
        return make<int_expr_t>(cast<int_expr_t>(lhs).n / cast<int_expr_t>(rhs).n);
    case expr_kind_t::And:
        return make<bool_expr_t>(cast<bool_expr_t>(lhs).b && cast<bool_expr_t>(rhs).b);
    case expr_kind_t::Or:
        return make<bool_expr_t>(cast<bool_expr_t>(lhs).b || cast<bool_expr_t>(rhs).b);
    default:
        throw std::logic_error{"invalid binop : " + to_string(kind)};
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl %ecx, %r12d
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq (%rsi), %rax
movq %rsi, %rdi
callq *(%rax)
cmpl $0x14, %eax
ja 0xae66
movl $0x160000, %ecx         # imm = 0x160000
btl %eax, %ecx
jae 0xae66
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
cmpl $0x14, %eax
ja 0xae7f
movl $0x160000, %ecx         # imm = 0x160000
btl %eax, %ecx
jae 0xae7f
leal -0x6(%r12), %eax
cmpl $0xa, %eax
ja 0xae9c
leaq 0x2b509(%rip), %rcx     # 0x361fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
callq 0xaf25
movl 0x8(%rax), %ebp
movq %r14, %rdi
callq 0xaf25
addl 0x8(%rax), %ebp
jmp 0xadb5
movq %r15, %rdi
callq 0xaf47
movb $0x1, %cl
cmpb $0x0, 0x8(%rax)
jne 0xad32
movq %r14, %rdi
callq 0xaf47
movb 0x8(%rax), %cl
leaq 0x20(%rsp), %rsi
movb %cl, (%rsi)
jmp 0xae34
movq %r15, %rdi
callq 0xaf47
cmpb $0x1, 0x8(%rax)
jne 0xae2b
movq %r14, %rdi
callq 0xaf47
movb 0x8(%rax), %al
jmp 0xae2d
movq %r15, %rdi
movq %r14, %rsi
callq 0xd52d
jmp 0xad92
movq %r15, %rdi
callq 0xaf25
movl 0x8(%rax), %ebp
movq %r14, %rdi
callq 0xaf25
subl 0x8(%rax), %ebp
jmp 0xadb5
movq %r15, %rdi
movq %r14, %rsi
callq 0xd52d
xorb $0x1, %al
leaq 0x20(%rsp), %rsi
movb %al, (%rsi)
jmp 0xae34
movq %r15, %rdi
callq 0xaf25
movl 0x8(%rax), %ebp
movq %r14, %rdi
callq 0xaf25
imull 0x8(%rax), %ebp
leaq 0x20(%rsp), %rsi
movl %ebp, (%rsi)
jmp 0xae01
movq %r15, %rdi
callq 0xaf25
movl 0x8(%rax), %ebp
movq %r14, %rdi
callq 0xaf25
cmpl 0x8(%rax), %ebp
leaq 0x20(%rsp), %rsi
setge (%rsi)
jmp 0xae34
movq %r15, %rdi
callq 0xaf25
movl 0x8(%rax), %ebp
movq %r14, %rdi
callq 0xaf25
movq %rax, %rcx
movl %ebp, %eax
cltd
idivl 0x8(%rcx)
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movq %rsp, %rdi
callq 0xbc7c
jmp 0xae3c
movq %r15, %rdi
callq 0xaf25
movl 0x8(%rax), %ebp
movq %r14, %rdi
callq 0xaf25
cmpl 0x8(%rax), %ebp
leaq 0x20(%rsp), %rsi
setle (%rsi)
jmp 0xae34
xorl %eax, %eax
leaq 0x20(%rsp), %rsi
movb %al, (%rsi)
movq %rsp, %rdi
callq 0xbaf2
leaq 0x8(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
andq $0x0, (%rdi)
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
callq 0xa248
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b40f(%rip), %rdi     # 0x3627c
leaq 0x2b416(%rip), %rsi     # 0x3628a
leaq 0x2b421(%rip), %rcx     # 0x3629c
pushq $0xe
jmp 0xae96
leaq 0x2b472(%rip), %rdi     # 0x362f8
leaq 0x2b3fd(%rip), %rsi     # 0x3628a
leaq 0x2b408(%rip), %rcx     # 0x3629c
pushq $0xf
popq %rdx
callq 0x91b0
pushq $0x10
popq %rdi
callq 0x9150
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movl %r12d, %esi
callq 0xd430
leaq 0x2b44b(%rip), %rsi     # 0x36306
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0xb97b
movb $0x1, %bpl
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x93f0
xorl %ebp, %ebp
movq 0x510f1(%rip), %rsi     # 0x5bfd0
movq 0x510b2(%rip), %rdx     # 0x5bf98
movq %rbx, %rdi
callq 0x94b0
movq %rax, %r14
movq %rsp, %rdi
callq 0x9130
jmp 0xaf01
movq %rax, %r14
movb $0x1, %bpl
leaq 0x20(%rsp), %rdi
callq 0x9130
testb %bpl, %bpl
jne 0xaf15
jmp 0xaf1d
movq %rax, %r14
movq %rbx, %rdi
callq 0x9210
movq %r14, %rdi
callq 0x94d0