// File: /workspace/github_cpp_makefile_star2_O2/Manuel123cool[P]smiley/instruction.cpp
// Function: Instruction::checkIf(int, Stack&)
int Instruction::checkIf(int whichInstr, Stack &stack)
{
    std::string code{ m_instructions.at(whichInstr) };
    if (code.length() <= 0)
        return -1;

    if (!MyRegex::testString(code, ":/ "))
        return -1;
    
    std::string identifier;
    bool start{ false };
    for(const auto &c : code) 
    {
        if (c == ' ' && start)
            break; 

        if (start)
            identifier += c;

        if (c == ' ' && !start)
            start = true;
    }     
    std::string value{ stack().getValueVar(identifier) };

    if (value == "true")
    {
        return whichInstr;
    }
    else 
    {
        int countBlockStarts{ 0 };
        for (int i{ whichInstr }; i < m_instructions.size(); ++i)  
        {
            std::string code{ m_instructions.at(i) };

            if (MyRegex::testString(code, "><"))
                ++countBlockStarts;

            if (MyRegex::testString(code, "<>"))
                --countBlockStarts;

            if (MyRegex::testString(code, "<>") && countBlockStarts == 0)
                return i;
            
        }
    }
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdx, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
addq $0x18, %rdi
movl %esi, 0xc(%rsp)
movslq %esi, %rsi
movq %rdi, 0x18(%rsp)
movq %rsi, %r14
callq 0x94c4
leaq 0x48(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x21e0
pushq $-0x1
popq %rbp
cmpq $0x0, 0x8(%r15)
je 0x8cbc
leaq 0xe8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x21e0
leaq 0x18d9(%rip), %rsi      # 0xa2ff
leaq 0xc8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x57ec
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x5ddc
movl %eax, %r15d
leaq 0xc8(%rsp), %rdi
callq 0x20c0
leaq 0xe8(%rsp), %rdi
callq 0x20c0
testb %r15b, %r15b
je 0x8cbc
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x48(%rsp), %r12
movq 0x50(%rsp), %r13
xorl %ebp, %ebp
leaq 0x28(%rsp), %r15
xorl %ebx, %ebx
cmpq %rbp, %r13
je 0x8ac2
movb (%r12,%rbp), %al
cmpb $0x20, %al
jne 0x8aad
testb $0x1, %bl
movb $0x1, %bl
je 0x8abd
jmp 0x8ac2
testb $0x1, %bl
je 0x8abd
movsbl %al, %esi
movq %r15, %rdi
callq 0x2140
incq %rbp
jmp 0x8a97
movq 0x10(%rsp), %rdi
callq 0x77fe
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x21e0
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
movq %rbx, %rsi
callq 0x310e
leaq 0x88(%rsp), %rdi
callq 0x20c0
leaq 0x15ae(%rip), %rsi      # 0xa0bb
leaq 0xa8(%rsp), %rdi
callq 0x58aa
testb %al, %al
jne 0x8ca1
xorl %r12d, %r12d
pushq $-0x1
popq %rax
movl %eax, 0xc(%rsp)
leaq 0x1a8(%rsp), %r15
leaq 0x68(%rsp), %rbx
leaq 0x148(%rsp), %r13
movq %r14, %rsi
movq 0x20(%rsp), %rcx
movq 0x20(%rcx), %rax
subq 0x18(%rcx), %rax
sarq $0x5, %rax
cmpq %rsi, %rax
jbe 0x8ca1
movq 0x18(%rsp), %rdi
movq %rsi, 0x10(%rsp)
callq 0x94c4
movq %r15, %rdi
movq %rax, %rsi
callq 0x21e0
movq %rbx, %rdi
movq %r15, %r14
movq %r15, %rsi
callq 0x21e0
leaq 0x188(%rsp), %r15
movq %r15, %rdi
leaq 0x1761(%rip), %rsi      # 0xa2f9
leaq 0xa(%rsp), %rdx
callq 0x57ec
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5ddc
movb %al, 0xb(%rsp)
leaq 0x128(%rsp), %rbp
movq %r15, %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x20c0
movq %rbp, %rdi
movq %r14, %rsi
callq 0x21e0
leaq 0x168(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1711(%rip), %rsi      # 0xa2fc
leaq 0xa(%rsp), %rdx
callq 0x57ec
leaq 0x128(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x5ddc
movq %rbp, %rdi
movl %eax, %ebp
callq 0x20c0
movq %rbx, %rdi
callq 0x20c0
leaq 0x108(%rsp), %rdi
movq %r14, %rsi
callq 0x21e0
movq %r13, %rdi
leaq 0x16c8(%rip), %rsi      # 0xa2fc
leaq 0xa(%rsp), %rdx
callq 0x57ec
leaq 0x108(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x5ddc
movl %eax, %ebx
movzbl 0xb(%rsp), %eax
addl %eax, %r12d
movzbl %bpl, %eax
subl %eax, %r12d
sete %bpl
movq %r13, %rdi
callq 0x20c0
movq %r15, %rdi
callq 0x20c0
movq %r14, %r15
movq %r14, %rdi
callq 0x20c0
testb %bpl, %bl
jne 0x8c98
movq 0x10(%rsp), %rsi
incq %rsi
leaq 0x68(%rsp), %rbx
jmp 0x8b44
movq 0x10(%rsp), %rax
movl %eax, 0xc(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x20c0
leaq 0x28(%rsp), %rdi
callq 0x20c0
movl 0xc(%rsp), %ebp
leaq 0x48(%rsp), %rdi
callq 0x20c0
movl %ebp, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x8d9a
jmp 0x8d16
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x20c0
jmp 0x8d01
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x8da4
movq %rax, %rbx
jmp 0x8da9
movq %rax, %rbx
jmp 0x8d9f
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
callq 0x20c0
jmp 0x8d4a
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
callq 0x20c0
jmp 0x8d54
movq %rax, %rbx
jmp 0x8d6e
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x8d76
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0x8d76
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x20c0
leaq 0x108(%rsp), %rdi
callq 0x20c0
jmp 0x8d85
movq %rax, %rbx
jmp 0x8d92
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x20c0
leaq 0xa8(%rsp), %rdi
callq 0x20c0
leaq 0x28(%rsp), %rdi
callq 0x20c0
leaq 0x48(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2250
nop