// File: /workspace/github_cpp_makefile_star2_O2/pfnet-research[P]pml/src/translate_to_mdp.cpp
// Function: create_if_case(ast::expr_t const&, ast::expr_t const&, ast::expr_t const&, environment_t<value_info_t> const&)
mdp_with_info_t create_if_case(
        ast::expr_t const& cond,
        ast::expr_t const& tr, ast::expr_t const& fl,
        var_env_t const& var_env) {

    auto cond_ = trans_impl(cond, var_env);
    auto tr_ = trans_impl(tr, var_env);
    auto fl_ = trans_impl(fl, var_env);

    auto result_mdp = mdp::mdp_t::merge(
            mdp::mdp_t::merge(std::move(cond_.mdp), std::move(tr_.mdp)),
            std::move(fl_.mdp));

    // [] location=accept-of-cond & cond -> 1:location'=init-of-tr
    auto concat_to_true = make_concat_with_cond(
            cond_.accept, tr_.init,
            make<mdp::var_expr_t>(cond_.value.name));
    // [] location=accept-of-cond & !cond -> 1:location'=init-of-fl
    auto concat_to_false = make_concat(
            cond_.accept, fl_.init,
            make<mdp::neg_expr_t>(make<mdp::var_expr_t>(cond_.value.name)));

    auto accept_loc = translation_data::fresh_location();
    auto result_var_name = translation_data::fresh_var();
    // [] location=accept-of-tr -> 1:location'=accept & value_name'=value_name-of-tr
    auto phi_true = make_concat(
            tr_.accept, accept_loc,
            make<mdp::binop_expr_t>(
                make<mdp::var_expr_t>(result_var_name + "'"),
                make<mdp::var_expr_t>(tr_.value.name),
                mdp::binop_kind_t::Eq));
    // [] location=accept-of-fl -> 1:location'=accept & value_name'=value_name-of-fl
    auto phi_false = make_concat(
            fl_.accept, accept_loc,
            make<mdp::binop_expr_t>(
                make<mdp::var_expr_t>(result_var_name+"'"),
                make<mdp::var_expr_t>(fl_.value.name),
                mdp::binop_kind_t::Eq));

    result_mdp.commands.push_back(concat_to_true);
    result_mdp.commands.push_back(concat_to_false);
    result_mdp.commands.push_back(phi_true);
    result_mdp.commands.push_back(phi_false);

    if (!tr_.value.bound != !fl_.value.bound)
        throw std::logic_error{"invalid if expression"};

    auto result_var = tr_.value.bound ?
        mdp::variable_t{result_var_name, *tr_.value.bound | *fl_.value.bound, 0} :
        mdp::variable_t{result_var_name, true};

    result_mdp.variables.push_back(result_var);

    return mdp_with_info_t {
        result_mdp, cond_.init, accept_loc,
        value_info_t {
            result_var_name,
            result_var.is_int() ?
                util::make_optional(result_var.as_int().bound) :
                util::nullopt
        }
    };
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %rbx
leaq 0x328(%rsp), %rdi
movq %r8, %rdx
callq 0x30c2e
leaq 0x220(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x30c2e
leaq 0x180(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x30c2e
leaq 0x90(%rsp), %rdi
leaq 0x328(%rsp), %rsi
leaq 0x220(%rsp), %rdx
callq 0x972c
leaq 0x2c0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x180(%rsp), %rdx
callq 0x972c
leaq 0x90(%rsp), %rdi
callq 0xa08a
leaq 0x398(%rsp), %r14
movl -0x4(%r14), %ebp
movl 0x288(%rsp), %r13d
leaq 0x130(%rsp), %rdi
movq %r14, %rsi
callq 0x33141
leaq 0x98(%rsp), %r12
leaq 0x138(%rsp), %r15
movaps -0x8(%r15), %xmm0
movaps %xmm0, -0x8(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
leaq 0x158(%rsp), %rdi
leaq 0x90(%rsp), %rcx
movl %ebp, %esi
movl %r13d, %edx
callq 0x306a7
movq %r12, %rdi
callq 0xa248
movq %r15, %rdi
callq 0xa248
movl 0x394(%rsp), %ebp
movl 0x1e8(%rsp), %r15d
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x33141
leaq 0x100(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x33288
leaq 0x98(%rsp), %r13
leaq 0x108(%rsp), %r12
movaps -0x8(%r12), %xmm0
movaps %xmm0, -0x8(%r13)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r12)
leaq 0x130(%rsp), %rdi
leaq 0x90(%rsp), %rcx
movl %ebp, %esi
movl %r15d, %edx
callq 0x3045a
movq %r13, %rdi
callq 0xa248
movq %r12, %rdi
callq 0xa248
leaq 0x48(%rsp), %rdi
callq 0xa248
movl 0x2b2c1(%rip), %r14d    # 0x5c2d0
leal 0x1(%r14), %eax
movl %eax, 0x2b2b7(%rip)     # 0x5c2d0
leaq 0x68(%rsp), %rdi
callq 0x3243a
movl 0x28c(%rsp), %ebp
leaq 0xb466(%rip), %rdx      # 0x3c497
leaq 0x90(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3249c
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x3294b
leaq 0x290(%rsp), %rsi
movq %rsp, %rdi
callq 0x33141
leaq 0x30(%rsp), %rcx
movl $0x8, (%rcx)
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rsp, %rdx
callq 0x32fe3
leaq 0x48(%rsp), %r12
leaq 0x28(%rsp), %r15
movaps -0x8(%r15), %xmm0
movaps %xmm0, -0x8(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
leaq 0x100(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movl %ebp, %esi
movl %r14d, %edx
callq 0x3045a
movq %r12, %rdi
callq 0xa248
movq %r15, %rdi
callq 0xa248
leaq 0x8(%rsp), %rdi
callq 0xa248
leaq 0x18(%rsp), %rdi
callq 0xa248
leaq 0x90(%rsp), %rdi
callq 0x9130
movl 0x1ec(%rsp), %ebp
leaq 0xb3a2(%rip), %rdx      # 0x3c497
leaq 0x90(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3249c
movq %rsp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x3294b
leaq 0x1f0(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x33141
leaq 0x8c(%rsp), %rcx
movl $0x8, (%rcx)
leaq 0x10(%rsp), %rdi
movq %rsp, %rsi
leaq 0x30(%rsp), %rdx
callq 0x32fe3
leaq 0x28(%rsp), %r12
leaq 0x18(%rsp), %r15
movaps -0x8(%r15), %xmm0
movaps %xmm0, -0x8(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rcx
movl %ebp, %esi
movl %r14d, %edx
callq 0x3045a
movq %r12, %rdi
callq 0xa248
movq %r15, %rdi
callq 0xa248
leaq 0x38(%rsp), %rdi
callq 0xa248
leaq 0x8(%rsp), %rdi
callq 0xa248
leaq 0x90(%rsp), %rdi
callq 0x9130
leaq 0x310(%rsp), %r15
leaq 0x158(%rsp), %rsi
movq %r15, %rdi
callq 0x325c6
leaq 0x130(%rsp), %rsi
movq %r15, %rdi
callq 0x325c6
leaq 0x100(%rsp), %rsi
movq %r15, %rdi
callq 0x325c6
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x325c6
movb 0x2b8(%rsp), %al
cmpb 0x218(%rsp), %al
jne 0x31370
testb %al, %al
je 0x31253
movl 0x2b0(%rsp), %eax
movl 0x2b4(%rsp), %ecx
movl 0x210(%rsp), %edx
cmpl %eax, %edx
cmovll %edx, %eax
movl 0x214(%rsp), %edx
cmpl %edx, %ecx
cmovgl %ecx, %edx
shlq $0x20, %rdx
orq %rdx, %rax
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x90(%rsp), %rdi
leaq 0x68(%rsp), %rsi
xorl %ecx, %ecx
callq 0x2c314
jmp 0x31268
leaq 0x90(%rsp), %rdi
leaq 0x68(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x325f2
leaq 0x2e0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x32642
leaq 0x2c0(%rsp), %rsi
movq %rbx, %rdi
callq 0x324d4
movl 0x390(%rsp), %eax
movl %eax, 0x68(%rbx)
movl %r14d, 0x6c(%rbx)
leaq 0x70(%rbx), %r15
leaq 0x68(%rsp), %rsi
movq %r15, %rdi
callq 0x93a0
movl 0xb0(%rsp), %eax
movl %eax, %ecx
sarl $0x1f, %ecx
cmpl %eax, %ecx
jne 0x312d7
leaq 0xb0(%rsp), %rdi
callq 0x14fc5
movq (%rax), %rax
movq %rax, 0x90(%rbx)
movb $0x1, %al
jmp 0x312d9
xorl %eax, %eax
movb %al, 0x98(%rbx)
leaq 0x90(%rsp), %rdi
callq 0xa3e2
leaq 0x40(%rsp), %rdi
callq 0xa198
leaq 0x100(%rsp), %rdi
callq 0xa198
leaq 0x68(%rsp), %rdi
callq 0x9130
leaq 0x130(%rsp), %rdi
callq 0xa198
leaq 0x158(%rsp), %rdi
callq 0xa198
leaq 0x2c0(%rsp), %rdi
callq 0xa08a
leaq 0x180(%rsp), %rdi
callq 0x2c15c
leaq 0x220(%rsp), %rdi
callq 0x2c15c
leaq 0x328(%rsp), %rdi
callq 0x2c15c
movq %rbx, %rax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x9150
movq %rax, %rbx
leaq 0xb79a(%rip), %rsi      # 0x3cb1c
movq %rax, %rdi
callq 0x93c0
movq 0x2ac3f(%rip), %rsi     # 0x5bfd0
movq 0x2ac00(%rip), %rdx     # 0x5bf98
movq %rbx, %rdi
callq 0x94b0
movq %rax, %r14
movq %r15, %rdi
callq 0x9130
jmp 0x313c0
movq %rax, %r14
movq %rbx, %rdi
callq 0x9210
jmp 0x314ee
movq %rax, %r14
movq %rbx, %rdi
callq 0xa08a
jmp 0x314dc
jmp 0x314eb
movq %rax, %r14
movq %r12, %rdi
callq 0xa248
movq %r15, %rdi
callq 0xa248
jmp 0x313ea
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0xa248
jmp 0x313f9
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xa248
jmp 0x31408
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x9130
jmp 0x314f8
movq %rax, %r14
jmp 0x314f8
movq %rax, %r14
movq %r12, %rdi
callq 0xa248
movq %r15, %rdi
callq 0xa248
jmp 0x3143a
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xa248
jmp 0x31449
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0xa248
jmp 0x31458
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x9130
jmp 0x31505
movq %rax, %r14
jmp 0x31505
movq %rax, %r14
jmp 0x3150f
movq %rax, %r14
movq %r13, %rdi
callq 0xa248
movq %r12, %rdi
callq 0xa248
jmp 0x31492
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0xa248
jmp 0x3151c
movq %rax, %r14
jmp 0x3151c
movq %rax, %r14
movq %r12, %rdi
callq 0xa248
movq %r15, %rdi
callq 0xa248
jmp 0x31529
movq %rax, %r14
jmp 0x31529
movq %rax, %r14
leaq 0x90(%rsp), %rdi
jmp 0x31531
movq %rax, %r14
jmp 0x31536
movq %rax, %r14
jmp 0x31543
movq %rax, %r14
jmp 0x31550
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0xa3e2
jmp 0x314ee
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0xa198
leaq 0x100(%rsp), %rdi
callq 0xa198
leaq 0x68(%rsp), %rdi
callq 0x9130
leaq 0x130(%rsp), %rdi
callq 0xa198
leaq 0x158(%rsp), %rdi
callq 0xa198
leaq 0x2c0(%rsp), %rdi
callq 0xa08a
leaq 0x180(%rsp), %rdi
callq 0x2c15c
leaq 0x220(%rsp), %rdi
callq 0x2c15c
leaq 0x328(%rsp), %rdi
callq 0x2c15c
movq %r14, %rdi
callq 0x94d0