// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movl %esi, 0xc(%rsp)
movslq %esi, %r14
movq 0x18(%rdi), %rax
movq %rdi, 0x48(%rsp)
movq 0x20(%rdi), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0xd3a5
movq %r14, %rcx
shlq $0x5, %rcx
leaq 0x68(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax,%rcx), %rsi
movq %rcx, 0x38(%rsp)
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x2a3e
movq 0x8(%r15), %rdx
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
testq %rdx, %rdx
je 0xd378
leaq 0x268(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x58(%rsp), %rsi
addq %rsi, %rdx
leaq 0x258(%rsp), %rdi
callq 0x2a3e
leaq 0x248(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x17ea(%rip), %rsi      # 0xe36a
leaq 0x17e6(%rip), %rdx      # 0xe36d
leaq 0x238(%rsp), %rdi
callq 0x7c60
leaq 0x258(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x801c
movl %eax, %r15d
movq 0x238(%rsp), %rdi
cmpq %r12, %rdi
je 0xcbc9
movq 0x248(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x258(%rsp), %rdi
cmpq %r13, %rdi
je 0xcbe6
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x2170
testb %r15b, %r15b
je 0xd378
leaq 0x128(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x60(%rsp), %r13
testq %r13, %r13
je 0xcc6e
movq 0x58(%rsp), %rbp
decq %r13
xorl %r12d, %r12d
xorl %r15d, %r15d
movb (%rbp,%r12), %al
cmpb $0x20, %al
jne 0xcc2f
movb $0x1, %cl
testb $0x1, %r15b
jne 0xcc5d
movb $0x1, %cl
testb $0x1, %r15b
je 0xcc4a
movsbl %al, %esi
leaq 0x118(%rsp), %rdi
callq 0x2120
movl %r15d, %ecx
cmpb $0x20, (%rbp,%r12)
movzbl %cl, %eax
movzbl %r15b, %r15d
cmovel %eax, %r15d
xorl %ecx, %ecx
testb %cl, %cl
jne 0xcc6e
leaq 0x1(%r12), %rax
cmpq %r12, %r13
movq %rax, %r12
jne 0xcc1e
movq %rbx, %rdi
callq 0xa8f4
movq %rax, %r15
leaq 0x228(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
addq %rsi, %rdx
leaq 0x218(%rsp), %rdi
callq 0x2a3e
leaq 0x278(%rsp), %rdi
leaq 0x218(%rsp), %rdx
movq %r15, %rsi
callq 0x3a6a
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0xccdb
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x1403(%rip), %rsi      # 0xe0e5
leaq 0x278(%rsp), %rdi
callq 0x2070
movq 0x48(%rsp), %rdx
movq 0x18(%rdx), %rcx
movq 0x20(%rdx), %rdx
subq %rcx, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
seta %sil
testl %eax, %eax
je 0xd004
cmpq %r14, %rdx
movq 0x38(%rsp), %rdx
jbe 0xd318
movq %r14, 0x30(%rsp)
orq $0x8, %rdx
movl $0x0, 0x44(%rsp)
leaq 0x178(%rsp), %rbp
leaq 0x158(%rsp), %rbx
leaq 0x138(%rsp), %r14
movb %sil, 0xb(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq -0x8(%rcx,%rdx), %rsi
movq %rdx, 0x38(%rsp)
movq (%rcx,%rdx), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x2a3e
leaq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x2a3e
leaq 0x188(%rsp), %rax
movq %rax, 0x178(%rsp)
movq %rbp, %r15
movq %rbp, %rdi
leaq 0x15a6(%rip), %rsi      # 0xe360
leaq 0x15a1(%rip), %rdx      # 0xe362
callq 0x7c60
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0x801c
movl %eax, %r13d
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0xcdfe
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xce23
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x2a3e
leaq 0x168(%rsp), %rax
movq %rax, 0x158(%rsp)
movq %rbx, %r15
movq %rbx, %rdi
leaq 0x14f9(%rip), %rsi      # 0xe363
leaq 0x14f4(%rip), %rdx      # 0xe365
callq 0x7c60
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x801c
movl %eax, %r12d
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0xceae
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xced3
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x2a3e
leaq 0x148(%rsp), %rax
movq %rax, 0x138(%rsp)
movq %r14, %r15
movq %r14, %rdi
leaq 0x144f(%rip), %rsi      # 0xe363
leaq 0x144a(%rip), %rdx      # 0xe365
callq 0x7c60
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x801c
movl %eax, %r15d
movzbl %r13b, %eax
movl 0x44(%rsp), %ecx
addl %eax, %ecx
movzbl %r12b, %eax
subl %eax, %ecx
movl %ecx, 0x44(%rsp)
sete %r12b
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0xcf6d
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xcf8f
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2170
andb %r12b, %r15b
movl 0x4(%rsp), %eax
cmovnel 0xc(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xcfbb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2170
testb %r15b, %r15b
jne 0xd31a
movq 0x30(%rsp), %rsi
incq %rsi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rax
subq %rcx, %rax
sarq $0x5, %rax
movq 0x38(%rsp), %rdx
addq $0x20, %rdx
incl 0xc(%rsp)
movq %rsi, 0x30(%rsp)
cmpq %rsi, %rax
seta %sil
ja 0xcd49
jmp 0xd31f
movq %r14, 0x30(%rsp)
cmpq %r14, %rdx
movq 0x38(%rsp), %rbx
jbe 0xd325
orq $0x8, %rbx
movl $0x0, 0x4(%rsp)
leaq 0x1f8(%rsp), %rbp
leaq 0x1d8(%rsp), %r14
leaq 0x1b8(%rsp), %r13
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq -0x8(%rcx,%rbx), %rsi
movq %rbx, 0x38(%rsp)
movq (%rcx,%rbx), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x2a3e
leaq 0x108(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf8(%rsp), %rdi
callq 0x2a3e
leaq 0x198(%rsp), %rbx
leaq 0x208(%rsp), %rax
movq %rax, 0x1f8(%rsp)
movq %rbp, %r15
movq %rbp, %rdi
leaq 0x12b1(%rip), %rsi      # 0xe360
leaq 0x12ac(%rip), %rdx      # 0xe362
callq 0x7c60
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x801c
movl %eax, %r15d
movq 0x1f8(%rsp), %rdi
leaq 0x208(%rsp), %rax
cmpq %rax, %rdi
je 0xd0f3
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0xd118
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0xe8(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x2a3e
leaq 0x1e8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
movq %r14, %r12
movq %r14, %rdi
leaq 0x1204(%rip), %rsi      # 0xe363
leaq 0x11ff(%rip), %rdx      # 0xe365
callq 0x7c60
leaq 0xd8(%rsp), %rdi
movq %r12, %rsi
callq 0x801c
movl %eax, %r12d
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0xd1a3
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0xd1c8
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x1c8(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x2a3e
leaq 0x1a8(%rsp), %rax
movq %rax, 0x198(%rsp)
movq %rbx, %rdi
leaq 0x115c(%rip), %rsi      # 0xe363
leaq 0x1157(%rip), %rdx      # 0xe365
callq 0x7c60
movq %rbx, %rsi
movq %r13, %rbx
movq %r13, %rdi
callq 0x801c
movl %eax, %r13d
movzbl %r15b, %eax
movl 0x4(%rsp), %ecx
addl %eax, %ecx
movzbl %r12b, %eax
subl %eax, %ecx
movl %ecx, 0x4(%rsp)
sete %r15b
movq 0x198(%rsp), %rdi
leaq 0x1a8(%rsp), %rax
cmpq %rax, %rdi
je 0xd261
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x1b8(%rsp), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0xd286
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x2170
andb %r15b, %r13b
movq %rbx, %r13
je 0xd2c7
movq 0x30(%rsp), %rax
movl %eax, 0x50(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x54(%rsp)
movq 0x48(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xd2bd
movq 0x50(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xd2c7
leaq 0x50(%rsp), %rdx
callq 0xd9e0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xd2e3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x30(%rsp), %rsi
incq %rsi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rax
subq %rcx, %rax
sarq $0x5, %rax
movq 0x38(%rsp), %rbx
addq $0x20, %rbx
movq %rsi, 0x30(%rsp)
cmpq %rsi, %rax
ja 0xd03b
jmp 0xd325
jmp 0xd31f
movb 0xb(%rsp), %sil
testb $0x1, %sil
jne 0xd32d
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
leaq 0x288(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd34e
movq 0x288(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
leaq 0x68(%rsp), %rbp
je 0xd378
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x58(%rsp), %rdi
cmpq %rbp, %rdi
je 0xd38f
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2170
movl 0x4(%rsp), %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd75(%rip), %rdi       # 0xe121
movq %r14, %rsi
xorl %eax, %eax
callq 0x2210
movq %rax, %rbx
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0xd677
movq 0x228(%rsp), %rsi
jmp 0xd66f
jmp 0xd637
jmp 0xd630
movq %rax, %rbx
movq 0x238(%rsp), %rdi
cmpq %r12, %rdi
je 0xd406
movq 0x248(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xd406
movq %rax, %rbx
movq 0x258(%rsp), %rdi
cmpq %r13, %rdi
je 0xd69c
movq 0x268(%rsp), %rsi
jmp 0xd694
movq %rax, %rbx
jmp 0xd69c
movq %rax, %rbx
jmp 0xd4c0
movq %rax, %rbx
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0xd4e6
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xd4e6
movq %rax, %rbx
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0xd50f
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xd50f
jmp 0xd535
movq %rax, %rbx
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0xd4c0
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xd63a
movq 0x88(%rsp), %rsi
jmp 0xd626
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xd63a
movq 0xa8(%rsp), %rsi
jmp 0xd626
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xd63a
movq 0xc8(%rsp), %rsi
jmp 0xd626
movq %rax, %rbx
jmp 0xd656
movq %rax, %rbx
jmp 0xd56a
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
leaq 0x208(%rsp), %rax
cmpq %rax, %rdi
je 0xd56a
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0xd63a
movq 0x108(%rsp), %rsi
jmp 0xd626
movq %rax, %rbx
jmp 0xd5bd
movq %rax, %rbx
movq 0x1d8(%rsp), %rdi
leaq 0x1e8(%rsp), %rax
cmpq %rax, %rdi
je 0xd5bd
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0xd63a
movq 0xe8(%rsp), %rsi
jmp 0xd626
movq %rax, %rbx
jmp 0xd609
movq %rax, %rbx
movq 0x198(%rsp), %rdi
leaq 0x1a8(%rsp), %rax
cmpq %rax, %rdi
je 0xd609
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x1b8(%rsp), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0xd63a
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0xd63a
movq %rax, %rbx
jmp 0xd677
jmp 0xd637
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xd656
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x288(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd677
movq 0x288(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0xd69c
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xd6b8
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2250