// File: /workspace/github_cpp_makefile_star2_O2/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 0xbdb3(%rip), %rbp      # 0x3c9fc
leaq 0x28e28(%rip), %r12     # 0x59a78
leaq 0x29039(%rip), %r13     # 0x59c90
movq (%r15), %rax
movq %r15, %rdi
callq *(%rax)
cmpl $0x14, %eax
ja 0x30e34
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 0x9330
testq %rax, %rax
je 0x30e2f
movq 0x8(%rax), %r15
jmp 0x30c57
movq %r15, %rdi
callq 0x3230e
movq 0x8(%rax), %r12
movq %r15, %rdi
callq 0x3230e
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 0x31bba
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x322ec
movl 0x8(%rax), %ebp
movq %r15, %rdi
callq 0x322ec
movl 0xc(%rax), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2fbdc
jmp 0x30cc6
movq %r15, %rdi
callq 0x322a8
leaq 0x8(%rax), %r12
movq %r15, %rdi
callq 0x322a8
movq 0x28(%rax), %r13
movq %r15, %rdi
callq 0x322a8
movq 0x38(%rax), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %r8
callq 0x308f1
jmp 0x30cc6
movq %r15, %rdi
callq 0x322ca
movq 0x8(%rax), %r12
movq %r15, %rdi
callq 0x322ca
movq 0x18(%rax), %r13
movq %r15, %rdi
callq 0x322ca
movq 0x28(%rax), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %r8
callq 0x30e77
jmp 0x30cc6
leaq 0x28d06(%rip), %rsi     # 0x59a78
leaq 0x28d0f(%rip), %rdx     # 0x59a88
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9330
testq %rax, %rax
je 0x30e2f
movzbl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x320a4
jmp 0x30cc6
leaq 0x28cd4(%rip), %rsi     # 0x59a78
leaq 0x28d05(%rip), %rdx     # 0x59ab0
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9330
testq %rax, %rax
je 0x30e2f
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0x31f63
jmp 0x30cc6
leaq 0x28ca7(%rip), %rsi     # 0x59a78
leaq 0x28e70(%rip), %rdx     # 0x59c48
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9330
testq %rax, %rax
je 0x30e2f
addq $0x8, %rax
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x321d0
jmp 0x30cc6
leaq 0x28c73(%rip), %rsi     # 0x59a78
leaq 0x28e24(%rip), %rdx     # 0x59c30
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x9330
testq %rax, %rax
je 0x30e2f
movq 0x8(%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x31ce6
jmp 0x30cc6
callq 0x9510
pushq $0x10
popq %rdi
callq 0x9150
movq %rax, %rbx
leaq 0xbd4b(%rip), %rsi      # 0x3cb91
movq %rax, %rdi
callq 0x93c0
movq 0x2b17b(%rip), %rsi     # 0x5bfd0
movq 0x2b13c(%rip), %rdx     # 0x5bf98
movq %rbx, %rdi
callq 0x94b0
movq %rax, %r14
movq %rbx, %rdi
callq 0x9210
movq %r14, %rdi
callq 0x94d0