// File: Merulo[P]CompilerJFTT/src/IRs/ThirdIR.cpp
// Function: ThirdIR::legalizeJumpWithEqualZero(Block&)
void ThirdIR::legalizeJumpWithEqualZero(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.blockIfFalse;
        b.lines.push_back(l);
        return;
    }
    argument = lastLine.two;
    
    Line l;
    l.operation = "JZERO";
    l.one = argument;
    l.two = "#" + b.blockIfFalse;
    b.lines.push_back(l);

    Line l2;
    l2.operation = "JUMP";
    l2.two = "#" + b.blockIfTrue;
    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 0x42215
movq 0x28(%rsp), %rdi
callq 0xdde0
movq %rax, 0x20(%rsp)
leaq 0x1d0(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x4180
jmp 0x4223b
movq 0x20(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x20600
movb %al, 0x1f(%rsp)
jmp 0x42253
movb 0x1f(%rsp), %al
xorb $-0x1, %al
movb %al, 0x1e(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x42277
jmp 0x42398
leaq 0x168(%rsp), %rdi
callq 0xda30
jmp 0x42286
leaq 0xef37(%rip), %rsi      # 0x511c4
leaq 0x168(%rsp), %rdi
callq 0x44a0
jmp 0x4229c
movq 0x288(%rsp), %rdx
addq $0x58, %rdx
leaq 0xf2ed(%rip), %rsi      # 0x5159c
leaq 0x148(%rsp), %rdi
callq 0x5070
jmp 0x422be
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 0x422fd
movl $0x1, 0x144(%rsp)
leaq 0x168(%rsp), %rdi
callq 0xd490
jmp 0x424e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x42553
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x42546
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
jmp 0x42546
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x168(%rsp), %rdi
callq 0xd490
jmp 0x42546
leaq 0x260(%rsp), %rsi
leaq 0x200(%rsp), %rdi
callq 0x4050
jmp 0x423af
leaq 0xd8(%rsp), %rdi
callq 0xda30
jmp 0x423be
leaq 0xedef(%rip), %rsi      # 0x511b4
leaq 0xd8(%rsp), %rdi
callq 0x44a0
jmp 0x423d4
leaq 0xf8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x4050
jmp 0x423eb
movq 0x288(%rsp), %rdx
addq $0x58, %rdx
leaq 0xf19e(%rip), %rsi      # 0x5159c
leaq 0xb8(%rsp), %rdi
callq 0x5070
jmp 0x4240d
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 0x4244c
leaq 0x50(%rsp), %rdi
callq 0xda30
jmp 0x42458
leaq 0xed65(%rip), %rsi      # 0x511c4
leaq 0x50(%rsp), %rdi
callq 0x44a0
jmp 0x4246b
movq 0x288(%rsp), %rdx
addq $0x38, %rdx
leaq 0xf11e(%rip), %rsi      # 0x5159c
leaq 0x30(%rsp), %rdi
callq 0x5070
jmp 0x4248a
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 0x424c1
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 0x42539
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)