// File: Merulo[P]CompilerJFTT/src/IRs/ThirdIR.cpp
// Function: ThirdIR::legalizeJumpWithZero(Block&)
void ThirdIR::legalizeJumpWithZero(Block& b)
{
    Line lastLine = b.lines.back();
    b.lines.clear();

    std::swap(b.blockIfFalse, b.blockIfTrue);
    std::string argument = lastLine.one;
    if (_symbolTable->isConst(argument))
    {
        Line l;
        l.operation = "JUMP";
        l.two = "#" + b.blockIfTrue;
        b.lines.push_back(l);
        return;
    }
    
    Line l;
    l.operation = "JZERO";
    l.one = argument;
    l.two = "#" + b.blockIfTrue;
    b.lines.push_back(l);

    Line l2;
    l2.operation = "JUMP";
    l2.two = "#" + b.blockIfFalse;
    b.lines.push_back(l2);
}

// Assembly:
subq $0x298, %rsp            # imm = 0x298
movq %rdi, 0x290(%rsp)
movq %rsi, 0x288(%rsp)
movq 0x290(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x288(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
movq %rax, %rsi
leaq 0x220(%rsp), %rdi
callq 0xfb20
movq 0x288(%rsp), %rdi
addq $0x20, %rdi
callq 0x1f100
movq 0x288(%rsp), %rsi
movq %rsi, %rdi
addq $0x58, %rdi
addq $0x38, %rsi
callq 0x2a080
leaq 0x240(%rsp), %rsi
leaq 0x200(%rsp), %rdi
callq 0x4180
jmp 0x41e55
movq 0x28(%rsp), %rdi
callq 0xdde0
movq %rax, 0x20(%rsp)
leaq 0x1d0(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x4180
jmp 0x41e7b
movq 0x20(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x20600
movb %al, 0x1f(%rsp)
jmp 0x41e93
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x41ead
jmp 0x41fce
leaq 0x168(%rsp), %rdi
callq 0xda30
jmp 0x41ebc
leaq 0xf301(%rip), %rsi      # 0x511c4
leaq 0x168(%rsp), %rdi
callq 0x44a0
jmp 0x41ed2
movq 0x288(%rsp), %rdx
addq $0x38, %rdx
leaq 0xf6b7(%rip), %rsi      # 0x5159c
leaq 0x148(%rsp), %rdi
callq 0x5070
jmp 0x41ef4
leaq 0x1a8(%rsp), %rdi
leaq 0x148(%rsp), %rsi
movq %rsi, 0x10(%rsp)
callq 0x4440
movq 0x10(%rsp), %rdi
callq 0x46e8
movq 0x288(%rsp), %rdi
addq $0x20, %rdi
leaq 0x168(%rsp), %rsi
callq 0x297e0
jmp 0x41f33
movl $0x1, 0x144(%rsp)
leaq 0x168(%rsp), %rdi
callq 0xd490
jmp 0x42102
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x42172
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x42165
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
jmp 0x42165
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x168(%rsp), %rdi
callq 0xd490
jmp 0x42165
leaq 0xd8(%rsp), %rdi
callq 0xda30
jmp 0x41fdd
leaq 0xf1d0(%rip), %rsi      # 0x511b4
leaq 0xd8(%rsp), %rdi
callq 0x44a0
jmp 0x41ff3
leaq 0xf8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x4050
jmp 0x4200a
movq 0x288(%rsp), %rdx
addq $0x38, %rdx
leaq 0xf57f(%rip), %rsi      # 0x5159c
leaq 0xb8(%rsp), %rdi
callq 0x5070
jmp 0x4202c
leaq 0x118(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
movq %rsi, 0x8(%rsp)
callq 0x4440
movq 0x8(%rsp), %rdi
callq 0x46e8
movq 0x288(%rsp), %rdi
addq $0x20, %rdi
leaq 0xd8(%rsp), %rsi
callq 0x297e0
jmp 0x4206b
leaq 0x50(%rsp), %rdi
callq 0xda30
jmp 0x42077
leaq 0xf146(%rip), %rsi      # 0x511c4
leaq 0x50(%rsp), %rdi
callq 0x44a0
jmp 0x4208a
movq 0x288(%rsp), %rdx
addq $0x58, %rdx
leaq 0xf4ff(%rip), %rsi      # 0x5159c
leaq 0x30(%rsp), %rdi
callq 0x5070
jmp 0x420a9
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %rsi, (%rsp)
callq 0x4440
movq (%rsp), %rdi
callq 0x46e8
movq 0x288(%rsp), %rdi
addq $0x20, %rdi
leaq 0x50(%rsp), %rsi
callq 0x297e0
jmp 0x420e0
leaq 0x50(%rsp), %rdi
callq 0xd490
leaq 0xd8(%rsp), %rdi
callq 0xd490
movl $0x0, 0x144(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x46e8
leaq 0x220(%rsp), %rdi
callq 0xd490
addq $0x298, %rsp            # imm = 0x298
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x42158
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xd490
leaq 0xd8(%rsp), %rdi
callq 0xd490
leaq 0x200(%rsp), %rdi
callq 0x46e8
leaq 0x220(%rsp), %rdi
callq 0xd490
movq 0x1f8(%rsp), %rdi
callq 0x45f0
nopl (%rax)