// File: olly-larkin[P]mips-parser/src/instructionList.cpp
// Function: I_TYPE(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<OP_TYPE, std::allocator<OP_TYPE>> const&, int, int, bool)
uint32_t I_TYPE(std::vector<std::string>& argVec, const std::vector<OP_TYPE>& opcodes, int op, int pc, bool branch) {
    uint32_t returnNum = (op << 26) & 0xFC000000;
    int32_t immediate = 0;
    std::vector<int> index;
    for(int i = 0; i < opcodes.size(); ++i) {
        if (opcodes[i] == $s || opcodes[i] == $t || opcodes[i] == $d)
            index.push_back(i+1);
    }
    if (!regCheck(argVec, index))
        exitError("Invalid register input \"" + giveStr(argVec) + "\" on instruction number " + std::to_string(pc+1), 5);
    for(int i = 0; i < opcodes.size(); ++i) {
        switch(opcodes[i]) {
            case imm:
                if (branch && labelReturn(argVec[i+1], immediate)) {
                    immediate = immediate - ((pc+1)*4 + 0x10000000);
                    immediate = immediate >> 2;

                } else {
                    if (!validIntStr(argVec[i+1], immediate))
                        exitError("Invalid instruction argument \"" + giveStr(argVec) + "\" on instruction number " + std::to_string(pc+1), 5);
                }
                returnNum = returnNum | (immediate & 0xFFFF);
                break;
            case $t:
                returnNum = returnNum | ((regMap[argVec[i+1]] & 0x1F) << 16);
                break;
            case $s:
                returnNum = returnNum | ((regMap[argVec[i+1]] & 0x1F) << 21);
                break;
            case regMem:
                int offset, reg;
                if (!regMemSeperator(argVec[i+1], offset, reg))
                    exitError("Invalid instruction argument \"" + giveStr(argVec) + "\" on instruction number " + std::to_string(i+1), 5);
                returnNum = returnNum | (offset & 0xFFFF) | ((reg & 0x1F) << 21);
                break;
            default:
                break;
        }
    }
    return returnNum;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movl -0x14(%rbp), %eax
shll $0x1a, %eax
andl $0xfc000000, %eax       # imm = 0xFC000000
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x10ee0
movl $0x0, -0x44(%rbp)
movslq -0x44(%rbp), %rax
movq %rax, -0x300(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10f00
movq %rax, %rcx
movq -0x300(%rbp), %rax
cmpq %rcx, %rax
jae 0xd3b9
movq -0x10(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x10f20
cmpl $0x0, (%rax)
je 0xd37f
movq -0x10(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x10f20
cmpl $0x1, (%rax)
je 0xd37f
movq -0x10(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x10f20
cmpl $0x2, (%rax)
jne 0xd3a9
movl -0x44(%rbp), %eax
incl %eax
movl %eax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x10f40
jmp 0xd396
jmp 0xd3a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdbff
jmp 0xd3ab
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xd326
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xcb20
movb %al, -0x301(%rbp)
jmp 0xd3ce
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0xd55f
jmp 0xd3de
movq -0x8(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0xc070
jmp 0xd3f0
leaq -0xd8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xca30
jmp 0xd405
leaq 0x607d(%rip), %rsi      # 0x13489
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0x10f70
jmp 0xd421
leaq 0x5ddf(%rip), %rdx      # 0x13207
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x5a30
jmp 0xd43d
movl -0x18(%rbp), %esi
incl %esi
leaq -0x110(%rbp), %rdi
callq 0x10fc0
jmp 0xd450
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x7810
jmp 0xd469
leaq -0x78(%rbp), %rdi
movl $0x5, %esi
callq 0xc9e0
jmp 0xd479
leaq -0x78(%rbp), %rdi
callq 0x31a0
leaq -0x110(%rbp), %rdi
callq 0x31a0
leaq -0x98(%rbp), %rdi
callq 0x31a0
leaq -0xb8(%rbp), %rdi
callq 0x31a0
leaq -0xd8(%rbp), %rdi
callq 0x31a0
leaq -0xf0(%rbp), %rdi
callq 0x5c60
jmp 0xd55f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd54e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd542
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd536
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd52a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd51e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x31a0
leaq -0x110(%rbp), %rdi
callq 0x31a0
leaq -0x98(%rbp), %rdi
callq 0x31a0
leaq -0xb8(%rbp), %rdi
callq 0x31a0
leaq -0xd8(%rbp), %rdi
callq 0x31a0
leaq -0xf0(%rbp), %rdi
callq 0x5c60
jmp 0xdbff
movl $0x0, -0x114(%rbp)
movslq -0x114(%rbp), %rax
movq %rax, -0x310(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10f00
movq %rax, %rcx
movq -0x310(%rbp), %rax
cmpq %rcx, %rax
jae 0xdbde
movq -0x10(%rbp), %rdi
movslq -0x114(%rbp), %rsi
callq 0x10f20
movl (%rax), %eax
movq %rax, -0x318(%rbp)
subq $0x5, %rax
ja 0xdbc6
movq -0x318(%rbp), %rax
leaq 0x5db8(%rip), %rcx      # 0x1337c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb -0x19(%rbp), %cl
movb $0x0, -0x139(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x319(%rbp)
je 0xd636
movq -0x8(%rbp), %rdi
movl -0x114(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x7c20
movq %rax, %rsi
leaq -0x138(%rbp), %rdi
callq 0x3120
jmp 0xd609
movb $0x1, -0x139(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x6ee0
movb %al, -0x31a(%rbp)
jmp 0xd628
movb -0x31a(%rbp), %al
movb %al, -0x319(%rbp)
jmp 0xd636
movb -0x319(%rbp), %al
movb %al, -0x31b(%rbp)
testb $0x1, -0x139(%rbp)
jne 0xd64d
jmp 0xd659
leaq -0x138(%rbp), %rdi
callq 0x31a0
movb -0x31b(%rbp), %al
testb $0x1, %al
jne 0xd665
jmp 0xd6b2
movl -0x24(%rbp), %eax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
shll $0x2, %ecx
addl $0x10000000, %ecx       # imm = 0x10000000
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
sarl $0x2, %eax
movl %eax, -0x24(%rbp)
jmp 0xd8c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
testb $0x1, -0x139(%rbp)
jne 0xd6a1
jmp 0xd6ad
leaq -0x138(%rbp), %rdi
callq 0x31a0
jmp 0xdbff
movq -0x8(%rbp), %rdi
movl -0x114(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x7c20
movq %rax, %rsi
leaq -0x160(%rbp), %rdi
callq 0x3120
jmp 0xd6d7
leaq -0x160(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x5fb0
movb %al, -0x31c(%rbp)
jmp 0xd6ef
movb -0x31c(%rbp), %al
xorb $-0x1, %al
movb %al, -0x31d(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x31a0
movb -0x31d(%rbp), %al
testb $0x1, %al
jne 0xd718
jmp 0xd8c5
movq -0x8(%rbp), %rsi
leaq -0x1f8(%rbp), %rdi
callq 0xc070
jmp 0xd72a
leaq -0x1e0(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0xca30
jmp 0xd73f
leaq 0x5d5c(%rip), %rsi      # 0x134a2
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rdx
callq 0x10f70
jmp 0xd75b
leaq 0x5aa5(%rip), %rdx      # 0x13207
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x5a30
jmp 0xd777
movl -0x18(%rbp), %esi
incl %esi
leaq -0x218(%rbp), %rdi
callq 0x10fc0
jmp 0xd78a
leaq -0x180(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x218(%rbp), %rdx
callq 0x7810
jmp 0xd7a6
leaq -0x180(%rbp), %rdi
movl $0x5, %esi
callq 0xc9e0
jmp 0xd7b9
leaq -0x180(%rbp), %rdi
callq 0x31a0
leaq -0x218(%rbp), %rdi
callq 0x31a0
leaq -0x1a0(%rbp), %rdi
callq 0x31a0
leaq -0x1c0(%rbp), %rdi
callq 0x31a0
leaq -0x1e0(%rbp), %rdi
callq 0x31a0
leaq -0x1f8(%rbp), %rdi
callq 0x5c60
jmp 0xd8c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x31a0
jmp 0xdbff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd8b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd8a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd89c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xd884
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x31a0
leaq -0x218(%rbp), %rdi
callq 0x31a0
leaq -0x1a0(%rbp), %rdi
callq 0x31a0
leaq -0x1c0(%rbp), %rdi
callq 0x31a0
leaq -0x1e0(%rbp), %rdi
callq 0x31a0
leaq -0x1f8(%rbp), %rdi
callq 0x5c60
jmp 0xdbff
jmp 0xd8c7
movl -0x20(%rbp), %eax
movl -0x24(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
orl %ecx, %eax
movl %eax, -0x20(%rbp)
jmp 0xdbc8
movl -0x20(%rbp), %eax
movl %eax, -0x32c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x114(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x7c20
movq %rax, %rsi
leaq 0xd9cc(%rip), %rdi      # 0x1b2d0
callq 0x74c0
movq %rax, -0x328(%rbp)
jmp 0xd912
movl -0x32c(%rbp), %eax
movq -0x328(%rbp), %rcx
movl (%rcx), %ecx
andl $0x1f, %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x20(%rbp)
jmp 0xdbc8
movl -0x20(%rbp), %eax
movl %eax, -0x33c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x114(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x7c20
movq %rax, %rsi
leaq 0xd978(%rip), %rdi      # 0x1b2d0
callq 0x74c0
movq %rax, -0x338(%rbp)
jmp 0xd966
movl -0x33c(%rbp), %eax
movq -0x338(%rbp), %rcx
movl (%rcx), %ecx
andl $0x1f, %ecx
shll $0x15, %ecx
orl %ecx, %eax
movl %eax, -0x20(%rbp)
jmp 0xdbc8
movq -0x8(%rbp), %rdi
movl -0x114(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x7c20
movq %rax, %rsi
leaq -0x240(%rbp), %rdi
callq 0x3120
jmp 0xd9aa
leaq -0x240(%rbp), %rdi
leaq -0x21c(%rbp), %rsi
leaq -0x220(%rbp), %rdx
callq 0xdc20
movb %al, -0x33d(%rbp)
jmp 0xd9cc
movb -0x33d(%rbp), %al
xorb $-0x1, %al
movb %al, -0x33e(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x31a0
movb -0x33e(%rbp), %al
testb $0x1, %al
jne 0xd9f5
jmp 0xdba2
movq -0x8(%rbp), %rsi
leaq -0x2d8(%rbp), %rdi
callq 0xc070
jmp 0xda07
leaq -0x2c0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0xca30
jmp 0xda1c
leaq 0x5a7f(%rip), %rsi      # 0x134a2
leaq -0x2a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rdx
callq 0x10f70
jmp 0xda38
leaq 0x57c8(%rip), %rdx      # 0x13207
leaq -0x280(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x5a30
jmp 0xda54
movl -0x114(%rbp), %esi
incl %esi
leaq -0x2f8(%rbp), %rdi
callq 0x10fc0
jmp 0xda6a
leaq -0x260(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x2f8(%rbp), %rdx
callq 0x7810
jmp 0xda86
leaq -0x260(%rbp), %rdi
movl $0x5, %esi
callq 0xc9e0
jmp 0xda99
leaq -0x260(%rbp), %rdi
callq 0x31a0
leaq -0x2f8(%rbp), %rdi
callq 0x31a0
leaq -0x280(%rbp), %rdi
callq 0x31a0
leaq -0x2a0(%rbp), %rdi
callq 0x31a0
leaq -0x2c0(%rbp), %rdi
callq 0x31a0
leaq -0x2d8(%rbp), %rdi
callq 0x5c60
jmp 0xdba2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x31a0
jmp 0xdbff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdb94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdb88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdb7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdb70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdb64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x31a0
leaq -0x2f8(%rbp), %rdi
callq 0x31a0
leaq -0x280(%rbp), %rdi
callq 0x31a0
leaq -0x2a0(%rbp), %rdi
callq 0x31a0
leaq -0x2c0(%rbp), %rdi
callq 0x31a0
leaq -0x2d8(%rbp), %rdi
callq 0x5c60
jmp 0xdbff
movl -0x20(%rbp), %eax
movl -0x21c(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
orl %ecx, %eax
movl -0x220(%rbp), %ecx
andl $0x1f, %ecx
shll $0x15, %ecx
orl %ecx, %eax
movl %eax, -0x20(%rbp)
jmp 0xdbc8
jmp 0xdbc8
jmp 0xdbca
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0xd569
movl -0x20(%rbp), %eax
movl %eax, -0x344(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x110e0
movl -0x344(%rbp), %eax
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x110e0
movq -0x50(%rbp), %rdi
callq 0x3420
nopw %cs:(%rax,%rax)