// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rsi, %r14
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(%r14), %r15
addq $0x38, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x41f0
leaq 0x158(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x4390
movq (%r12), %r12
leaq 0x90(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4390
leaq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x10282
movl %eax, %ebp
leaq 0x90(%rsp), %rdi
callq 0x4548
testb %bpl, %bpl
je 0x1d816
leaq 0x178(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x4180
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x5a68(%rip), %rsi      # 0x2317c
leaq 0x28(%rsp), %rdi
callq 0x44e0
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4180
leaq 0x5e27(%rip), %rsi      # 0x2355b
leaq 0xb0(%rsp), %rdi
movq %r15, %rdx
callq 0x4acd
leaq 0x68(%rsp), %rdi
leaq 0xb0(%rsp), %r15
movq %r15, %rsi
callq 0x4340
movq %r15, %rdi
callq 0x4548
leaq 0x28(%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 0x59dc(%rip), %rsi      # 0x2318c
leaq 0xb0(%rsp), %rdi
callq 0x44e0
leaq 0x5d97(%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
jmp 0x1d89a
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x593d(%rip), %rsi      # 0x2318c
leaq 0x28(%rsp), %rdi
callq 0x44e0
leaq 0x5cfb(%rip), %rsi      # 0x2355b
leaq 0xb0(%rsp), %rdi
movq %r15, %rdx
callq 0x4acd
leaq 0x68(%rsp), %rdi
leaq 0xb0(%rsp), %r14
movq %r14, %rsi
callq 0x4340
movq %r14, %rdi
callq 0x4548
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x13a3e
leaq 0x28(%rsp), %rdi
callq 0x81fe
leaq 0x8(%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 0x1d8d1
jmp 0x1d8fc
jmp 0x1d8fc
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x81fe
jmp 0x1d8ff
jmp 0x1d8fc
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x4548
jmp 0x1d90e
movq %rax, %rbx
jmp 0x1d918
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x81fe
jmp 0x1d90e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4548
leaq 0x138(%rsp), %rdi
callq 0x81fe
movq %rbx, %rdi
callq 0x4490
nop