// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rsi, %r15
movq %rdi, %r12
leaq 0x20(%rsi), %rbx
movq 0x28(%rsi), %rsi
addq $-0x68, %rsi
leaq 0x138(%rsp), %rdi
callq 0x8a26
movq %rbx, %rdi
callq 0xfbda
leaq 0x58(%r15), %r14
addq $0x38, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x41f0
leaq 0x158(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x4390
movq (%r12), %r12
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x4390
leaq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x10282
movl %eax, %ebp
leaq 0x90(%rsp), %rdi
callq 0x4548
leaq 0x18(%rsp), %rax
testb %bpl, %bpl
je 0x1d46c
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x5d70(%rip), %rsi      # 0x2318c
leaq 0x8(%rsp), %rdi
callq 0x44e0
leaq 0x612e(%rip), %rsi      # 0x2355b
leaq 0xb0(%rsp), %rdi
movq %r15, %rdx
callq 0x4acd
leaq 0x48(%rsp), %rdi
leaq 0xb0(%rsp), %r14
movq %r14, %rsi
callq 0x4340
movq %r14, %rdi
callq 0x4548
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x13a3e
jmp 0x1d59d
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x5cdc(%rip), %rsi      # 0x2317c
leaq 0x8(%rsp), %rdi
callq 0x44e0
leaq 0x28(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x4180
leaq 0x609b(%rip), %rsi      # 0x2355b
leaq 0xb0(%rsp), %rdi
movq %r15, %rdx
callq 0x4acd
leaq 0x48(%rsp), %rdi
leaq 0xb0(%rsp), %r15
movq %r15, %rsi
callq 0x4340
movq %r15, %rdi
callq 0x4548
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x13a3e
leaq 0xc0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x100(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x5c50(%rip), %rsi      # 0x2318c
leaq 0xb0(%rsp), %rdi
callq 0x44e0
leaq 0x600b(%rip), %rsi      # 0x2355b
leaq 0x118(%rsp), %rdi
movq %r14, %rdx
callq 0x4acd
leaq 0xf0(%rsp), %rdi
leaq 0x118(%rsp), %r14
movq %r14, %rsi
callq 0x4340
movq %r14, %rdi
callq 0x4548
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0x13a3e
leaq 0xb0(%rsp), %rdi
callq 0x81fe
leaq 0x8(%rsp), %rdi
callq 0x81fe
leaq 0x70(%rsp), %rdi
callq 0x4548
leaq 0x138(%rsp), %rdi
callq 0x81fe
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1d5d4
jmp 0x1d604
jmp 0x1d604
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x81fe
jmp 0x1d607
jmp 0x1d604
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x4548
jmp 0x1d611
movq %rax, %rbx
jmp 0x1d611
movq %rax, %rbx
jmp 0x1d61b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x81fe
leaq 0x70(%rsp), %rdi
callq 0x4548
leaq 0x138(%rsp), %rdi
callq 0x81fe
movq %rbx, %rdi
callq 0x4490