// File: Manuel123cool[P]smiley/instruction.cpp
// Function: Instruction::processFunctions()
void Instruction::processFunctions()
{
    struct Funct
    {
        std::string identifier;
        int start;
        int end; 
    };
    std::vector<Funct> functIdent;

    for (int i{ 0 }; i < m_instructions.size(); ++i)  
    {
        std::string code{ m_instructions.at(i) };

        std::string identifier;
        bool start{ false };
        for(const auto &c : code) 
        {
            if (c == ' ' && start)
                break; 

            if (start)
                identifier += c;

            if (c == ' ' && !start)
                start = true;
        }     
 
        bool isInString{ MyRegex::testString(code, ":D ") };    
        if (isInString)
        {
            int jmpTo{ -1 };
            int countBlockStarts{ 0 };
            for (int j{ i }; j < m_instructions.size(); ++j)  
            {
                std::string code{ m_instructions.at(j) };

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

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

                if (MyRegex::testString(code, "<>") && countBlockStarts == 0)
                    jmpTo = j;
            } 
            if (jmpTo == -1)
                std::cerr << "Smt went in functions wrong" << std::endl;

            Jump jump;
            jump.start = i;
            jump.jumpTo = jmpTo;
            m_jumps.push_back(jump); 
            
            Funct func;
            func.start = i;
            func.end = jmpTo;
            func.identifier = identifier;
            functIdent.push_back(func); 
        }     

        bool isInString1{ MyRegex::testString(code, ";) ") };    
        if (isInString1)
        {
            for (const auto &elem : functIdent)
            {
                if (elem.identifier == identifier)
                {
                    Jump jump;
                    jump.start = i;
                    jump.jumpTo = elem.start;
                    m_jumps.push_back(jump); 
                    
                    Jump jump1;
                    jump1.start = elem.end;
                    jump1.jumpTo = i;
                    m_jumps.push_back(jump1); 
 
                }
            }
        } 
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x12050
movl $0x0, -0x24(%rbp)
movq -0x2a8(%rbp), %rdi
movslq -0x24(%rbp), %rax
movq %rax, -0x2b0(%rbp)
addq $0x18, %rdi
callq 0x12e70
movq %rax, %rcx
movq -0x2b0(%rbp), %rax
cmpq %rcx, %rax
jae 0x10d04
movq -0x2a8(%rbp), %rdi
addq $0x18, %rdi
movslq -0x24(%rbp), %rsi
callq 0x12e90
movq %rax, -0x2b8(%rbp)
jmp 0x10475
movq -0x2b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x30e0
jmp 0x10487
leaq -0x78(%rbp), %rdi
callq 0x3300
movb $0x0, -0x79(%rbp)
leaq -0x48(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0x31e0
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
callq 0x3130
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x9180
testb $0x1, %al
jne 0x104e1
jmp 0x10576
leaq -0x90(%rbp), %rdi
callq 0x91c0
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x1051c
testb $0x1, -0x79(%rbp)
je 0x1051c
jmp 0x10576
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x10d16
testb $0x1, -0x79(%rbp)
je 0x1054a
movq -0xa0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x78(%rbp), %rdi
callq 0x3170
jmp 0x10537
jmp 0x1054a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x10cf0
movq -0xa0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x10563
testb $0x1, -0x79(%rbp)
jne 0x10563
movb $0x1, -0x79(%rbp)
jmp 0x10565
leaq -0x90(%rbp), %rdi
callq 0x91e0
jmp 0x104c5
leaq -0xc8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x30e0
jmp 0x10588
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x3390
movq -0x2c0(%rbp), %rdx
leaq 0x4d5e(%rip), %rsi      # 0x15307
leaq -0xe8(%rbp), %rdi
callq 0x8eb0
jmp 0x105b7
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xa430
movb %al, -0x2c1(%rbp)
jmp 0x105d2
leaq -0xe8(%rbp), %rdi
callq 0x3160
leaq -0xe9(%rbp), %rdi
callq 0x3270
leaq -0xc8(%rbp), %rdi
callq 0x3160
movb -0x2c1(%rbp), %al
andb $0x1, %al
movb %al, -0xa1(%rbp)
testb $0x1, -0xa1(%rbp)
je 0x10ae3
movl $0xffffffff, -0xf0(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xf4(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xf8(%rbp)
movq -0x2a8(%rbp), %rdi
movslq -0xf8(%rbp), %rax
movq %rax, -0x2d0(%rbp)
addq $0x18, %rdi
callq 0x12e70
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x109f3
movq -0x2a8(%rbp), %rdi
addq $0x18, %rdi
movslq -0xf8(%rbp), %rsi
callq 0x12e90
movq %rax, -0x2d8(%rbp)
jmp 0x1067f
movq -0x2d8(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x30e0
jmp 0x10694
leaq -0x138(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x30e0
jmp 0x106a9
leaq -0x159(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x3390
movq -0x2e0(%rbp), %rdx
leaq 0x4c2f(%rip), %rsi      # 0x152f9
leaq -0x158(%rbp), %rdi
callq 0x8eb0
jmp 0x106d8
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0xa430
movb %al, -0x2e1(%rbp)
jmp 0x106f3
leaq -0x158(%rbp), %rdi
callq 0x3160
leaq -0x159(%rbp), %rdi
callq 0x3270
leaq -0x138(%rbp), %rdi
callq 0x3160
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x10726
jmp 0x107d1
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x107d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x10760
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x3160
leaq -0xe9(%rbp), %rdi
callq 0x3270
leaq -0xc8(%rbp), %rdi
callq 0x3160
jmp 0x10cf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x109e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x107b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x3160
leaq -0x159(%rbp), %rdi
callq 0x3270
leaq -0x138(%rbp), %rdi
callq 0x3160
jmp 0x109e2
leaq -0x180(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x30e0
jmp 0x107e6
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x3390
movq -0x2f0(%rbp), %rdx
leaq 0x4af5(%rip), %rsi      # 0x152fc
leaq -0x1a0(%rbp), %rdi
callq 0x8eb0
jmp 0x10815
leaq -0x180(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0xa430
movb %al, -0x2f1(%rbp)
jmp 0x10830
leaq -0x1a0(%rbp), %rdi
callq 0x3160
leaq -0x1a1(%rbp), %rdi
callq 0x3270
leaq -0x180(%rbp), %rdi
callq 0x3160
movb -0x2f1(%rbp), %al
testb $0x1, %al
jne 0x10860
jmp 0x108b4
movl -0xf4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x108b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x10897
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x3160
leaq -0x1a1(%rbp), %rdi
callq 0x3270
leaq -0x180(%rbp), %rdi
callq 0x3160
jmp 0x109e2
leaq -0x1c8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x30e0
jmp 0x108c9
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0x3390
movq -0x300(%rbp), %rdx
leaq 0x4a12(%rip), %rsi      # 0x152fc
leaq -0x1e8(%rbp), %rdi
callq 0x8eb0
jmp 0x108f8
leaq -0x1c8(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0xa430
movb %al, -0x301(%rbp)
jmp 0x10913
movb -0x301(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x302(%rbp)
jne 0x10928
jmp 0x10938
cmpl $0x0, -0xf4(%rbp)
sete %al
movb %al, -0x302(%rbp)
movb -0x302(%rbp), %al
movb %al, -0x303(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x3160
leaq -0x1e9(%rbp), %rdi
callq 0x3270
leaq -0x1c8(%rbp), %rdi
callq 0x3160
movb -0x303(%rbp), %al
testb $0x1, %al
jne 0x10974
jmp 0x109c2
movl -0xf8(%rbp), %eax
movl %eax, -0xf0(%rbp)
jmp 0x109c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x109a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x3160
leaq -0x1e9(%rbp), %rdi
callq 0x3270
leaq -0x1c8(%rbp), %rdi
callq 0x3160
jmp 0x109e2
leaq -0x118(%rbp), %rdi
callq 0x3160
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0x1062e
leaq -0x118(%rbp), %rdi
callq 0x3160
jmp 0x10cf0
cmpl $-0x1, -0xf0(%rbp)
jne 0x10a2f
movq 0xc5ed(%rip), %rdi      # 0x1cff0
leaq 0x4901(%rip), %rsi      # 0x1530b
callq 0x3220
movq %rax, -0x310(%rbp)
jmp 0x10a18
movq -0x310(%rbp), %rdi
movq 0xc57a(%rip), %rsi      # 0x1cfa0
callq 0x3250
jmp 0x10a2d
jmp 0x10a2f
leaq -0x1f4(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x12ef0
movq -0x2a8(%rbp), %rdi
movq -0x318(%rbp), %rsi
movl -0x24(%rbp), %eax
movl %eax, -0x1f4(%rbp)
movl -0xf0(%rbp), %eax
movl %eax, -0x1f0(%rbp)
callq 0x12f10
jmp 0x10a6c
leaq -0x220(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x12070
movq -0x320(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, -0x200(%rbp)
movl -0xf0(%rbp), %eax
movl %eax, -0x1fc(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x3030
jmp 0x10aa6
leaq -0x20(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x12090
jmp 0x10ab8
leaq -0x220(%rbp), %rdi
callq 0x12100
jmp 0x10ae3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x12100
jmp 0x10cf0
leaq -0x248(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x30e0
jmp 0x10af5
leaq -0x269(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0x3390
movq -0x328(%rbp), %rdx
leaq 0x4811(%rip), %rsi      # 0x15327
leaq -0x268(%rbp), %rdi
callq 0x8eb0
jmp 0x10b24
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0xa430
movb %al, -0x329(%rbp)
jmp 0x10b3f
leaq -0x268(%rbp), %rdi
callq 0x3160
leaq -0x269(%rbp), %rdi
callq 0x3270
leaq -0x248(%rbp), %rdi
callq 0x3160
movb -0x329(%rbp), %al
andb $0x1, %al
movb %al, -0x221(%rbp)
testb $0x1, -0x221(%rbp)
je 0x10cd0
leaq -0x20(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rdi
callq 0x12120
movq %rax, -0x280(%rbp)
movq -0x278(%rbp), %rdi
callq 0x12150
movq %rax, -0x288(%rbp)
leaq -0x280(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x12180
testb $0x1, %al
jne 0x10bcb
jmp 0x10cce
leaq -0x280(%rbp), %rdi
callq 0x121c0
movq %rax, -0x290(%rbp)
movq -0x290(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x4100
testb $0x1, %al
jne 0x10bf7
jmp 0x10cbb
leaq -0x298(%rbp), %rdi
movq %rdi, -0x338(%rbp)
callq 0x12ef0
movq -0x2a8(%rbp), %rdi
movq -0x338(%rbp), %rsi
movl -0x24(%rbp), %eax
movl %eax, -0x298(%rbp)
movq -0x290(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x294(%rbp)
callq 0x12f10
jmp 0x10c38
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x12ef0
movq -0x2a8(%rbp), %rdi
movq -0x340(%rbp), %rsi
movq -0x290(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x2a0(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x29c(%rbp)
callq 0x12f10
jmp 0x10c79
jmp 0x10cbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x10ca1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x3160
leaq -0x269(%rbp), %rdi
callq 0x3270
leaq -0x248(%rbp), %rdi
callq 0x3160
jmp 0x10cf0
jmp 0x10cbd
leaq -0x280(%rbp), %rdi
callq 0x121e0
jmp 0x10baf
jmp 0x10cd0
leaq -0x78(%rbp), %rdi
callq 0x3160
leaq -0x48(%rbp), %rdi
callq 0x3160
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1042a
leaq -0x78(%rbp), %rdi
callq 0x3160
leaq -0x48(%rbp), %rdi
callq 0x3160
jmp 0x10d16
leaq -0x20(%rbp), %rdi
callq 0x12200
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x20(%rbp), %rdi
callq 0x12200
movq -0x50(%rbp), %rdi
callq 0x3380
nopl (%rax,%rax)