// File: johan-bjareholt[P]lua-compiler/src/ir.cc
// Function: BBlock::dumpDot(std::ostream&)
void BBlock::dumpDot(std::ostream& ss){
    traversed_blocks.insert(this);
    // Def self
    ss  << '"' << this << '"' << std::endl;
    // Set self string
    if (this->label.empty())
        ss  << "[" << "label=\"" << this << "" << std::endl;
    else
        ss  << "[" << "label=\"" << this->label << "" << std::endl;
    std::stringstream ss_code;
    for(auto i : instructions){
        i.dump(ss_code);
    }
    // Handle " in the code so it doesn't escape
    std::string code_s = ss_code.str();
    for (int i = 0; i < code_s.length(); i++) {
        //std::cout << i << std::endl;
        if (code_s[i] == '"'){
            code_s[i] = '\'';
        }
    }
    ss << code_s;
    // Close self def
    ss << "\"];" << std::endl;
    // Connect to subs
    if (trueExit)
        ss  << "    \"" << this << "\" -> \"" << trueExit << "\";" << std::endl;
    if (falseExit)
        ss  << "    \"" << this << "\" -> \"" << falseExit << "\";"<< std::endl;
    // Dumpdot subs
    bool trueExitFound = traversed_blocks.find(trueExit) != traversed_blocks.end();
    if (trueExit && !trueExitFound)
        trueExit->dumpDot(ss);
    bool falseExitFound = traversed_blocks.find(falseExit) != traversed_blocks.end();
    if (falseExit && !falseExitFound)
        falseExit->dumpDot(ss);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x298(%rbp)
movq %rax, -0x18(%rbp)
leaq 0x379d7(%rip), %rdi     # 0x3e390
leaq -0x18(%rbp), %rsi
callq 0x9f30
movq %rax, -0x28(%rbp)
movb %dl, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl $0x22, %esi
callq 0x3300
movq -0x298(%rbp), %rsi
movq %rax, %rdi
callq 0x3200
movq %rax, %rdi
movl $0x22, %esi
callq 0x3300
movq %rax, %rdi
movq 0x375a3(%rip), %rsi     # 0x3dfa0
callq 0x32a0
movq -0x298(%rbp), %rdi
addq $0x28, %rdi
callq 0x3480
testb $0x1, %al
jne 0x6a18
jmp 0x6a66
movq -0x10(%rbp), %rdi
leaq 0x24d13(%rip), %rsi     # 0x2b736
callq 0x3260
movq %rax, %rdi
leaq 0x247cb(%rip), %rsi     # 0x2b1fd
callq 0x3260
movq -0x298(%rbp), %rsi
movq %rax, %rdi
callq 0x3200
movq %rax, %rdi
leaq 0x24aca(%rip), %rsi     # 0x2b51a
callq 0x3260
movq %rax, %rdi
movq 0x37541(%rip), %rsi     # 0x3dfa0
callq 0x32a0
jmp 0x6ab6
movq -0x10(%rbp), %rdi
leaq 0x24cc5(%rip), %rsi     # 0x2b736
callq 0x3260
movq %rax, %rdi
leaq 0x2477d(%rip), %rsi     # 0x2b1fd
callq 0x3260
movq -0x298(%rbp), %rsi
movq %rax, %rdi
addq $0x28, %rsi
callq 0x3220
movq %rax, %rdi
leaq 0x24a78(%rip), %rsi     # 0x2b51a
callq 0x3260
movq %rax, %rdi
movq 0x374ef(%rip), %rsi     # 0x3dfa0
callq 0x32a0
leaq -0x1b0(%rbp), %rdi
callq 0x31d0
movq -0x298(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq -0x1b8(%rbp), %rdi
callq 0x9c40
movq %rax, -0x1c0(%rbp)
movq -0x1b8(%rbp), %rdi
callq 0x9c70
movq %rax, -0x1c8(%rbp)
leaq -0x1c0(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x9ca0
testb $0x1, %al
jne 0x6b12
jmp 0x6b98
leaq -0x1c0(%rbp), %rdi
callq 0x9cd0
movq %rax, %rsi
leaq -0x230(%rbp), %rdi
callq 0x9d00
jmp 0x6b2f
leaq -0x1a0(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x6600
jmp 0x6b44
leaq -0x230(%rbp), %rdi
callq 0x9db0
leaq -0x1c0(%rbp), %rdi
callq 0x9df0
jmp 0x6af6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x6f59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x9db0
jmp 0x6f59
leaq -0x260(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x3250
jmp 0x6bad
movl $0x0, -0x264(%rbp)
movslq -0x264(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x3410
movq %rax, %rcx
movq -0x2a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x6c70
movslq -0x264(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x3510
movq %rax, -0x2a8(%rbp)
jmp 0x6c00
movq -0x2a8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x6c5a
movslq -0x264(%rbp), %rsi
leaq -0x260(%rbp), %rdi
callq 0x3510
movq %rax, -0x2b0(%rbp)
jmp 0x6c2b
movq -0x2b0(%rbp), %rax
movb $0x27, (%rax)
jmp 0x6c5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x3528
jmp 0x6f59
jmp 0x6c5c
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
jmp 0x6bb7
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x3220
jmp 0x6c82
movq -0x10(%rbp), %rdi
leaq 0x24578(%rip), %rsi     # 0x2b205
callq 0x3260
movq %rax, -0x2b8(%rbp)
jmp 0x6c9b
movq -0x2b8(%rbp), %rdi
movq 0x372f7(%rip), %rsi     # 0x3dfa0
callq 0x32a0
jmp 0x6cb0
movq -0x298(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x6d66
movq -0x10(%rbp), %rdi
leaq 0x2453c(%rip), %rsi     # 0x2b209
callq 0x3260
movq %rax, -0x2c0(%rbp)
jmp 0x6cdb
movq -0x298(%rbp), %rsi
movq -0x2c0(%rbp), %rdi
callq 0x3200
movq %rax, -0x2c8(%rbp)
jmp 0x6cf7
movq -0x2c8(%rbp), %rdi
leaq 0x2450a(%rip), %rsi     # 0x2b20f
callq 0x3260
movq %rax, -0x2d0(%rbp)
jmp 0x6d13
movq -0x2d0(%rbp), %rdi
movq -0x298(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x3200
movq %rax, -0x2d8(%rbp)
jmp 0x6d33
movq -0x2d8(%rbp), %rdi
leaq 0x24493(%rip), %rsi     # 0x2b1d4
callq 0x3260
movq %rax, -0x2e0(%rbp)
jmp 0x6d4f
movq -0x2e0(%rbp), %rdi
movq 0x37243(%rip), %rsi     # 0x3dfa0
callq 0x32a0
jmp 0x6d64
jmp 0x6d66
movq -0x298(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6e1c
movq -0x10(%rbp), %rdi
leaq 0x24486(%rip), %rsi     # 0x2b209
callq 0x3260
movq %rax, -0x2e8(%rbp)
jmp 0x6d91
movq -0x298(%rbp), %rsi
movq -0x2e8(%rbp), %rdi
callq 0x3200
movq %rax, -0x2f0(%rbp)
jmp 0x6dad
movq -0x2f0(%rbp), %rdi
leaq 0x24454(%rip), %rsi     # 0x2b20f
callq 0x3260
movq %rax, -0x2f8(%rbp)
jmp 0x6dc9
movq -0x2f8(%rbp), %rdi
movq -0x298(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x3200
movq %rax, -0x300(%rbp)
jmp 0x6de9
movq -0x300(%rbp), %rdi
leaq 0x243dd(%rip), %rsi     # 0x2b1d4
callq 0x3260
movq %rax, -0x308(%rbp)
jmp 0x6e05
movq -0x308(%rbp), %rdi
movq 0x3718d(%rip), %rsi     # 0x3dfa0
callq 0x32a0
jmp 0x6e1a
jmp 0x6e1c
movq -0x298(%rbp), %rsi
addq $0x18, %rsi
leaq 0x37562(%rip), %rdi     # 0x3e390
callq 0x9fb0
movq %rax, -0x310(%rbp)
jmp 0x6e3c
movq -0x310(%rbp), %rax
movq %rax, -0x270(%rbp)
leaq 0x3753f(%rip), %rdi     # 0x3e390
callq 0x9ff0
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x9f80
movb %al, %cl
movq -0x298(%rbp), %rax
andb $0x1, %cl
movb %cl, -0x265(%rbp)
cmpq $0x0, 0x18(%rax)
je 0x6eaa
testb $0x1, -0x265(%rbp)
jne 0x6eaa
movq -0x298(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x6990
jmp 0x6ea8
jmp 0x6eaa
movq -0x298(%rbp), %rsi
addq $0x20, %rsi
leaq 0x374d4(%rip), %rdi     # 0x3e390
callq 0x9fb0
movq %rax, -0x318(%rbp)
jmp 0x6eca
movq -0x318(%rbp), %rax
movq %rax, -0x288(%rbp)
leaq 0x374b1(%rip), %rdi     # 0x3e390
callq 0x9ff0
movq %rax, -0x290(%rbp)
leaq -0x288(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x9f80
movb %al, %cl
movq -0x298(%rbp), %rax
andb $0x1, %cl
movb %cl, -0x279(%rbp)
cmpq $0x0, 0x20(%rax)
je 0x6f38
testb $0x1, -0x279(%rbp)
jne 0x6f38
movq -0x298(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x6990
jmp 0x6f36
jmp 0x6f38
leaq -0x260(%rbp), %rdi
callq 0x3528
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
movq -0x238(%rbp), %rdi
callq 0x34b0
nopw %cs:(%rax,%rax)