// File: pfnet-research[P]pml/src/typechecker.cpp
// Function: check_by_PRISM(mdp::mdp_t const&, pctl::pctl_t const&)
bool check_by_PRISM(mdp::mdp_t const& mdp, pctl::pctl_t const& pctl) {
    std::ofstream mdp_output{"./output.mdp"};
    if (mdp_output.fail())
        throw std::runtime_error{"can not open file: ./output.mdp"};
    mdp_output << mdp << std::endl;

    std::ofstream pctl_output{"./output.pctl"};
    if (pctl_output.fail())
        throw std::runtime_error{"can not open file: ./output.pctl"};
    pctl.output(pctl_output);

    if (std::system("prism ./output.mdp ./output.pctl > prism_output") != 0)
        throw std::runtime_error{"can not execute prism"};

    std::ifstream prism{"prism_output"};

    std::string line;
    while (std::getline(prism, line)) {
        if (line.find("Result: true") != std::string::npos)
            return true;
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x6a0, %rsp            # imm = 0x6A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0xb4ca(%rip), %rsi      # 0xa20c4
leaq -0x218(%rbp), %rdi
movl $0x10, %edx
callq 0xa430
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0xa030
movb %al, -0x655(%rbp)
jmp 0x96c2b
movb -0x655(%rbp), %al
testb $0x1, %al
jne 0x96c37
jmp 0x96cb5
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x660(%rbp)
leaq 0xb45c(%rip), %rsi      # 0xa20b1
callq 0xa160
jmp 0x96c5c
movq -0x660(%rbp), %rdi
movq 0x50386(%rip), %rsi     # 0xe6ff0
movq 0x5030f(%rip), %rdx     # 0xe6f80
callq 0xa610
jmp 0x96f79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x96f61
movq -0x660(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
callq 0xa2c0
jmp 0x96f61
movq -0x10(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0xb000
movq %rax, -0x668(%rbp)
jmp 0x96cce
movq -0x668(%rbp), %rdi
movq 0x5027c(%rip), %rsi     # 0xe6f58
callq 0xa400
jmp 0x96ce3
leaq 0xb3fa(%rip), %rsi      # 0xa20e4
leaq -0x428(%rbp), %rdi
movl $0x10, %edx
callq 0xa430
jmp 0x96cfd
movq -0x428(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x428(%rbp,%rax), %rdi
callq 0xa030
movb %al, -0x669(%rbp)
jmp 0x96d1d
movb -0x669(%rbp), %al
testb $0x1, %al
jne 0x96d29
jmp 0x96da7
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x678(%rbp)
leaq 0xb38a(%rip), %rsi      # 0xa20d1
callq 0xa160
jmp 0x96d4e
movq -0x678(%rbp), %rdi
movq 0x50294(%rip), %rsi     # 0xe6ff0
movq 0x5021d(%rip), %rdx     # 0xe6f80
callq 0xa610
jmp 0x96f79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x96f55
movq -0x678(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
callq 0xa2c0
jmp 0x96f55
movq -0x18(%rbp), %rdi
leaq -0x428(%rbp), %rsi
callq 0x11540
jmp 0x96db9
leaq 0xb332(%rip), %rdi      # 0xa20f2
callq 0xa320
movl %eax, -0x67c(%rbp)
jmp 0x96dcd
movl -0x67c(%rbp), %eax
cmpl $0x0, %eax
je 0x96e3f
movl $0x10, %edi
callq 0xa1d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x688(%rbp)
leaq 0xb32c(%rip), %rsi      # 0xa2122
callq 0xa160
jmp 0x96dfd
movq -0x688(%rbp), %rdi
movq 0x501e5(%rip), %rsi     # 0xe6ff0
movq 0x5016e(%rip), %rdx     # 0xe6f80
callq 0xa610
jmp 0x96f79
movq -0x688(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
callq 0xa2c0
jmp 0x96f55
leaq 0xb2cf(%rip), %rsi      # 0xa2115
leaq -0x630(%rbp), %rdi
movl $0x8, %edx
callq 0xa690
jmp 0x96e59
leaq -0x650(%rbp), %rdi
callq 0xa520
leaq -0x630(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0xa0b0
movq %rax, -0x690(%rbp)
jmp 0x96e81
movq -0x690(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa4d0
movb %al, -0x691(%rbp)
jmp 0x96e9f
movb -0x691(%rbp), %al
testb $0x1, %al
jne 0x96eab
jmp 0x96f09
leaq -0x650(%rbp), %rdi
leaq 0xb27f(%rip), %rsi      # 0xa2138
xorl %eax, %eax
movl %eax, %edx
callq 0xa700
cmpq $-0x1, %rax
je 0x96f04
movb $0x1, -0x1(%rbp)
movl $0x1, -0x654(%rbp)
jmp 0x96f17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x650(%rbp), %rdi
callq 0xa240
leaq -0x630(%rbp), %rdi
callq 0xa0f0
jmp 0x96f55
jmp 0x96e65
movb $0x0, -0x1(%rbp)
movl $0x1, -0x654(%rbp)
leaq -0x650(%rbp), %rdi
callq 0xa240
leaq -0x630(%rbp), %rdi
callq 0xa0f0
leaq -0x428(%rbp), %rdi
callq 0xa580
leaq -0x218(%rbp), %rdi
callq 0xa580
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x6a0, %rsp            # imm = 0x6A0
popq %rbp
retq
leaq -0x428(%rbp), %rdi
callq 0xa580
leaq -0x218(%rbp), %rdi
callq 0xa580
movq -0x220(%rbp), %rdi
callq 0xa650
nopl (%rax)