// File: Merulo[P]CompilerJFTT/src/IRs/ThirdIR.cpp
// Function: ThirdIR::legalizeJLS(Block&, bool)
void ThirdIR::legalizeJLS(Block& b, bool inc)
{
    if (checkZeroJump(b) && !inc)
    {
        std::swap(b.lines.back().one, b.lines.back().two);
        legalizeJumpWithZero(b);
        return;
    }
    if (checkZeroJump(b) && inc)
    {
        std::swap(b.lines.back().one, b.lines.back().two);
        legalizeJumpWithEqualZero(b);
        return;
    }
    Line lastLine = b.lines.back();
    b.lines.pop_back();

    std::string var = calculateDiff(b, lastLine.two, lastLine.one, inc);
    insertJumps(b, var);
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movb %dl, %al
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
andb $0x1, %al
movb %al, 0x127(%rsp)
movq 0x130(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movq 0x128(%rsp), %rsi
callq 0x41850
testb $0x1, %al
jne 0x40bb2
jmp 0x40c0f
testb $0x1, 0x127(%rsp)
jne 0x40c0f
movq 0x128(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
addq $0x20, %rax
movq %rax, 0x18(%rsp)
movq 0x128(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
movq 0x18(%rsp), %rdi
movq %rax, %rsi
addq $0x40, %rsi
callq 0x2a080
movq 0x20(%rsp), %rdi
movq 0x128(%rsp), %rsi
callq 0x41dd0
jmp 0x40d88
movq 0x20(%rsp), %rdi
movq 0x128(%rsp), %rsi
callq 0x41850
testb $0x1, %al
jne 0x40c27
jmp 0x40c84
testb $0x1, 0x127(%rsp)
je 0x40c84
movq 0x128(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
addq $0x20, %rax
movq %rax, 0x10(%rsp)
movq 0x128(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
movq 0x10(%rsp), %rdi
movq %rax, %rsi
addq $0x40, %rsi
callq 0x2a080
movq 0x20(%rsp), %rdi
movq 0x128(%rsp), %rsi
callq 0x42190
jmp 0x40d88
movq 0x128(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
callq 0xfb20
movq 0x128(%rsp), %rdi
addq $0x20, %rdi
callq 0x428a0
movq 0x128(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x4180
jmp 0x40cd7
leaq 0xd8(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x4180
jmp 0x40ceb
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rsi
movzbl 0x127(%rsp), %r9d
andl $0x1, %r9d
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rcx
leaq 0x48(%rsp), %r8
callq 0x41420
jmp 0x40d1b
leaq 0x48(%rsp), %rdi
callq 0x46e8
leaq 0x78(%rsp), %rdi
callq 0x46e8
movq 0x128(%rsp), %rax
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x4180
jmp 0x40d4f
movq (%rsp), %rsi
movq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x416b0
jmp 0x40d64
leaq 0x28(%rsp), %rdi
callq 0x46e8
leaq 0x98(%rsp), %rdi
callq 0x46e8
leaq 0xb8(%rsp), %rdi
callq 0xd490
addq $0x138, %rsp            # imm = 0x138
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x40e09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x40dc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x46e8
leaq 0x78(%rsp), %rdi
callq 0x46e8
jmp 0x40e09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x40dfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x46e8
leaq 0x98(%rsp), %rdi
callq 0x46e8
leaq 0xb8(%rsp), %rdi
callq 0xd490
movq 0x70(%rsp), %rdi
callq 0x45f0