// File: /workspace/github_cpp_makefile_star2_O1/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 0xd24f(%rip), %rbp      # 0x4b390
leaq 0x22928(%rip), %r12     # 0x60a70
leaq 0x22b29(%rip), %r13     # 0x60c78
movq (%r15), %rax
movq %r15, %rdi
callq *(%rax)
cmpl $0x14, %eax
ja 0x3e355
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 0x3e350
movq 0x8(%rax), %r15
jmp 0x3e14f
leaq 0x228de(%rip), %rsi     # 0x60a70
leaq 0x22a67(%rip), %rdx     # 0x60c00
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
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 0x3fab8
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22888(%rip), %rsi     # 0x60a70
leaq 0x22a71(%rip), %rdx     # 0x60c60
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
movq %rbx, %rdi
callq 0x3c5b4
jmp 0x3e1cf
leaq 0x22857(%rip), %rsi     # 0x60a70
leaq 0x229c8(%rip), %rdx     # 0x60be8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
movq 0x8(%rax), %rsi
movq 0x18(%rax), %rdx
movq 0x28(%rax), %rcx
movq %rbx, %rdi
movq %r14, %r8
callq 0x3e39a
jmp 0x3e1cf
leaq 0x2281d(%rip), %rsi     # 0x60a70
leaq 0x228ce(%rip), %rdx     # 0x60b28
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
movq %rax, %rsi
addq $0x8, %rsi
movq 0x28(%rax), %rdx
movq 0x38(%rax), %rcx
movq %rbx, %rdi
movq %r14, %r8
callq 0x3db1c
jmp 0x3e1cf
leaq 0x227dd(%rip), %rsi     # 0x60a70
leaq 0x227e6(%rip), %rdx     # 0x60a80
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
movzbl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x4050b
jmp 0x3e1cf
leaq 0x227ab(%rip), %rsi     # 0x60a70
leaq 0x227cc(%rip), %rdx     # 0x60a98
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x40252
jmp 0x3e1cf
leaq 0x2277e(%rip), %rsi     # 0x60a70
leaq 0x22937(%rip), %rdx     # 0x60c30
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
addq $0x8, %rax
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x40740
jmp 0x3e1cf
leaq 0x2274a(%rip), %rsi     # 0x60a70
leaq 0x228eb(%rip), %rdx     # 0x60c18
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x3e350
movq 0x8(%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x3fdaa
jmp 0x3e1cf
callq 0x9530
movl $0x10, %edi
callq 0x9150
movq %rax, %rbx
leaq 0xd1bc(%rip), %rsi      # 0x4b525
movq %rax, %rdi
callq 0x93c0
movq 0x24c58(%rip), %rsi     # 0x62fd0
movq 0x24c29(%rip), %rdx     # 0x62fa8
movq %rbx, %rdi
callq 0x94b0
movq %rax, %r14
movq %rbx, %rdi
callq 0x9200
movq %r14, %rdi
callq 0x94e0