// File: Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::checkPowerOfTwoDiv(Line&, Block&, unsigned long)
void SecondIR::checkPowerOfTwoDiv(Line& l, Block& b, size_t i)
{
    if (!_symbolTable->isConst(l.two))
    {
        return;
    }
    std::string value = _symbolTable->getConstValue(l.two);
    if (value == "0")
    {
        l.operation = "CONST";
        std::string arg = l.two;
        l.two = "0";
        stripVariable(arg, b);
        return;
    }
    if (value == "NAN")
    {
        return;
    }
    unsigned long long number = std::stoull(value);
    if ((number & (number - 1)) != 0)
    {
        return;
    }

    Line addLine;
    addLine.operation = "HALF";
    addLine.one = l.one;

    stripVariable(l.two, b);

    while (number != 1)
    {
        b.lines.insert(b.lines.begin() + i - 1, addLine);
        number = number / 2;
    }
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, 0x1e0(%rsp)
movq %rsi, 0x1d8(%rsp)
movq %rdx, 0x1d0(%rsp)
movq %rcx, 0x1c8(%rsp)
movq 0x1e0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xdde0
movq %rax, 0x40(%rsp)
movq 0x1d8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x4180
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x20600
movb %al, 0x57(%rsp)
jmp 0x2f211
movb 0x57(%rsp), %al
xorb $-0x1, %al
movb %al, 0x37(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x46e8
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x2f232
jmp 0x2f25d
jmp 0x2f616
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x46e8
jmp 0x2f638
movq 0x38(%rsp), %rdi
callq 0xdde0
movq %rax, 0x20(%rsp)
movq 0x1d8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x158(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4180
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x178(%rsp), %rdi
callq 0x21240
jmp 0x2f2a3
leaq 0x158(%rsp), %rdi
callq 0x46e8
leaq 0x222bf(%rip), %rsi     # 0x51576
leaq 0x178(%rsp), %rdi
callq 0xdd10
movb %al, 0x1f(%rsp)
jmp 0x2f2ca
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x2f2d7
jmp 0x2f407
movq 0x1d8(%rsp), %rdi
leaq 0x2227c(%rip), %rsi     # 0x51562
callq 0x44a0
jmp 0x2f2ed
movq 0x1d8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x138(%rsp), %rdi
callq 0x4180
jmp 0x2f308
movq 0x1d8(%rsp), %rdi
addq $0x40, %rdi
leaq 0x2225b(%rip), %rsi     # 0x51576
callq 0x44a0
jmp 0x2f322
leaq 0x118(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x4180
jmp 0x2f339
movq 0x38(%rsp), %rdi
movq 0x1d0(%rsp), %rdx
leaq 0x118(%rsp), %rsi
callq 0x2e010
jmp 0x2f355
leaq 0x118(%rsp), %rdi
callq 0x46e8
movl $0x1, 0x114(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x46e8
jmp 0x2f609
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x46e8
jmp 0x2f638
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x2f62b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x2f3f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x46e8
leaq 0x138(%rsp), %rdi
callq 0x46e8
jmp 0x2f62b
leaq 0x220a6(%rip), %rsi     # 0x514b4
leaq 0x178(%rsp), %rdi
callq 0xdd10
movb %al, 0x1e(%rsp)
jmp 0x2f421
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x2f42b
jmp 0x2f43b
movl $0x1, 0x114(%rsp)
jmp 0x2f609
xorl %eax, %eax
movl %eax, %esi
leaq 0x178(%rsp), %rdi
movl $0xa, %edx
callq 0xdd90
movq %rax, 0x10(%rsp)
jmp 0x2f458
movq 0x10(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rax
movq 0x108(%rsp), %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x2f492
movl $0x1, 0x114(%rsp)
jmp 0x2f609
leaq 0xa0(%rsp), %rdi
callq 0xda30
jmp 0x2f4a1
leaq 0x21d17(%rip), %rsi     # 0x511bf
leaq 0xa0(%rsp), %rdi
callq 0x44a0
jmp 0x2f4b7
movq 0x1d8(%rsp), %rsi
addq $0x20, %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4050
jmp 0x2f4d2
movq 0x1d8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x80(%rsp), %rdi
callq 0x4180
jmp 0x2f4ed
movq 0x38(%rsp), %rdi
movq 0x1d0(%rsp), %rdx
leaq 0x80(%rsp), %rsi
callq 0x2e010
jmp 0x2f509
leaq 0x80(%rsp), %rdi
callq 0x46e8
cmpq $0x1, 0x108(%rsp)
je 0x2f5f1
movq 0x1d0(%rsp), %rdi
addq $0x20, %rdi
movq %rdi, (%rsp)
callq 0xe3f0
movq %rax, 0x60(%rsp)
movq 0x1c8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0xe510
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
movl $0x1, %esi
callq 0x118b0
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe3b0
movq (%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x30e70
movq %rax, 0x8(%rsp)
jmp 0x2f596
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x108(%rsp), %rax
shrq %rax
movq %rax, 0x108(%rsp)
jmp 0x2f516
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x2f61e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x46e8
jmp 0x2f61e
leaq 0xa0(%rsp), %rdi
callq 0xd490
movl $0x0, 0x114(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x46e8
addq $0x1e8, %rsp            # imm = 0x1E8
retq
leaq 0xa0(%rsp), %rdi
callq 0xd490
leaq 0x178(%rsp), %rdi
callq 0x46e8
movq 0x1a0(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)