// File: Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::checkPowerOfTwoMul(Line&, Block&, unsigned long)
void SecondIR::checkPowerOfTwoMul(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;
    }
    unsigned long long number = std::stoull(value);
    if ((number & (number - 1)) != 0)
    {
        return;
    }

    Line addLine;
    addLine.operation = "ADD";
    addLine.one = l.one;
    addLine.two = 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 0x2ed81
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 0x2eda2
jmp 0x2edcd
jmp 0x2f16d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x46e8
jmp 0x2f18f
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 0x2ee13
leaq 0x158(%rsp), %rdi
callq 0x46e8
leaq 0x2274f(%rip), %rsi     # 0x51576
leaq 0x178(%rsp), %rdi
callq 0xdd10
movb %al, 0x1f(%rsp)
jmp 0x2ee3a
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x2ee47
jmp 0x2ef77
movq 0x1d8(%rsp), %rdi
leaq 0x2270c(%rip), %rsi     # 0x51562
callq 0x44a0
jmp 0x2ee5d
movq 0x1d8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x138(%rsp), %rdi
callq 0x4180
jmp 0x2ee78
movq 0x1d8(%rsp), %rdi
addq $0x40, %rdi
leaq 0x226eb(%rip), %rsi     # 0x51576
callq 0x44a0
jmp 0x2ee92
leaq 0x118(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x4180
jmp 0x2eea9
movq 0x38(%rsp), %rdi
movq 0x1d0(%rsp), %rdx
leaq 0x118(%rsp), %rsi
callq 0x2e010
jmp 0x2eec5
leaq 0x118(%rsp), %rdi
callq 0x46e8
movl $0x1, 0x114(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x46e8
jmp 0x2f160
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x46e8
jmp 0x2f18f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x2f182
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x2ef65
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 0x2f182
xorl %eax, %eax
movl %eax, %esi
leaq 0x178(%rsp), %rdi
movl $0xa, %edx
callq 0xdd90
movq %rax, 0x10(%rsp)
jmp 0x2ef94
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 0x2efce
movl $0x1, 0x114(%rsp)
jmp 0x2f160
leaq 0xa0(%rsp), %rdi
callq 0xda30
jmp 0x2efdd
leaq 0x220f6(%rip), %rsi     # 0x510da
leaq 0xa0(%rsp), %rdi
callq 0x44a0
jmp 0x2eff3
movq 0x1d8(%rsp), %rsi
addq $0x20, %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4050
jmp 0x2f00e
movq 0x1d8(%rsp), %rsi
addq $0x20, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x4050
jmp 0x2f029
movq 0x1d8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x80(%rsp), %rdi
callq 0x4180
jmp 0x2f044
movq 0x38(%rsp), %rdi
movq 0x1d0(%rsp), %rdx
leaq 0x80(%rsp), %rsi
callq 0x2e010
jmp 0x2f060
leaq 0x80(%rsp), %rdi
callq 0x46e8
cmpq $0x1, 0x108(%rsp)
je 0x2f148
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 0x2f0ed
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x108(%rsp), %rax
shrq %rax
movq %rax, 0x108(%rsp)
jmp 0x2f06d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x2f175
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x46e8
jmp 0x2f175
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
nopl (%rax)