// File: /workspace/github_cpp_makefile_star2_O3/Manuel123cool[P]smiley/instruction.cpp
// Function: Instruction::checkLoop(int, Stack&)
int Instruction::checkLoop(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")
    {
        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)
            {
                Jump jump;
                jump.start = i;
                jump.jumpTo = whichInstr;
                m_jumps.push_back(jump); 
            }
        }       
    }
    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 $0x298, %rsp            # imm = 0x298
movq %rdx, 0x8(%rsp)
movl %esi, 0x54(%rsp)
movslq %esi, %r14
movq 0x18(%rdi), %rax
movq %rdi, 0x38(%rsp)
movq 0x20(%rdi), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0xcf7e
movq %r14, %rdx
shlq $0x5, %rdx
leaq 0x68(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax,%rdx), %rsi
movq %rdx, %rbx
movq 0x8(%rax,%rdx), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %r12
movq %r12, %rdi
callq 0x2a32
movq 0x8(%r12), %rdx
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
testq %rdx, %rdx
je 0xcf4c
leaq 0x268(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x58(%rsp), %rsi
addq %rsi, %rdx
leaq 0x258(%rsp), %rdi
callq 0x2a32
leaq 0x248(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1bc7(%rip), %rsi      # 0xe36a
leaq 0x1bc3(%rip), %rdx      # 0xe36d
leaq 0x238(%rsp), %rdi
callq 0x79c6
leaq 0x258(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x7d88
movl %eax, %ebp
movq 0x238(%rsp), %rdi
cmpq %r15, %rdi
je 0xc7eb
movq 0x248(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x258(%rsp), %rdi
cmpq %r12, %rdi
je 0xc808
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x2170
testb %bpl, %bpl
je 0xcf4c
leaq 0x108(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x60(%rsp), %r13
testq %r13, %r13
je 0xc86f
movq 0x58(%rsp), %rbp
xorl %r15d, %r15d
xorl %r12d, %r12d
movb (%rbp,%r15), %al
cmpb $0x20, %al
jne 0xc851
testb $0x1, %r12b
movb $0x1, %r12b
je 0xc867
jmp 0xc86f
testb $0x1, %r12b
je 0xc867
movsbl %al, %esi
leaq 0xf8(%rsp), %rdi
callq 0x2120
incq %r15
cmpq %r15, %r13
jne 0xc83d
movq 0x8(%rsp), %rdi
callq 0xa598
movq %rax, %r15
leaq 0x228(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0xf8(%rsp), %rsi
movq 0x100(%rsp), %rdx
addq %rsi, %rdx
leaq 0x218(%rsp), %rdi
callq 0x2a32
leaq 0x278(%rsp), %rdi
leaq 0x218(%rsp), %rdx
movq %r15, %rsi
callq 0x3908
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0xc8de
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x1800(%rip), %rsi      # 0xe0e5
leaq 0x278(%rsp), %rdi
callq 0x2070
movq 0x38(%rsp), %rdx
movq 0x18(%rdx), %rcx
movq 0x20(%rdx), %rdx
subq %rcx, %rdx
sarq $0x5, %rdx
testl %eax, %eax
je 0xcbe7
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
cmpq %r14, %rdx
jbe 0xcf06
movq %rbx, %rdx
movq %r14, 0x8(%rsp)
orq $0x8, %rdx
movl $0x0, 0x4(%rsp)
leaq 0x178(%rsp), %rbp
leaq 0x138(%rsp), %r13
leaq 0x118(%rsp), %rbx
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq -0x8(%rcx,%rdx), %rsi
movq %rdx, 0x40(%rsp)
movq (%rcx,%rdx), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0x2a32
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x2a32
leaq 0x188(%rsp), %rax
movq %rax, 0x178(%rsp)
movq %rbp, %r15
movq %rbp, %rdi
leaq 0x19a9(%rip), %rsi      # 0xe360
leaq 0x19a4(%rip), %rdx      # 0xe362
callq 0x79c6
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x7d88
movl %eax, %r12d
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0xc9fb
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xca20
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x2a32
leaq 0x168(%rsp), %rax
movq %rax, 0x158(%rsp)
leaq 0x158(%rsp), %r15
movq %r15, %rdi
leaq 0x18fd(%rip), %rsi      # 0xe363
leaq 0x18f8(%rip), %rdx      # 0xe365
callq 0x79c6
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x7d88
movl %eax, %r15d
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0xcaa7
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xcac9
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x148(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x2a32
leaq 0x128(%rsp), %rax
movq %rax, 0x118(%rsp)
movq %rbx, %rdi
leaq 0x185b(%rip), %rsi      # 0xe363
leaq 0x1856(%rip), %rdx      # 0xe365
callq 0x79c6
movq %rbx, %rsi
movq %r13, %r14
movq %r13, %rdi
callq 0x7d88
movl %eax, %r13d
movzbl %r12b, %eax
movl 0x4(%rsp), %ecx
addl %eax, %ecx
movzbl %r15b, %eax
subl %eax, %ecx
movl %ecx, 0x4(%rsp)
sete %r15b
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0xcb62
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0xcb87
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xcba3
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2170
andb %r15b, %r13b
jne 0xcefd
movq 0x8(%rsp), %rsi
incq %rsi
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rax
subq %rcx, %rax
sarq $0x5, %rax
movq 0x40(%rsp), %rdx
addq $0x20, %rdx
movq %rsi, 0x8(%rsp)
cmpq %rsi, %rax
movq %r14, %r13
ja 0xc94b
jmp 0xcf06
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
cmpq %r14, %rdx
jbe 0xcf06
movq %r14, 0x8(%rsp)
orq $0x8, %rbx
movl $0x0, 0x4(%rsp)
leaq 0x1f8(%rsp), %r15
leaq 0x1d8(%rsp), %r14
leaq 0x1b8(%rsp), %rbp
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq -0x8(%rcx,%rbx), %rsi
movq %rbx, 0x40(%rsp)
movq (%rcx,%rbx), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0x2a32
leaq 0xe8(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x2a32
leaq 0x198(%rsp), %rbx
leaq 0x208(%rsp), %rax
movq %rax, 0x1f8(%rsp)
movq %r15, %r12
movq %r15, %rdi
leaq 0x16cb(%rip), %rsi      # 0xe360
leaq 0x16c6(%rip), %rdx      # 0xe362
callq 0x79c6
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x7d88
movl %eax, %r13d
movq 0x1f8(%rsp), %rdi
leaq 0x208(%rsp), %rax
cmpq %rax, %rdi
je 0xccd9
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0xccfe
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x2a32
leaq 0x1e8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
movq %r14, %r12
movq %r14, %rdi
leaq 0x161e(%rip), %rsi      # 0xe363
leaq 0x1619(%rip), %rdx      # 0xe365
callq 0x79c6
leaq 0xb8(%rsp), %rdi
movq %r12, %rsi
callq 0x7d88
movl %eax, %r12d
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0xcd89
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xcdae
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x1c8(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x2a32
leaq 0x1a8(%rsp), %rax
movq %rax, 0x198(%rsp)
movq %rbx, %rdi
leaq 0x1576(%rip), %rsi      # 0xe363
leaq 0x1571(%rip), %rdx      # 0xe365
callq 0x79c6
movq %rbx, %rsi
movq %rbp, %rbx
movq %rbp, %rdi
callq 0x7d88
movl %eax, %ebp
movzbl %r13b, %eax
movl 0x4(%rsp), %ecx
addl %eax, %ecx
movzbl %r12b, %eax
subl %eax, %ecx
movl %ecx, 0x4(%rsp)
sete %r12b
movq 0x198(%rsp), %rdi
leaq 0x1a8(%rsp), %rax
cmpq %rax, %rdi
je 0xce46
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x1b8(%rsp), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0xce6b
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x2170
andb %r12b, %bpl
movq %rbx, %rbp
je 0xceac
movq 0x8(%rsp), %rax
movl %eax, 0x48(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x38(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xcea2
movq 0x48(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xceac
leaq 0x48(%rsp), %rdx
callq 0xd58a
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xcec8
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x8(%rsp), %rsi
incq %rsi
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rax
subq %rcx, %rax
sarq $0x5, %rax
movq 0x40(%rsp), %rbx
addq $0x20, %rbx
movq %rsi, 0x8(%rsp)
cmpq %rsi, %rax
ja 0xcc21
jmp 0xcf06
movq 0x8(%rsp), %rax
movl %eax, 0x14(%rsp)
leaq 0x288(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xcf27
movq 0x288(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0xcf4c
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xcf68
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2170
movl 0x14(%rsp), %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x119c(%rip), %rdi      # 0xe121
movq %r14, %rsi
xorl %eax, %eax
callq 0x2210
movq %rax, %rbx
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0xd250
movq 0x228(%rsp), %rsi
jmp 0xd248
jmp 0xd210
jmp 0xd002
movq %rax, %rbx
movq 0x238(%rsp), %rdi
cmpq %r15, %rdi
je 0xcfdc
movq 0x248(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xcfdc
movq %rax, %rbx
movq 0x258(%rsp), %rdi
cmpq %r12, %rdi
je 0xd275
movq 0x268(%rsp), %rsi
jmp 0xd26d
movq %rax, %rbx
jmp 0xd275
movq %rax, %rbx
jmp 0xd250
movq %rax, %rbx
jmp 0xd09e
movq %rax, %rbx
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0xd0c7
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xd0c7
movq %rax, %rbx
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0xd0ed
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xd0ed
jmp 0xd113
movq %rax, %rbx
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0xd09e
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0xd213
movq 0x148(%rsp), %rsi
jmp 0xd204
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xd213
movq 0x88(%rsp), %rsi
jmp 0xd204
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xd213
movq 0xa8(%rsp), %rsi
jmp 0xd204
movq %rax, %rbx
jmp 0xd22f
movq %rax, %rbx
jmp 0xd148
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
leaq 0x208(%rsp), %rax
cmpq %rax, %rdi
je 0xd148
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0xd213
movq 0xe8(%rsp), %rsi
jmp 0xd204
movq %rax, %rbx
jmp 0xd19b
movq %rax, %rbx
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0xd19b
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xd213
movq 0xc8(%rsp), %rsi
jmp 0xd204
movq %rax, %rbx
jmp 0xd1e7
movq %rax, %rbx
movq 0x198(%rsp), %rdi
leaq 0x1a8(%rsp), %rax
cmpq %rax, %rdi
je 0xd1e7
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x1b8(%rsp), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0xd213
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xd213
jmp 0xd210
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xd22f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x288(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd250
movq 0x288(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0xd275
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xd291
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2250
nop