// File: pfnet-research[P]pml/src/translate_to_mdp.cpp
// Function: create_rand_case(int, int)
mdp_with_info_t create_rand_case(int start, int end) {
    int from = translation_data::fresh_location();
    int to = translation_data::fresh_location();
    auto rand_var = translation_data::fresh_var();

    mdp::command_t command {
        make<mdp::binop_expr_t>(
                make<mdp::var_expr_t>("location"),
                make<mdp::int_expr_t>(from),
                mdp::binop_kind_t::Eq),
        {}
    };

    auto prob = make<mdp::binop_expr_t>(
            make<mdp::int_expr_t>(1),
            make<mdp::int_expr_t>(end - start + 1),
            mdp::binop_kind_t::Div);
    auto next = make<mdp::binop_expr_t>(
            make<mdp::var_expr_t>("location'"),
            make<mdp::int_expr_t>(to),
            mdp::binop_kind_t::Eq);
    for (int i=start; i<=end; ++i) {
        auto branch = make<mdp::binop_expr_t>(
                next,
                make<mdp::binop_expr_t>(
                    make<mdp::var_expr_t>(rand_var + "'"),
                    make<mdp::int_expr_t>(i),
                    mdp::binop_kind_t::Eq),
                mdp::binop_kind_t::And);
        command.branches.push_back(mdp::branch_t {prob, branch});
    }

    mdp::mdp_t mdp {
        "default",
        {
            mdp::variable_t {
                "location",
                bound_t{from, to}, from
            },
            mdp::variable_t {
                rand_var,
                bound_t{start, end}, start
            }
        },
        {}, // constants
        {command}
    };

    return mdp_with_info_t {
        mdp, from, to,
        value_info_t {
            rand_var, {bound_t{start, end}}
        }
    };
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movq %rdi, -0x330(%rbp)
movq %rdi, %rax
movq %rax, -0x328(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
callq 0x8b550
movl %eax, -0x14(%rbp)
callq 0x8b550
movl %eax, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x8b570
leaq -0x60(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq 0x12e73(%rip), %rsi     # 0x99164
leaq -0x80(%rbp), %rdi
callq 0x86e70
jmp 0x862fc
leaq -0xa0(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x86ea0
jmp 0x8630e
movl $0x8, -0xa4(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
leaq -0xa4(%rbp), %rcx
callq 0x86e30
jmp 0x86335
movq -0x320(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movq %rsi, -0x338(%rbp)
callq 0x7a500
leaq -0x50(%rbp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
callq 0x8b5f0
movq -0x338(%rbp), %rdi
callq 0x7a670
leaq -0xa0(%rbp), %rdi
callq 0x7a690
leaq -0x80(%rbp), %rdi
callq 0x7a6b0
movl $0x1, -0xcc(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x86f10
jmp 0x863a4
movl -0x10(%rbp), %eax
movl -0xc(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, -0xe4(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe4(%rbp), %rsi
callq 0x86f10
jmp 0x863c9
movl $0x1, -0xe8(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
callq 0x86ed0
jmp 0x863f6
leaq -0xe0(%rbp), %rdi
callq 0x7a690
leaq -0xc8(%rbp), %rdi
callq 0x7a690
leaq 0x1985e(%rip), %rsi     # 0x9fc73
leaq -0x108(%rbp), %rdi
callq 0x86f40
jmp 0x86423
leaq -0x118(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x86ea0
jmp 0x86435
movl $0x8, -0x11c(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x118(%rbp), %rdx
leaq -0x11c(%rbp), %rcx
callq 0x86e30
jmp 0x86462
leaq -0x118(%rbp), %rdi
callq 0x7a690
leaq -0x108(%rbp), %rdi
callq 0x7a6b0
movl -0xc(%rbp), %eax
movl %eax, -0x120(%rbp)
movl -0x120(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x867ac
leaq 0x197e6(%rip), %rdx     # 0x9fc7f
leaq -0x170(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8b610
jmp 0x864ab
leaq -0x150(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x86fb0
jmp 0x864c0
leaq -0x180(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x86ea0
jmp 0x864d5
movl $0x8, -0x184(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x180(%rbp), %rdx
leaq -0x184(%rbp), %rcx
callq 0x86e30
jmp 0x86502
movl $0xa, -0x188(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x140(%rbp), %rdx
leaq -0x188(%rbp), %rcx
callq 0x86f70
jmp 0x8652f
leaq -0x140(%rbp), %rdi
callq 0x7a670
leaq -0x180(%rbp), %rdi
callq 0x7a690
leaq -0x150(%rbp), %rdi
callq 0x7a6b0
leaq -0x170(%rbp), %rdi
callq 0xa240
leaq -0x50(%rbp), %rax
movq %rax, -0x348(%rbp)
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x340(%rbp)
leaq -0xb8(%rbp), %rsi
callq 0x8b6c0
leaq -0x198(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x8b6c0
movq -0x348(%rbp), %rdi
movq -0x340(%rbp), %rsi
callq 0x8b690
jmp 0x865ac
leaq -0x1a8(%rbp), %rdi
callq 0xcfe0
leaq -0x130(%rbp), %rdi
callq 0x7a670
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x86483
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86e15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86621
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7a690
leaq -0x80(%rbp), %rdi
callq 0x7a6b0
jmp 0x86e15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86e0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86678
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x7a690
leaq -0xc8(%rbp), %rdi
callq 0x7a690
jmp 0x86e0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86e00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x866d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x7a690
leaq -0x108(%rbp), %rdi
callq 0x7a6b0
jmp 0x86e00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86df4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x8676c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86760
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86754
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x7a670
leaq -0x180(%rbp), %rdi
callq 0x7a690
leaq -0x150(%rbp), %rdi
callq 0x7a6b0
leaq -0x170(%rbp), %rdi
callq 0xa240
jmp 0x86df4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0xcfe0
leaq -0x130(%rbp), %rdi
callq 0x7a670
jmp 0x86df4
leaq -0x210(%rbp), %rax
movq %rax, -0x358(%rbp)
leaq -0x211(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0xa660
movq -0x358(%rbp), %rdi
movq -0x350(%rbp), %rdx
leaq 0x19458(%rip), %rsi     # 0x9fc3a
callq 0x1dd10
jmp 0x867e9
movb $0x1, -0x30c(%rbp)
leaq -0x1f0(%rbp), %rax
movq %rax, -0x368(%rbp)
movb $0x1, -0x2c5(%rbp)
leaq -0x288(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0x2b1(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0xa660
movq -0x360(%rbp), %rdx
leaq 0x12930(%rip), %rsi     # 0x99164
leaq -0x2b0(%rbp), %rdi
callq 0x1dd10
jmp 0x86842
movl -0x14(%rbp), %eax
movl %eax, -0x2bc(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x2b8(%rbp)
movl -0x14(%rbp), %ecx
leaq -0x288(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
leaq -0x2bc(%rbp), %rdx
callq 0x7a3c0
jmp 0x86873
leaq -0x258(%rbp), %rdi
movq %rdi, -0x290(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x2c4(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x2c0(%rbp)
movl -0xc(%rbp), %ecx
leaq -0x38(%rbp), %rsi
leaq -0x2c4(%rbp), %rdx
callq 0x7a3c0
jmp 0x868a8
movb $0x0, -0x2c5(%rbp)
leaq -0x288(%rbp), %rax
movq %rax, -0x228(%rbp)
movq $0x2, -0x220(%rbp)
leaq -0x2c6(%rbp), %rdi
movq %rdi, -0x370(%rbp)
callq 0x7a440
movq -0x368(%rbp), %rdi
movq -0x370(%rbp), %rcx
movq -0x228(%rbp), %rsi
movq -0x220(%rbp), %rdx
callq 0x7a460
jmp 0x868fe
movb $0x1, -0x30b(%rbp)
leaq -0x1d8(%rbp), %rdi
movq %rdi, -0x380(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0x1d8(%rbp)
movq $0x0, -0x1c8(%rbp)
callq 0x7a4e0
movb $0x1, -0x30a(%rbp)
leaq -0x1c0(%rbp), %rax
movq %rax, -0x378(%rbp)
leaq -0x300(%rbp), %rdi
movq %rdi, -0x308(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x7e880
jmp 0x8695b
leaq -0x300(%rbp), %rax
movq %rax, -0x2d8(%rbp)
movq $0x1, -0x2d0(%rbp)
leaq -0x309(%rbp), %rdi
movq %rdi, -0x388(%rbp)
callq 0x7a5d0
movq -0x378(%rbp), %rdi
movq -0x388(%rbp), %rcx
movq -0x2d8(%rbp), %rsi
movq -0x2d0(%rbp), %rdx
callq 0x7a5f0
jmp 0x869aa
movb $0x0, -0x30a(%rbp)
movb $0x0, -0x30b(%rbp)
movb $0x0, -0x30c(%rbp)
leaq -0x309(%rbp), %rdi
callq 0xd360
leaq -0x300(%rbp), %rax
movq %rax, -0x398(%rbp)
addq $0x28, %rax
movq %rax, -0x390(%rbp)
movq -0x390(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x3a0(%rbp)
callq 0xce20
movq -0x398(%rbp), %rcx
movq -0x3a0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x390(%rbp)
jne 0x869e4
leaq -0x2c6(%rbp), %rdi
callq 0xe460
leaq -0x288(%rbp), %rax
movq %rax, -0x3b0(%rbp)
addq $0x60, %rax
movq %rax, -0x3a8(%rbp)
movq -0x3a8(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x3b8(%rbp)
callq 0xdda0
movq -0x3b0(%rbp), %rcx
movq -0x3b8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3a8(%rbp)
jne 0x86a3a
leaq -0x2b0(%rbp), %rdi
callq 0xa240
leaq -0x2b1(%rbp), %rdi
callq 0xa420
leaq -0x211(%rbp), %rdi
callq 0xa420
movq -0x330(%rbp), %rdi
movq %rdi, %rax
movq %rax, -0x3c0(%rbp)
leaq -0x210(%rbp), %rsi
callq 0x8b6f0
jmp 0x86aae
movq -0x330(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, 0x68(%rdi)
movl -0x18(%rbp), %eax
movl %eax, 0x6c(%rdi)
addq $0x70, %rdi
movq %rdi, -0x3d0(%rbp)
movq %rdi, %rax
movq %rax, -0x3c8(%rbp)
leaq -0x38(%rbp), %rsi
callq 0xa190
jmp 0x86ae1
movq -0x3c8(%rbp), %rdi
addq $0x20, %rdi
movl -0xc(%rbp), %eax
movl %eax, -0x314(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x310(%rbp)
leaq -0x314(%rbp), %rsi
callq 0x8b7c0
jmp 0x86b0c
leaq -0x210(%rbp), %rdi
callq 0xc340
leaq -0xf8(%rbp), %rdi
callq 0x7a670
leaq -0xb8(%rbp), %rdi
callq 0x7a670
leaq -0x60(%rbp), %rdi
callq 0xce20
leaq -0x38(%rbp), %rdi
callq 0xa240
movq -0x328(%rbp), %rax
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86d88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86d0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86cff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86ca7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
movq -0x308(%rbp), %rax
leaq -0x300(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x3d8(%rbp)
je 0x86c0b
movq -0x3d8(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x3e0(%rbp)
callq 0xce20
movq -0x3e0(%rbp), %rax
leaq -0x300(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x3d8(%rbp)
jne 0x86bda
jmp 0x86c77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x309(%rbp), %rdi
callq 0xd360
leaq -0x300(%rbp), %rax
movq %rax, -0x3f0(%rbp)
addq $0x28, %rax
movq %rax, -0x3e8(%rbp)
movq -0x3e8(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x3f8(%rbp)
callq 0xce20
movq -0x3f0(%rbp), %rcx
movq -0x3f8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3e8(%rbp)
jne 0x86c44
jmp 0x86c77
testb $0x1, -0x30a(%rbp)
jne 0x86c82
jmp 0x86c8e
movq -0x380(%rbp), %rdi
callq 0xcc30
testb $0x1, -0x30b(%rbp)
jne 0x86c99
jmp 0x86ca5
movq -0x368(%rbp), %rdi
callq 0xcc90
jmp 0x86ca7
leaq -0x2c6(%rbp), %rdi
callq 0xe460
leaq -0x288(%rbp), %rax
movq %rax, -0x408(%rbp)
addq $0x60, %rax
movq %rax, -0x400(%rbp)
movq -0x400(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x410(%rbp)
callq 0xdda0
movq -0x408(%rbp), %rcx
movq -0x410(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x400(%rbp)
jne 0x86ccc
jmp 0x86cff
leaq -0x2b0(%rbp), %rdi
callq 0xa240
leaq -0x2b1(%rbp), %rdi
callq 0xa420
testb $0x1, -0x2c5(%rbp)
jne 0x86d22
jmp 0x86d6f
movq -0x290(%rbp), %rax
leaq -0x288(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x418(%rbp)
je 0x86d6d
movq -0x418(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x420(%rbp)
callq 0xdda0
movq -0x420(%rbp), %rax
leaq -0x288(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x418(%rbp)
jne 0x86d3c
jmp 0x86d6f
testb $0x1, -0x30c(%rbp)
jne 0x86d7a
jmp 0x86d86
movq -0x358(%rbp), %rdi
callq 0xa240
jmp 0x86d88
leaq -0x211(%rbp), %rdi
callq 0xa420
jmp 0x86df4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86de8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x86ddc
movq -0x3d0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
callq 0xa240
movq -0x3c0(%rbp), %rdi
callq 0xc340
leaq -0x210(%rbp), %rdi
callq 0xc340
leaq -0xf8(%rbp), %rdi
callq 0x7a670
leaq -0xb8(%rbp), %rdi
callq 0x7a670
leaq -0x60(%rbp), %rdi
callq 0xce20
leaq -0x38(%rbp), %rdi
callq 0xa240
movq -0x88(%rbp), %rdi
callq 0xa650
nopw (%rax,%rax)