// File: 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
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x230(%rbp)
addq $0x18, %rdi
movslq -0x14(%rbp), %rsi
callq 0x12e90
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x30e0
leaq -0x40(%rbp), %rdi
callq 0x3330
cmpq $0x0, %rax
ja 0x10ecc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x44(%rbp)
jmp 0x11550
leaq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x30e0
jmp 0x10edb
leaq -0x99(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x3390
movq -0x238(%rbp), %rdx
leaq 0x4403(%rip), %rsi      # 0x152ff
leaq -0x98(%rbp), %rdi
callq 0x8eb0
jmp 0x10f0a
leaq -0x68(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xa430
movb %al, -0x239(%rbp)
jmp 0x10f22
movb -0x239(%rbp), %al
xorb $-0x1, %al
movb %al, -0x23a(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3160
leaq -0x99(%rbp), %rdi
callq 0x3270
leaq -0x68(%rbp), %rdi
callq 0x3160
movb -0x23a(%rbp), %al
testb $0x1, %al
jne 0x10f5d
jmp 0x10fc1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x44(%rbp)
jmp 0x11550
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x11565
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x10fa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3160
leaq -0x99(%rbp), %rdi
callq 0x3270
leaq -0x68(%rbp), %rdi
callq 0x3160
jmp 0x11565
leaq -0xc0(%rbp), %rdi
callq 0x3300
movb $0x0, -0xc1(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x31e0
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x3130
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x9180
testb $0x1, %al
jne 0x11021
jmp 0x110b4
leaq -0xd8(%rbp), %rdi
callq 0x91c0
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x1104e
testb $0x1, -0xc1(%rbp)
je 0x1104e
jmp 0x110b4
testb $0x1, -0xc1(%rbp)
je 0x11082
movq -0xe8(%rbp), %rax
movsbl (%rax), %esi
leaq -0xc0(%rbp), %rdi
callq 0x3170
jmp 0x1106f
jmp 0x11082
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x11542
movq -0xe8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x110a1
testb $0x1, -0xc1(%rbp)
jne 0x110a1
movb $0x1, -0xc1(%rbp)
jmp 0x110a3
leaq -0xd8(%rbp), %rdi
callq 0x91e0
jmp 0x11005
movq -0x20(%rbp), %rdi
callq 0xdf30
movq %rax, -0x248(%rbp)
jmp 0x110c6
leaq -0x128(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x30e0
jmp 0x110db
movq -0x248(%rbp), %rsi
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rdx
callq 0x5200
jmp 0x110f7
leaq -0x128(%rbp), %rdi
callq 0x3160
leaq 0x3fb1(%rip), %rsi      # 0x150bb
leaq -0x108(%rbp), %rdi
callq 0x9240
movb %al, -0x249(%rbp)
jmp 0x1111e
movb -0x249(%rbp), %al
testb $0x1, %al
jne 0x1112a
jmp 0x1116a
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x1151c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3160
jmp 0x11542
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x11536
movl $0x0, -0x12c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x130(%rbp)
movq -0x230(%rbp), %rdi
movslq -0x130(%rbp), %rax
movq %rax, -0x258(%rbp)
addq $0x18, %rdi
callq 0x12e70
movq %rax, %rcx
movq -0x258(%rbp), %rax
cmpq %rcx, %rax
jae 0x1150c
movq -0x230(%rbp), %rdi
addq $0x18, %rdi
movslq -0x130(%rbp), %rsi
callq 0x12e90
movq %rax, -0x260(%rbp)
jmp 0x111ce
movq -0x260(%rbp), %rsi
leaq -0x150(%rbp), %rdi
callq 0x30e0
jmp 0x111e3
leaq -0x170(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x30e0
jmp 0x111f8
leaq -0x191(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x3390
movq -0x268(%rbp), %rdx
leaq 0x40e0(%rip), %rsi      # 0x152f9
leaq -0x190(%rbp), %rdi
callq 0x8eb0
jmp 0x11227
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xa430
movb %al, -0x269(%rbp)
jmp 0x11242
leaq -0x190(%rbp), %rdi
callq 0x3160
leaq -0x191(%rbp), %rdi
callq 0x3270
leaq -0x170(%rbp), %rdi
callq 0x3160
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0x11272
jmp 0x112d7
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x112d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x114fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x112ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x3160
leaq -0x191(%rbp), %rdi
callq 0x3270
leaq -0x170(%rbp), %rdi
callq 0x3160
jmp 0x114fe
leaq -0x1b8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x30e0
jmp 0x112ec
leaq -0x1d9(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x3390
movq -0x278(%rbp), %rdx
leaq 0x3fef(%rip), %rsi      # 0x152fc
leaq -0x1d8(%rbp), %rdi
callq 0x8eb0
jmp 0x1131b
leaq -0x1b8(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0xa430
movb %al, -0x279(%rbp)
jmp 0x11336
leaq -0x1d8(%rbp), %rdi
callq 0x3160
leaq -0x1d9(%rbp), %rdi
callq 0x3270
leaq -0x1b8(%rbp), %rdi
callq 0x3160
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x11366
jmp 0x113ba
movl -0x12c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x113ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1139d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x3160
leaq -0x1d9(%rbp), %rdi
callq 0x3270
leaq -0x1b8(%rbp), %rdi
callq 0x3160
jmp 0x114fe
leaq -0x200(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x30e0
jmp 0x113cf
leaq -0x221(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3390
movq -0x288(%rbp), %rdx
leaq 0x3f0c(%rip), %rsi      # 0x152fc
leaq -0x220(%rbp), %rdi
callq 0x8eb0
jmp 0x113fe
leaq -0x200(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0xa430
movb %al, -0x289(%rbp)
jmp 0x11419
movb -0x289(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x28a(%rbp)
jne 0x1142e
jmp 0x1143e
cmpl $0x0, -0x12c(%rbp)
sete %al
movb %al, -0x28a(%rbp)
movb -0x28a(%rbp), %al
movb %al, -0x28b(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3160
leaq -0x221(%rbp), %rdi
callq 0x3270
leaq -0x200(%rbp), %rdi
callq 0x3160
movb -0x28b(%rbp), %al
testb $0x1, %al
jne 0x1147a
jmp 0x114cc
movl -0x130(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x114d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x114b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3160
leaq -0x221(%rbp), %rdi
callq 0x3270
leaq -0x200(%rbp), %rdi
callq 0x3160
jmp 0x114fe
movl $0x0, -0x44(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x3160
movl -0x44(%rbp), %eax
testl %eax, %eax
jne 0x1151c
jmp 0x114e8
jmp 0x114ea
movl -0x130(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x130(%rbp)
jmp 0x1117d
leaq -0x150(%rbp), %rdi
callq 0x3160
jmp 0x11536
jmp 0x1150e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x44(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3160
leaq -0xc0(%rbp), %rdi
callq 0x3160
jmp 0x11550
leaq -0x108(%rbp), %rdi
callq 0x3160
leaq -0xc0(%rbp), %rdi
callq 0x3160
jmp 0x11565
leaq -0x40(%rbp), %rdi
callq 0x3160
movl -0x4(%rbp), %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x3160
movq -0x70(%rbp), %rdi
callq 0x3380
nopw (%rax,%rax)