// File: pfnet-research[P]pml/src/evaluator.cpp
// Function: evaluator::eval(std::shared_ptr<ast::expr_t>, environment_t<ast::expr_t> const&)
ptr<ast::expr_t> eval(ptr<ast::expr_t> e, environment_t const& env) {
    using namespace ast;
    switch (e->kind()) {
    case expr_kind_t::Let: {
        auto& let_expr = cast<let_expr_t>(*e);
        auto init = eval(let_expr.init, env);
        auto new_env = env.append(let_expr.name, init);
        return eval(let_expr.body, new_env);
        }
    case expr_kind_t::LetFun: {
        auto& letfun_expr = cast<letfun_expr_t>(*e);
        auto fun = make<ast::fun_expr_t>(letfun_expr.type, letfun_expr.init);
        auto new_env = env.append(letfun_expr.name, fun);
        return eval(letfun_expr.body, new_env);
        }
    case expr_kind_t::If: {
        auto& if_expr = cast<if_expr_t>(*e);
        auto cond_val = eval(if_expr.cond_expr, env);
        if (cond_val->kind() != ast::expr_kind_t::Bool) {
            std::cerr << "eval error: if-condition must be boolean " + ast::to_debug_string(*cond_val) << std::endl;
            assert(false);
            return nullptr;
        } else if (cast<bool_expr_t>(*cond_val).b == true) {
            return eval(if_expr.true_expr, env);
        } {
            return eval(if_expr.false_expr, env);
        }
        }
    case expr_kind_t::Eq:  case expr_kind_t::Neq:
    case expr_kind_t::Leq:  case expr_kind_t::Geq:
    case expr_kind_t::Add: case expr_kind_t::Sub:
    case expr_kind_t::Mul: case expr_kind_t::Div:
    case expr_kind_t::And: case expr_kind_t::Or: {
            auto& binop_expr = cast<binop_expr_t>(*e);
            return calc_int_binop(
                    *eval(binop_expr.lhs, env),
                    *eval(binop_expr.rhs, env),
                    e->kind());
        }
    case expr_kind_t::Neg: {
            auto val = eval(cast<neg_expr_t>(*e).inner, env);
            return make<bool_expr_t>(!cast<bool_expr_t>(*val).b);
        }
    case expr_kind_t::Int: case expr_kind_t::Bool: case expr_kind_t::Fun:
        return e;
    case expr_kind_t::Var:
        return env.lookup(cast<var_expr_t>(*e).name);
    case expr_kind_t::App: {
            auto const& app_expr = cast<app_expr_t>(*e);
            auto f_ = eval(app_expr.f, env);
            if (f_->kind() != ast::expr_kind_t::Fun)
                throw std::logic_error{"arienai"};
            auto f = cast<fun_expr_t>(*f_);
            if (f.type.args.size() != app_expr.args.size())
                throw std::logic_error{"arienai"};
            environment_t new_env = env;
            for (size_t i=0; i<app_expr.args.size(); ++i) {
                new_env = new_env.append(
                        f.type.args[i].name,
                        eval(app_expr.args[i], env));
            }
            return eval(f.body, new_env);
        }
    case expr_kind_t::Rand: {
            auto& rand_expr = cast<rand_expr_t>(*e);
            int start = rand_expr.start;
            int end = rand_expr.end;
            return make<int_expr_t>(std::rand() % (end - start + 1) + start);
        }
    case expr_kind_t::Typed:
        return eval(cast<typed_expr_t>(*e).expr, env);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rsi, -0x328(%rbp)
movq %rdi, %rax
movq -0x328(%rbp), %rdi
movq %rax, -0x320(%rbp)
movq %rax, %rcx
movq %rcx, -0x318(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x13000
movq %rax, %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, %ecx
movq %rcx, -0x310(%rbp)
subl $0x14, %eax
ja 0x12a93
movq -0x310(%rbp), %rax
leaq 0x874c7(%rip), %rcx     # 0x99250
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12ab0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
addq $0x28, %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x13050
movq -0x330(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x11d20
jmp 0x11dd8
leaq -0x40(%rbp), %rdi
callq 0x13080
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x8, %rdx
leaq -0x68(%rbp), %rdi
leaq -0x30(%rbp), %rcx
callq 0x130a0
jmp 0x11dfc
movq -0x20(%rbp), %rsi
addq $0x38, %rsi
leaq -0x78(%rbp), %rdi
movq %rdi, -0x338(%rbp)
callq 0x13050
movq -0x320(%rbp), %rdi
movq -0x338(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x11d20
jmp 0x11e2d
leaq -0x78(%rbp), %rdi
callq 0x13080
leaq -0x68(%rbp), %rdi
callq 0x13170
leaq -0x30(%rbp), %rdi
callq 0x13080
jmp 0x12a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x11e93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x13080
leaq -0x68(%rbp), %rdi
callq 0x13170
leaq -0x30(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12af0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdx
movq %rdx, %rsi
addq $0x28, %rsi
addq $0x78, %rdx
leaq -0x90(%rbp), %rdi
movq %rdi, -0x358(%rbp)
callq 0x12b30
movq -0x358(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0x350(%rbp)
movq -0x80(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x348(%rbp)
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x13190
movq -0x350(%rbp), %rsi
movq -0x348(%rbp), %rdx
movq -0x340(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
callq 0x130a0
jmp 0x11f32
leaq -0xb8(%rbp), %rdi
callq 0x13080
movq -0x80(%rbp), %rsi
addq $0x88, %rsi
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0x13050
movq -0x320(%rbp), %rdi
movq -0x360(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x11d20
jmp 0x11f78
leaq -0xc8(%rbp), %rdi
callq 0x13080
leaq -0xa8(%rbp), %rdi
callq 0x13170
leaq -0x90(%rbp), %rdi
callq 0x131c0
jmp 0x12a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13080
jmp 0x11fdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x13080
leaq -0xa8(%rbp), %rdi
callq 0x13170
leaq -0x90(%rbp), %rdi
callq 0x131c0
jmp 0x12aa5
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12b70
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rsi
addq $0x8, %rsi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x368(%rbp)
callq 0x13050
movq -0x368(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0x11d20
jmp 0x12042
leaq -0xf0(%rbp), %rdi
callq 0x13080
leaq -0xe0(%rbp), %rdi
callq 0x13000
movq %rax, %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x36c(%rbp)
jmp 0x1206d
movl -0x36c(%rbp), %eax
cmpl $0x12, %eax
je 0x12182
leaq -0xe0(%rbp), %rdi
callq 0x13020
movq %rax, %rsi
leaq -0x130(%rbp), %rdi
callq 0x1c030
jmp 0x12099
leaq 0x872a0(%rip), %rsi     # 0x99340
leaq -0x110(%rbp), %rdi
leaq -0x130(%rbp), %rdx
callq 0x12fb0
jmp 0x120b5
movq 0xd4f2c(%rip), %rdi     # 0xe6fe8
leaq -0x110(%rbp), %rsi
callq 0xa340
movq %rax, -0x378(%rbp)
jmp 0x120d1
movq -0x378(%rbp), %rdi
movq 0xd4e79(%rip), %rsi     # 0xe6f58
callq 0xa400
jmp 0x120e6
leaq -0x110(%rbp), %rdi
callq 0xa240
leaq -0x130(%rbp), %rdi
callq 0xa240
leaq 0x8dba2(%rip), %rdi     # 0x9fca7
leaq 0x871a7(%rip), %rsi     # 0x992b3
movl $0x43, %edx
leaq 0x87252(%rip), %rcx     # 0x9936a
callq 0xa260
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1229b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12171
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0xa240
leaq -0x130(%rbp), %rdi
callq 0xa240
jmp 0x1229b
leaq -0xe0(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12bb0
movq %rax, -0x380(%rbp)
jmp 0x1219f
movq -0x380(%rbp), %rax
movb 0x8(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x1221f
movq -0xd0(%rbp), %rsi
addq $0x18, %rsi
leaq -0x140(%rbp), %rdi
movq %rdi, -0x388(%rbp)
callq 0x13050
movq -0x320(%rbp), %rdi
movq -0x388(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x11d20
jmp 0x121ea
leaq -0x140(%rbp), %rdi
callq 0x13080
movl $0x1, -0x144(%rbp)
jmp 0x1228a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x13080
jmp 0x1229b
jmp 0x12221
movq -0xd0(%rbp), %rsi
addq $0x28, %rsi
leaq -0x158(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x13050
movq -0x320(%rbp), %rdi
movq -0x390(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x11d20
jmp 0x12258
leaq -0x158(%rbp), %rdi
callq 0x13080
movl $0x1, -0x144(%rbp)
jmp 0x1228a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x13080
jmp 0x1229b
leaq -0xe0(%rbp), %rdi
callq 0x13080
jmp 0x12a95
leaq -0xe0(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12bf0
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rsi
addq $0x8, %rsi
leaq -0x180(%rbp), %rdi
movq %rdi, -0x398(%rbp)
callq 0x13050
movq -0x398(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x170(%rbp), %rdi
callq 0x11d20
jmp 0x122fe
leaq -0x170(%rbp), %rdi
callq 0x13020
movq %rax, -0x3a8(%rbp)
movq -0x160(%rbp), %rsi
addq $0x18, %rsi
leaq -0x1a0(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
callq 0x13050
movq -0x3a0(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x190(%rbp), %rdi
callq 0x11d20
jmp 0x12348
leaq -0x190(%rbp), %rdi
callq 0x13020
movq -0x328(%rbp), %rdi
movq %rax, -0x3b8(%rbp)
callq 0x13000
movq %rax, %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x3ac(%rbp)
jmp 0x1237a
movl -0x3ac(%rbp), %ecx
movq -0x3b8(%rbp), %rdx
movq -0x3a8(%rbp), %rsi
movq -0x320(%rbp), %rdi
callq 0x11650
jmp 0x1239c
leaq -0x190(%rbp), %rdi
callq 0x13080
leaq -0x1a0(%rbp), %rdi
callq 0x13080
leaq -0x170(%rbp), %rdi
callq 0x13080
leaq -0x180(%rbp), %rdi
callq 0x13080
jmp 0x12a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1241d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12405
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x13080
leaq -0x1a0(%rbp), %rdi
callq 0x13080
leaq -0x170(%rbp), %rdi
callq 0x13080
leaq -0x180(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12c30
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x13050
movq -0x3c0(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x1b0(%rbp), %rdi
callq 0x11d20
jmp 0x12475
leaq -0x1c0(%rbp), %rdi
callq 0x13080
leaq -0x1b0(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12bb0
movq %rax, -0x3c8(%rbp)
jmp 0x1249e
movq -0x3c8(%rbp), %rax
movb 0x8(%rax), %al
notb %al
andb $0x1, %al
movb %al, -0x1d1(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x1d1(%rbp), %rsi
callq 0x11c10
jmp 0x124c7
movq -0x320(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x12f10
leaq -0x1d0(%rbp), %rdi
callq 0x12f40
movl $0x1, -0x144(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x13080
jmp 0x12a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq -0x328(%rbp), %rsi
movq -0x320(%rbp), %rdi
callq 0x131e0
jmp 0x12a95
movq -0x328(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x3d0(%rbp)
callq 0x13020
movq %rax, %rdi
callq 0x12c70
movq -0x320(%rbp), %rdi
movq -0x3d0(%rbp), %rsi
movq %rax, %rdx
addq $0x8, %rdx
callq 0x13210
jmp 0x12a95
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12cb0
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x200(%rbp), %rdi
movq %rdi, -0x3d8(%rbp)
callq 0x13050
movq -0x3d8(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x1f0(%rbp), %rdi
callq 0x11d20
jmp 0x125e3
leaq -0x200(%rbp), %rdi
callq 0x13080
leaq -0x1f0(%rbp), %rdi
callq 0x13000
movq %rax, %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x3dc(%rbp)
jmp 0x1260e
movl -0x3dc(%rbp), %eax
cmpl $0x13, %eax
je 0x126ac
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x3e8(%rbp)
leaq 0x86d79(%rip), %rsi     # 0x993b4
callq 0xa540
jmp 0x12642
movq -0x3e8(%rbp), %rdi
movq 0xd4980(%rip), %rsi     # 0xe6fd0
movq 0xd4939(%rip), %rdx     # 0xe6f90
callq 0xa610
jmp 0x12aae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12981
movq -0x3e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xa2c0
jmp 0x12981
leaq -0x1f0(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12cf0
movq %rax, -0x3f0(%rbp)
jmp 0x126c9
movq -0x3f0(%rbp), %rsi
leaq -0x268(%rbp), %rdi
callq 0x132c0
jmp 0x126de
leaq -0x268(%rbp), %rdi
addq $0x8, %rdi
callq 0x13340
movq %rax, -0x3f8(%rbp)
movq -0x1e0(%rbp), %rdi
addq $0x18, %rdi
callq 0x13370
movq %rax, %rcx
movq -0x3f8(%rbp), %rax
cmpq %rcx, %rax
je 0x12786
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x400(%rbp)
leaq 0x86c82(%rip), %rsi     # 0x993b4
callq 0xa540
jmp 0x12739
movq -0x400(%rbp), %rdi
movq 0xd4889(%rip), %rsi     # 0xe6fd0
movq 0xd4842(%rip), %rdx     # 0xe6f90
callq 0xa610
jmp 0x12aae
movq -0x400(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0xa2c0
jmp 0x12975
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12975
movq -0x18(%rbp), %rsi
leaq -0x280(%rbp), %rdi
callq 0x13390
jmp 0x12798
movq $0x0, -0x288(%rbp)
movq -0x288(%rbp), %rax
movq %rax, -0x408(%rbp)
movq -0x1e0(%rbp), %rdi
addq $0x18, %rdi
callq 0x13370
movq %rax, %rcx
movq -0x408(%rbp), %rax
cmpq %rcx, %rax
jae 0x128dc
leaq -0x260(%rbp), %rdi
movq -0x288(%rbp), %rsi
callq 0x133c0
movq %rax, -0x418(%rbp)
movq -0x1e0(%rbp), %rdi
addq $0x18, %rdi
movq -0x288(%rbp), %rsi
callq 0x133e0
movq %rax, %rsi
leaq -0x2c0(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x13050
movq -0x410(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x2b0(%rbp), %rdi
callq 0x11d20
jmp 0x12834
movq -0x418(%rbp), %rdx
leaq -0x2a0(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x2b0(%rbp), %rcx
callq 0x130a0
jmp 0x12857
leaq -0x280(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x13400
leaq -0x2a0(%rbp), %rdi
callq 0x13170
leaq -0x2b0(%rbp), %rdi
callq 0x13080
leaq -0x2c0(%rbp), %rdi
callq 0x13080
movq -0x288(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x288(%rbp)
jmp 0x127a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x128cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x13080
leaq -0x2c0(%rbp), %rdi
callq 0x13080
jmp 0x12969
leaq -0x210(%rbp), %rsi
leaq -0x2d0(%rbp), %rdi
movq %rdi, -0x420(%rbp)
callq 0x13050
movq -0x320(%rbp), %rdi
movq -0x420(%rbp), %rsi
leaq -0x280(%rbp), %rdx
callq 0x11d20
jmp 0x12912
leaq -0x2d0(%rbp), %rdi
callq 0x13080
movl $0x1, -0x144(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x13170
leaq -0x268(%rbp), %rdi
callq 0x13430
leaq -0x1f0(%rbp), %rdi
callq 0x13080
jmp 0x12a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x13080
leaq -0x280(%rbp), %rdi
callq 0x13170
leaq -0x268(%rbp), %rdi
callq 0x13430
leaq -0x1f0(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12d30
movq %rax, -0x2d8(%rbp)
movq -0x2d8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2dc(%rbp)
movq -0x2d8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2e0(%rbp)
callq 0xa100
movl -0x2e0(%rbp), %ecx
subl -0x2dc(%rbp), %ecx
addl $0x1, %ecx
cltd
idivl %ecx
addl -0x2dc(%rbp), %edx
movl %edx, -0x2f4(%rbp)
leaq -0x2f0(%rbp), %rdi
leaq -0x2f4(%rbp), %rsi
callq 0x11cb0
movq -0x320(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x12f60
leaq -0x2f0(%rbp), %rdi
callq 0x12f90
jmp 0x12a95
movq -0x328(%rbp), %rdi
callq 0x13020
movq %rax, %rdi
callq 0x12d70
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x308(%rbp), %rdi
movq %rdi, -0x428(%rbp)
callq 0x13050
movq -0x320(%rbp), %rdi
movq -0x428(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x11d20
jmp 0x12a6b
leaq -0x308(%rbp), %rdi
callq 0x13080
jmp 0x12a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x13080
jmp 0x12aa5
ud2
movq -0x318(%rbp), %rax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0xa650
nop