// File: /workspace/github_cpp_makefile_star2_O3/pfnet-research[P]pml/src/translate_to_mdp.cpp
// Function: trans_impl(ast::expr_t const&, environment_t<value_info_t> const&)
mdp_with_info_t trans_impl(ast::expr_t const& e, var_env_t const& var_env) {
    using namespace ast;
    switch (e.kind()) {
    case expr_kind_t::Let:
        return create_let_case(
                cast<ast::let_expr_t>(e).name,
                *cast<ast::let_expr_t>(e).init,
                *cast<ast::let_expr_t>(e).body,
                var_env);
    case expr_kind_t::If:
        return create_if_case(
                *cast<if_expr_t>(e).cond_expr,
                *cast<if_expr_t>(e).true_expr,
                *cast<if_expr_t>(e).false_expr,
                var_env);
    case expr_kind_t::Rand:
        return create_rand_case(
                cast<rand_expr_t>(e).start,
                cast<rand_expr_t>(e).end);
    case expr_kind_t::Add: case expr_kind_t::Sub:
    case expr_kind_t::Mul: case expr_kind_t::Div:
    case expr_kind_t::Eq:  case expr_kind_t::Neq:
    case expr_kind_t::Leq: case expr_kind_t::Geq:
    case expr_kind_t::And: case expr_kind_t::Or:
        return create_binop_case(
                *cast<ast::binop_expr_t>(e).lhs,
                *cast<ast::binop_expr_t>(e).rhs,
                e.kind(), var_env);
    case expr_kind_t::Neg:
        return create_neg_case(*cast<ast::neg_expr_t>(e).inner, var_env);
    case expr_kind_t::Int:
        return create_int_case(cast<ast::int_expr_t>(e).n);
    case expr_kind_t::Bool:
        return create_bool_case(cast<ast::bool_expr_t>(e).b);
    case expr_kind_t::Var:
        return create_var_case(cast<ast::var_expr_t>(e).name, var_env);
    case expr_kind_t::Typed:
        return trans_impl(*cast<typed_expr_t>(e).expr, var_env);
    default:
        throw std::logic_error{"unimplemented translation"};
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xdb47(%rip), %rbp      # 0x4b390
leaq 0x22248(%rip), %r12     # 0x5fa98
leaq 0x22449(%rip), %r13     # 0x5fca0
movq (%r15), %rax
movq %r15, %rdi
callq *(%rax)
cmpl $0x14, %eax
ja 0x3da5d
movl %eax, %eax
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movq 0x8(%rax), %r15
jmp 0x3d857
leaq 0x221fe(%rip), %rsi     # 0x5fa98
leaq 0x22387(%rip), %rdx     # 0x5fc28
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movq 0x8(%rax), %r12
movq 0x18(%rax), %r13
movq (%r15), %rax
movq %r15, %rdi
callq *(%rax)
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl %eax, %ecx
movq %r14, %r8
callq 0x3f1f7
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x221a8(%rip), %rsi     # 0x5fa98
leaq 0x22391(%rip), %rdx     # 0x5fc88
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
movq %rbx, %rdi
callq 0x3bd3c
jmp 0x3d8d7
leaq 0x22177(%rip), %rsi     # 0x5fa98
leaq 0x222e8(%rip), %rdx     # 0x5fc10
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movq 0x8(%rax), %rsi
movq 0x18(%rax), %rdx
movq 0x28(%rax), %rcx
movq %rbx, %rdi
movq %r14, %r8
callq 0x3daa2
jmp 0x3d8d7
leaq 0x2213d(%rip), %rsi     # 0x5fa98
leaq 0x221ee(%rip), %rdx     # 0x5fb50
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movq %rax, %rsi
addq $0x8, %rsi
movq 0x28(%rax), %rdx
movq 0x38(%rax), %rcx
movq %rbx, %rdi
movq %r14, %r8
callq 0x3d224
jmp 0x3d8d7
leaq 0x220fd(%rip), %rsi     # 0x5fa98
leaq 0x22106(%rip), %rdx     # 0x5faa8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movzbl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x3fc47
jmp 0x3d8d7
leaq 0x220cb(%rip), %rsi     # 0x5fa98
leaq 0x220ec(%rip), %rdx     # 0x5fac0
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x3f991
jmp 0x3d8d7
leaq 0x2209e(%rip), %rsi     # 0x5fa98
leaq 0x22257(%rip), %rdx     # 0x5fc58
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
addq $0x8, %rax
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x3fe79
jmp 0x3d8d7
leaq 0x2206a(%rip), %rsi     # 0x5fa98
leaq 0x2220b(%rip), %rdx     # 0x5fc40
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3da58
movq 0x8(%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x3f4e9
jmp 0x3d8d7
callq 0x9530
movl $0x10, %edi
callq 0x9150
movq %rax, %rbx
leaq 0xdab4(%rip), %rsi      # 0x4b525
movq %rax, %rdi
callq 0x93c0
movq 0x24550(%rip), %rsi     # 0x61fd0
movq 0x24521(%rip), %rdx     # 0x61fa8
movq %rbx, %rdi
callq 0x94b0
movq %rax, %r14
movq %rbx, %rdi
callq 0x9200
movq %r14, %rdi
callq 0x94e0