LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/memory.cpp
// Function: dsemu::memory::write(unsigned short, unsigned char)
void write(ushort address, byte value) {
        ram[address] = value;

        if (address == 0xFFFF) {
            cout << "\t - IE EN REGISTER WRITE: " << Byte(value) << endl;
            cpu::handleInterrupt(value, false);
        } else if (address == 0xFF0F) {
            cout << "\t - IE FL REGISTER WRITE: " << Byte(value) << endl;
            
            //cpu::handleInterrupt(value, true);
        }
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
movl %edi, %eax
leaq 0x1a0d1(%rip), %rcx     # 0x285b0
movb %bl, (%rax,%rcx)
cmpl $0xff0f, %edi           # imm = 0xFF0F
je 0xe5cf
cmpl $0xffff, %edi           # imm = 0xFFFF
jne 0xe694
movq 0x9acf(%rip), %r14      # 0x17fd0
leaq 0x4d3d(%rip), %rsi      # 0x13245
movl $0x1a, %edx
movq %r14, %rdi
callq 0x3300
movq (%r14), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r14,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%r14,%rcx)
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0xe1(%r14,%rax)
jne 0xe55b
movq %r15, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x30, 0xe0(%r15)
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r14,%rax)
movzbl %bl, %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movl %ebx, %edi
xorl %esi, %esi
movl $0x1, %edx
popq %rbx
popq %r14
popq %r15
jmp 0xd040
movq 0x99fa(%rip), %r14      # 0x17fd0
leaq 0x4c83(%rip), %rsi      # 0x13260
movl $0x1a, %edx
movq %r14, %rdi
callq 0x3300
movq (%r14), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r14,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%r14,%rcx)
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0xe1(%r14,%rax)
jne 0xe630
movq %r15, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x30, 0xe0(%r15)
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r14,%rax)
movzbl %bl, %esi
movq %r14, %rdi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x31a0
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::regFromBits(unsigned char)
byte *regFromBits(byte reg) {
    byte *pReg = nullptr;

    switch(reg) {
        case 0: pReg = &regBC.hi; break; //cout << "GOT B" << endl; break;
        case 1: pReg = &regBC.lo; break; // cout << "GOT C" << endl; break;
        case 2: pReg = &regDE.hi; break; // cout << "GOT D" << endl; break;
        case 3: pReg = &regDE.lo; break; // cout << "GOT E" << endl; break;
        case 4: pReg = &regHL.hi; break; // cout << "GOT H" << endl; break;
        case 5: pReg = &regHL.lo; break; // cout << "GOT L" << endl; break;
        case 6: pReg = &memory::ram[toShort(regHL.lo, regHL.hi)]; break;
        case 7: pReg = &regAF.hi; break;
            default:
                cout << "INVALID REG " << endl;
                exit(-1);
    }

    return pReg;
}

// Assembly:
cmpl $0x7, %edi
ja 0xea3e
leaq 0x9b05(%rip), %rax      # 0x184f2
movl %edi, %ecx
leaq 0x4886(%rip), %rdx      # 0x1327c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x9aee(%rip), %rax      # 0x184f4
jmp 0xea20
leaq 0x9ae7(%rip), %rax      # 0x184f6
jmp 0xea20
leaq 0x9adc(%rip), %rax      # 0x184f4
retq
leaq 0x9ad0(%rip), %rax      # 0x184f0
incq %rax
retq
leaq 0x9acb(%rip), %rax      # 0x184f6
retq
leaq 0x9ac3(%rip), %rax      # 0x184f6
movzwl (%rax), %eax
addq 0x957b(%rip), %rax      # 0x17fb8
retq
pushq %rax
movq 0x958a(%rip), %rdi      # 0x17fd0
leaq 0x496b(%rip), %rsi      # 0x133b8
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::getPointer(dsemu::cpu::ParamType, bool)
byte *getPointer(ParamType pt, bool hlAsRam = true) {
    switch(pt) {
        case A: return &regAF.hi;
        case B: return &regBC.hi; 
        case C: return &regBC.lo; 
        case D: return &regDE.hi; 
        case E: return &regDE.lo; 
        case H: return &regHL.hi; 
        case L: return &regHL.lo;
        case AF: return &regAF.lo;
        case BC: return &regBC.lo;
        case DE: return &regDE.lo;
        case SP: return &regSP.lo;
        case N: {
            //byte t = memory::ram[(regPC + 1)];
            //unsigned int i = 
            return &memory::ram[(regPC + 1)]; 
        } case HL: {
            return hlAsRam ? &memory::ram[getReg16Value(regHL)] : &regHL.lo;
        }
        default:
            break;
    }

    cout << "ERROR BAD POINTER" << endl;
    exit(-1);

    return nullptr;
}

// Assembly:
cmpl $0xe, %edi
ja 0xeaf2
leaq 0x9a7c(%rip), %rax      # 0x184f0
movl %edi, %ecx
leaq 0x481f(%rip), %rdx      # 0x1329c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x9a65(%rip), %rax      # 0x184f2
retq
leaq 0x9a5f(%rip), %rax      # 0x184f4
retq
leaq 0x9a5f(%rip), %rax      # 0x184fc
retq
leaq 0x9a59(%rip), %rax      # 0x184fe
movzwl (%rax), %eax
leaq 0x19b01(%rip), %rcx     # 0x285b0
addq %rcx, %rax
incq %rax
retq
testb %sil, %sil
je 0xeacd
leaq 0x9a34(%rip), %rax      # 0x184f6
movzwl (%rax), %eax
addq 0x94ec(%rip), %rax      # 0x17fb8
retq
leaq 0x9a22(%rip), %rax      # 0x184f6
retq
leaq 0x9a1a(%rip), %rax      # 0x184f6
jmp 0xeaee
leaq 0x9a0f(%rip), %rax      # 0x184f4
jmp 0xeaee
leaq 0x9a04(%rip), %rax      # 0x184f2
incq %rax
retq
pushq %rax
movq 0x94d6(%rip), %rdi      # 0x17fd0
leaq 0x48c4(%rip), %rsi      # 0x133c5
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleLDH(dsemu::cpu::OpCode const&)
int handleLDH(const OpCode &op) {
    bool srcIsA = op.params[1] == A;

    if (srcIsA) {
        byte *p = getPointer(op.params[0]);
        //cout << "READING B: " << Int64((uint64_t)p) << endl;
        //cout << "B: " << Byte(*p) << endl;
        
        bus::write(*p | 0xFF00, regAF.hi);
    } else {
        byte *p = getPointer(op.params[1]);
        regAF.hi = bus::read(*p | 0xFF00);
    }
    return 0;
}

// Assembly:
pushq %rax
movq %rdi, %rax
movl 0x20(%rdi), %edi
testl %edi, %edi
je 0xeb4c
movl $0x1, %esi
callq 0xea64
movzbl (%rax), %eax
orl $0xff00, %eax           # imm = 0xFF00
movzwl %ax, %edi
callq 0xb94c
leaq 0x99a9(%rip), %rcx      # 0x184f0
movb %al, 0x1(%rcx)
jmp 0xeb74
movl 0x1c(%rax), %edi
movl $0x1, %esi
callq 0xea64
movzbl (%rax), %eax
orl $0xff00, %eax           # imm = 0xFF00
leaq 0x9988(%rip), %rcx      # 0x184f0
movzbl 0x1(%rcx), %esi
movzwl %ax, %edi
callq 0xb9cd
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::getAddrValue(dsemu::cpu::ParamType, short)
ushort getAddrValue(ParamType op, short srcValue) {
    switch(op) {
        case HL: return getReg16Value(regHL);
        case AF: return getReg16Value(regAF);
        case BC: return getReg16Value(regBC);
        case DE: return getReg16Value(regDE);
        case NN: return srcValue;
        case N: return 0xFF00 | srcValue;
        default: 
            cout << "ERROR BAD ADDR VAL: " << endl;
            exit(-1);
            return 0;
    }
}

// Assembly:
addl $-0x7, %edi
cmpl $0x7, %edi
ja 0xebc0
leaq 0x4751(%rip), %rax      # 0x132d8
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x995b(%rip), %rax      # 0x184f2
jmp 0xebba
orl $0xff00, %esi           # imm = 0xFF00
jmp 0xebbd
leaq 0x9948(%rip), %rax      # 0x184f0
jmp 0xebba
leaq 0x9943(%rip), %rax      # 0x184f4
jmp 0xebba
leaq 0x993c(%rip), %rax      # 0x184f6
movzwl (%rax), %esi
movl %esi, %eax
retq
pushq %rax
movq 0x9408(%rip), %rdi      # 0x17fd0
leaq 0x4808(%rip), %rsi      # 0x133d7
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::conditionalJump(unsigned short, dsemu::cpu::OpCode const&, bool&)
int conditionalJump(ushort location, const OpCode &op, bool &didJump) {
    int diff = jumpCycleMap[op.value];

    if (op.mode == ATypeJ) {
        regPC = location;
        didJump = true;
        return 0;
    } else if (op.mode == ATypeJ_C && getFlag(FlagC)) {
        regPC = location;
        didJump = true;
        return diff;
    } else if (op.mode == ATypeJ_NC && !getFlag(FlagC)) {
        regPC = location;
        didJump = true;
        return diff;
    } else if (op.mode == ATypeJ_NZ && !getFlag(FlagZ)) {
        regPC = location;
        didJump = true;
        return diff;
    } else if (op.mode == ATypeJ_Z && getFlag(FlagZ)) {
        regPC = location;
        didJump = true;
        return diff;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movl %edi, %ebp
leaq 0x293a6(%rip), %rdi     # 0x38620
callq 0x10c80
movq %rax, %rcx
movl 0x18(%r14), %edx
xorl %eax, %eax
leal -0x6(%rdx), %esi
cmpl $0x4, %esi
ja 0xf30b
movb (%rcx), %cl
leaq 0x407f(%rip), %rdi      # 0x13318
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
xorl %ecx, %ecx
jmp 0xf2fb
leaq 0x9243(%rip), %rsi      # 0x184f0
testb $0x10, (%rsi)
jne 0xf2fb
cmpl $0x7, %edx
je 0xf2d7
cmpl $0x8, %edx
je 0xf2ef
cmpl $0x9, %edx
jne 0xf30b
leaq 0x9228(%rip), %rsi      # 0x184f0
testb $0x10, (%rsi)
je 0xf2fb
cmpl $0x8, %edx
je 0xf2ef
cmpl $0x7, %edx
jne 0xf30b
leaq 0x9212(%rip), %rsi      # 0x184f0
cmpb $0x0, (%rsi)
jns 0xf2fb
cmpl $0x8, %edx
jne 0xf30b
cmpb $0x0, (%rsi)
js 0xf2fb
jmp 0xf30b
leaq 0x91fa(%rip), %rdx      # 0x184f0
cmpb $0x0, (%rdx)
jns 0xf30b
leaq 0x91fc(%rip), %rax      # 0x184fe
movw %bp, (%rax)
movb $0x1, (%rbx)
movzbl %cl, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleJumpRelative(dsemu::cpu::OpCode const&)
int handleJumpRelative(const OpCode &op) {
    char b = bus::read(regPC + 1);

    if ((byte)b == 0xfe) {
        cout << "INF LOOP? " << endl;
        sleep(5);
    }

    ushort location = regPC + b;
    bool didJump;

    return conditionalJump(location, op, didJump);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x91dd(%rip), %r15      # 0x184fe
movzwl (%r15), %eax
incl %eax
movzwl %ax, %edi
callq 0xb94c
movl %eax, %ebp
cmpb $-0x2, %al
jne 0xf381
movq 0x8c94(%rip), %r14      # 0x17fd0
leaq 0x40f4(%rip), %rsi      # 0x13437
movl $0xa, %edx
movq %r14, %rdi
callq 0x3300
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movl $0x5, %edi
callq 0x3210
movsbl %bpl, %eax
addw (%r15), %ax
movzwl %ax, %edi
leaq 0x7(%rsp), %rdx
movq %rbx, %rsi
callq 0xf267
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleJump(dsemu::cpu::OpCode const&)
int handleJump(const OpCode &op) {
    ushort location = 0;
    bool didJump;

    switch(op.params[0]) {
        case NN:
            location = toShort(bus::read(regPC + 1), bus::read(regPC + 2));
            break;
        case HL:
            location = toShort(regHL.lo, regHL.hi);
            break;
        default:
            cout << "ERRO BAD JUMP" << endl;
            exit(-1);

    }

    return conditionalJump(location - op.length, op, didJump);

/*
    if (op.mode == ATypeJ) {
        regPC = location - op.length;
        return 0;
    } else if (op.mode == ATypeJ_C && getFlag(FlagC)) {
        regPC = location - op.length;
        return 4;
    } else if (op.mode == ATypeJ_NC && !getFlag(FlagC)) {
        regPC = location - op.length;
        return 4;
    } else if (op.mode == ATypeJ_NZ && !getFlag(FlagZ)) {
        regPC = location - op.length;
        return 4;
    } else if (op.mode == ATypeJ_Z && getFlag(FlagZ)) {
        regPC = location - op.length;
        return 4;
    }
    return 0;
*/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x1c(%rdi), %eax
cmpl $0x9, %eax
je 0xf3e9
cmpl $0xd, %eax
jne 0xf423
leaq 0x913c(%rip), %r14      # 0x184fe
movzwl (%r14), %edi
incl %edi
movl $0xffff, %r15d          # imm = 0xFFFF
andl %r15d, %edi
callq 0xb94c
movl %eax, %ebp
movzwl (%r14), %edi
addl $0x2, %edi
andl %r15d, %edi
callq 0xb94c
jmp 0xf3f6
leaq 0x9106(%rip), %rax      # 0x184f6
movb (%rax), %bpl
movb 0x1(%rax), %al
movzbl %al, %eax
shll $0x8, %eax
movzbl %bpl, %ecx
orl %eax, %ecx
movzbl 0x14(%rbx), %eax
subl %eax, %ecx
movzwl %cx, %edi
leaq 0x7(%rsp), %rdx
movq %rbx, %rsi
callq 0xf267
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x8ba6(%rip), %rdi      # 0x17fd0
leaq 0x4011(%rip), %rsi      # 0x13442
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handlePOP(dsemu::cpu::OpCode const&)
int handlePOP(const OpCode &op) {
    ushort *p = (ushort *)getPointer(op.params[0], false);
    
    ushort s = spop();
    cout << "POPPED VALUE: " << Short(s) << endl;

    if (p == (ushort *)&regAF) {
        *p = s & 0xFFF0;
    } else {
        *p = s;
    }

    if (op.value == 0xF1) {
        //sleep(2);
    }
    
    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl 0x1c(%rdi), %edi
xorl %esi, %esi
callq 0xea64
movq %rax, %r14
callq 0xc5a3
movl %eax, %ebx
movq 0x8ace(%rip), %r15      # 0x17fd0
leaq 0x3f47(%rip), %rsi      # 0x13450
movl $0xe, %edx
movq %r15, %rdi
callq 0x3300
movq (%r15), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r15,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%r15,%rcx)
movq -0x18(%rax), %rax
leaq (%r15,%rax), %r12
cmpb $0x0, 0xe1(%r15,%rax)
jne 0xf55e
movq %r12, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r12)
movb $0x1, 0xe1(%r12)
movb $0x30, 0xe0(%r12)
movq (%r15), %rax
movq -0x18(%rax), %rax
movq $0x4, 0x10(%r15,%rax)
movzwl %bx, %esi
movq %r15, %rdi
callq 0x3190
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
cmpq 0x8a03(%rip), %r14      # 0x17fc8
je 0xf5cd
movw %bx, (%r14)
jmp 0xf5dd
andl $0xfff0, %ebx           # imm = 0xFFF0
leaq 0x8f16(%rip), %rax      # 0x184f0
movw %bx, (%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handlePUSH(dsemu::cpu::OpCode const&)
int handlePUSH(const OpCode &op) {
    ushort *p = (ushort *)getPointer(op.params[0], false);

    push(*p);

    cout << "PUSHED: " << Short(*p) << endl;

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl 0x1c(%rdi), %edi
xorl %esi, %esi
callq 0xea64
movq %rax, %r14
movzwl (%rax), %edi
callq 0xc4e4
movq 0x89c4(%rip), %rbx      # 0x17fd0
leaq 0x3e4c(%rip), %rsi      # 0x1345f
movl $0x8, %edx
movq %rbx, %rdi
callq 0x3300
movzwl (%r14), %r14d
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r15
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xf667
movq %r15, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x30, 0xe0(%r15)
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0x4, 0x10(%rbx,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3190
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::setFlags(unsigned char, unsigned char, bool, bool)
void setFlags(byte first, byte second, bool add, bool withCarry) {
    if (add) {
        unsigned int a = first + second + (withCarry ? getFlag(FlagC) : 0);
        byte cf = getFlag(FlagC);
        //setFlag(FlagZ, (a & 0xFF) == 0);
        setFlag(FlagZ, !(a & 0xFF));
        //cout << "AF: 2: " << Byte(regAF.lo) << endl;
        //setFlag(FlagC, a > 0xFF);
        setFlag(FlagC, a >= 0x100);
        //cout << "AF: 3: " << Byte(regAF.lo) << endl;
        setFlag(FlagN, false);
        //cout << "AF: 4: " << Byte(regAF.lo) << endl;
        setFlag(FlagH, ((first&0xF) + (second&0xF) + (withCarry ? cf : 0)) >= 0x10);
        //cout << "AF: 5: " << Byte(regAF.lo) << " - " << Short(a) << endl;
        //setFlag(FlagH, (first & 0xF) + (second & 0xF) + (withCarry && getFlag(FlagC)) > 0xF);
    } else {
        int a = first - second - (withCarry && getFlag(FlagC));
        byte cf = getFlag(FlagC);
        setFlag(FlagZ, (a & 0xFF) == 0);
        setFlag(FlagC, a < 0);
        setFlag(FlagN, true);
        setFlag(FlagH, (first & 0xF) - (second & 0xF) - (withCarry ? cf : 0) < 0);
    }

    return;
}

// Assembly:
leaq 0x8748(%rip), %rax      # 0x184f0
movzbl (%rax), %r8d
testl %edx, %edx
je 0xfe19
movl %r8d, %edx
shrb $0x4, %dl
movl %r8d, %r10d
shrl $0x4, %r10d
movzbl %cl, %r11d
andl %r10d, %r11d
addl %esi, %r11d
addl %edi, %r11d
testb %r11b, %r11b
sete %r9b
andb $0x2f, %r8b
shlb $0x7, %r9b
cmpl $0x100, %r11d           # imm = 0x100
setae %r10b
shlb $0x4, %r10b
orb %r8b, %r10b
orb %r9b, %r10b
movb %r10b, (%rax)
andl $0xf, %edi
andl $0xf, %esi
addl %edi, %esi
andb %cl, %dl
movzbl %dl, %ecx
addl %esi, %ecx
movl %r10d, %edx
andb $-0x61, %dl
orb $0x20, %r10b
cmpl $0x10, %ecx
movzbl %r10b, %esi
movzbl %dl, %ecx
cmovael %esi, %ecx
jmp 0xfe87
movl %r8d, %edx
shrb $0x4, %dl
movl %edi, %r10d
subl %esi, %r10d
leal (,%r8,8), %r9d
sarb $0x7, %r9b
movsbl %r9b, %r11d
xorl %r9d, %r9d
testb %cl, %cl
cmovnel %r11d, %r9d
addl %r10d, %r9d
testb %r9b, %r9b
sete %r10b
andb $0x2f, %r8b
shlb $0x7, %r10b
orb %r8b, %r10b
shrl $0x1b, %r9d
andb $0x10, %r9b
orb %r10b, %r9b
leal 0x40(%r9), %r8d
movb %r8b, (%rax)
andl $0xf, %edi
andl $0xf, %esi
subl %esi, %edi
andb %cl, %dl
movzbl %dl, %ecx
andb $-0x21, %r8b
orb $0x60, %r9b
cmpl %ecx, %edi
movzbl %r9b, %edx
movzbl %r8b, %ecx
cmovsl %edx, %ecx
movb %cl, (%rax)
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleADC(dsemu::cpu::OpCode const&)
int handleADC(const OpCode &op) {
    byte *val = getPointer(op.params[1]);

    if (op.value == 0xCE) {
        byte t = bus::read(regPC + 1);
        unsigned int i = regAF.hi + t + getFlag(FlagC) >= 0x100;
        //setFlags(regAF.hi, t, true, true);
        setFlag(FlagN, false);
        setFlag(FlagH, ((regAF.hi&0xF) + (t&0xF) + getFlag(FlagC)) >= 0x10);
        regAF.hi = regAF.hi + t + getFlag(FlagC);
        setFlag(FlagC, i);
        setFlag(FlagZ, !regAF.hi);

        return  0;
    }

    unsigned int a = regAF.hi + *val + getFlag(FlagC);

    setFlags(regAF.hi, *val, true, true);

    regAF.hi = a & 0xFF;
    return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x20(%rdi), %edi
movl $0x1, %esi
callq 0xea64
cmpb $-0x32, (%rbx)
jne 0xff6e
leaq 0x8628(%rip), %rax      # 0x184fe
movzwl (%rax), %eax
incl %eax
movzwl %ax, %edi
callq 0xb94c
leaq 0x8606(%rip), %rcx      # 0x184f0
movzbl 0x1(%rcx), %edx
movzbl %al, %eax
movzbl (%rcx), %edi
movl %edi, %r8d
shrl $0x4, %r8d
andl $0x1, %r8d
leal (%rdx,%r8), %esi
addl %eax, %esi
movl %edx, %r9d
andl $0xf, %r9d
movl %eax, %r10d
andl $0xf, %r10d
addl %r8d, %r9d
addl %r10d, %r9d
andb $-0x61, %dil
leal 0x20(%rdi), %r8d
cmpl $0x10, %r9d
movzbl %dil, %edi
movzbl %r8b, %r8d
cmovbl %edi, %r8d
btl $0x4, %r8d
adcb %dl, %al
movl %r8d, %edx
andb $-0x51, %dl
orb $0x10, %r8b
cmpl $0x100, %esi            # imm = 0x100
movb %al, 0x1(%rcx)
movzbl %r8b, %esi
movzbl %dl, %edx
cmovael %esi, %edx
movl %edx, %esi
andb $0x3f, %sil
orb $-0x80, %dl
testb %al, %al
movzbl %dl, %eax
movzbl %sil, %edx
cmovel %eax, %edx
movb %dl, (%rcx)
jmp 0xff9b
leaq 0x857b(%rip), %rbx      # 0x184f0
movzbl 0x1(%rbx), %edi
movzbl (%rax), %esi
movzbl (%rbx), %eax
btl $0x4, %eax
movl %esi, %ebp
adcb %dil, %bpl
movl $0x1, %edx
movl $0x1, %ecx
callq 0xfda1
movb %bpl, 0x1(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleADD(dsemu::cpu::OpCode const&)
int handleADD(const OpCode &op) {
    if (op.params[0] == A) {
        byte *p = getPointer(op.params[1]);
        ushort a = regAF.hi + *p;
        setFlags(regAF.hi, *p, true, false);
        regAF.hi = a & 0x00FF;

    } else if (op.params[0] == SP) {
        char e = bus::read(regPC + 1);
        setFlags(getReg16Value(regSP), e, true, false);
        setReg16Value(regSP, getReg16Value(regSP) + e);
        setFlag(FlagZ, false);
    } else {
        ushort *p = (ushort *)getPointer(op.params[1], false);
        ushort *pHL = (ushort *)&regHL;
        int n = *pHL + *p;

        setFlag(FlagC, n >= 0x10000);
        setFlag(FlagN, false);
        setFlag(FlagH, (n & 0xFFF) < (*pHL & 0xFFF));
        *pHL = n & 0xFFFF;
    }

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl 0x1c(%rdi), %eax
cmpl $0xa, %eax
je 0xfff0
testl %eax, %eax
jne 0x10033
movl 0x20(%rdi), %edi
movl $0x1, %esi
callq 0xea64
leaq 0x8527(%rip), %r15      # 0x184f0
movzbl 0x1(%r15), %ebx
movzbl (%rax), %r14d
movl %ebx, %edi
movl %r14d, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0xfda1
leal (%r14,%rbx), %eax
movb %al, 0x1(%r15)
jmp 0x1008f
leaq 0x8507(%rip), %rax      # 0x184fe
movzwl (%rax), %eax
incl %eax
movzwl %ax, %edi
callq 0xb94c
leaq 0x84f1(%rip), %r14      # 0x184fc
movzbl (%r14), %edi
movzbl %al, %ebx
movl %ebx, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0xfda1
movsbl %bl, %eax
addw %ax, (%r14)
leaq 0x84c2(%rip), %rax      # 0x184f0
andb $0x7f, (%rax)
jmp 0x1008f
movl 0x20(%rdi), %edi
xorl %esi, %esi
callq 0xea64
leaq 0x84b2(%rip), %rsi      # 0x184f6
movzwl (%rsi), %ecx
movzwl (%rax), %edi
addl %ecx, %edi
cmpl $0x10000, %edi          # imm = 0x10000
setae %dl
leaq 0x8494(%rip), %rax      # 0x184f0
movb (%rax), %r8b
andb $-0x51, %r8b
shlb $0x4, %dl
orb %r8b, %dl
movl $0xfff, %r8d            # imm = 0xFFF
movw %di, (%rsi)
andl %r8d, %edi
andl %r8d, %ecx
movl %edx, %esi
andb $-0x61, %sil
orb $0x20, %dl
cmpl %ecx, %edi
movzbl %dl, %ecx
movzbl %sil, %edx
cmovbl %ecx, %edx
movb %dl, (%rax)
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleSUB(dsemu::cpu::OpCode const&)
int handleSUB(const OpCode &op) {
    byte *val = getPointer(op.params[0]);

    short a = regAF.hi - *val;
    setFlags(regAF.hi, *val, false, false);

    regAF.hi = a & 0x00FF;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl 0x1c(%rdi), %edi
movl $0x1, %esi
callq 0xea64
leaq 0x8441(%rip), %r14      # 0x184f0
movzbl 0x1(%r14), %ebx
movzbl (%rax), %ebp
movl %ebx, %edi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xfda1
subb %bpl, %bl
movb %bl, 0x1(%r14)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleSBC(dsemu::cpu::OpCode const&)
int handleSBC(const OpCode &op) {
    byte *val = getPointer(op.params[0]);

    short a = regAF.hi - *val - getFlag(FlagC);
    setFlags(regAF.hi, *val, false, true);

    regAF.hi = a & 0x00FF;
    return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl 0x1c(%rdi), %edi
movl $0x1, %esi
callq 0xea64
leaq 0x8407(%rip), %rbx      # 0x184f0
movzbl 0x1(%rbx), %edi
movzbl (%rax), %esi
movl %edi, %eax
subb %sil, %al
movb (%rbx), %bpl
shlb $0x3, %bpl
sarb $0x7, %bpl
addb %al, %bpl
xorl %edx, %edx
movl $0x1, %ecx
callq 0xfda1
movb %bpl, 0x1(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleAND(dsemu::cpu::OpCode const&)
int handleAND(const OpCode &op) {
    byte *val = getPointer(op.params[0]);

    regAF.hi &= *val;
    
    setFlag(FlagZ, regAF.hi == 0);
    setFlag(FlagN, false);
    setFlag(FlagH, true);
    setFlag(FlagC, 0);
    return 0;
}

// Assembly:
pushq %rax
movl 0x1c(%rdi), %edi
movl $0x1, %esi
callq 0xea64
movb (%rax), %al
leaq 0x83bd(%rip), %rcx      # 0x184f0
andb %al, 0x1(%rcx)
setne %al
movb (%rcx), %dl
andb $0xf, %dl
shlb $0x7, %al
orb %dl, %al
addb $-0x60, %al
movb %al, (%rcx)
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleOR(dsemu::cpu::OpCode const&)
int handleOR(const OpCode &op) {
    byte *val = getPointer(op.params[0]);

    regAF.hi |= *val;
    
    setFlag(FlagZ, regAF.hi == 0);
    setFlag(FlagN, false);
    setFlag(FlagH, false);
    setFlag(FlagC, 0);
    return 0;
}

// Assembly:
pushq %rax
movl 0x1c(%rdi), %edi
movl $0x1, %esi
callq 0xea64
movb (%rax), %al
leaq 0x838e(%rip), %rcx      # 0x184f0
orb %al, 0x1(%rcx)
sete %al
movb (%rcx), %dl
andb $0xf, %dl
shlb $0x7, %al
orb %dl, %al
movb %al, (%rcx)
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleXOR(dsemu::cpu::OpCode const&)
int handleXOR(const OpCode &op) {
    byte *val = getPointer(op.params[0]);

    //cout << "XORING VAL: " << Byte(*val) << endl;

    regAF.hi ^= *val;
    
    setFlag(FlagZ, regAF.hi == 0);
    setFlag(FlagN, false);
    setFlag(FlagH, false);
    setFlag(FlagC, 0);
    return 0;
}

// Assembly:
pushq %rax
movl 0x1c(%rdi), %edi
movl $0x1, %esi
callq 0xea64
movb (%rax), %al
leaq 0x8361(%rip), %rcx      # 0x184f0
movb (%rcx), %dl
movb 0x1(%rcx), %sil
movl %esi, %edi
xorb %al, %dil
movb %dil, 0x1(%rcx)
cmpb %al, %sil
sete %al
andb $0xf, %dl
shlb $0x7, %al
orb %dl, %al
movb %al, (%rcx)
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::getVal(dsemu::cpu::ParamType)
byte getVal(ParamType pt) {
    switch(pt) {
        case A: return regAF.hi; 
        case B: return regBC.hi; 
        case C: return regBC.lo; 
        case D: return regDE.hi; 
        case E: return regDE.lo; 
        case H: return regHL.hi; 
        case L: return regHL.lo; 
        case N: return bus::read(regPC + 1); 
        case HL: return bus::read(toShort(regHL.lo, regHL.hi)); break;
        default:
            cout << "BAD LDD" << endl;
            exit(-1);
            return 0;
    }
}

// Assembly:
cmpl $0xc, %edi
ja 0x1022e
movl %edi, %eax
leaq 0x316c(%rip), %rcx      # 0x1332c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8320(%rip), %rax      # 0x184f0
jmp 0x10220
leaq 0x8325(%rip), %rax      # 0x184fe
movzwl (%rax), %eax
incl %eax
movzwl %ax, %edi
jmp 0xb94c
leaq 0x8307(%rip), %rax      # 0x184f4
jmp 0x1022b
leaq 0x8300(%rip), %rax      # 0x184f6
jmp 0x10220
leaq 0x82f3(%rip), %rax      # 0x184f2
jmp 0x1022b
leaq 0x82ee(%rip), %rax      # 0x184f6
movzwl (%rax), %edi
jmp 0xb94c
leaq 0x82dd(%rip), %rax      # 0x184f4
jmp 0x10220
leaq 0x82d2(%rip), %rax      # 0x184f2
movb 0x1(%rax), %al
retq
leaq 0x82cb(%rip), %rax      # 0x184f6
movb (%rax), %al
retq
pushq %rax
movq 0x7d9a(%rip), %rdi      # 0x17fd0
leaq 0x3270(%rip), %rsi      # 0x134ad
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleLDD(dsemu::cpu::OpCode const&)
int handleLDD(const OpCode &op) {
    handleLD(op);
    ushort *p = (ushort *)&regHL;
    (*p)--;
    return 0;
}

// Assembly:
pushq %rax
callq 0xebe6
leaq 0x8295(%rip), %rax      # 0x184f6
decw (%rax)
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleLDI(dsemu::cpu::OpCode const&)
int handleLDI(const OpCode &op) {
    handleLD(op);
    ushort *p = (ushort *)&regHL;
    (*p)++;
    return 0;
}

// Assembly:
pushq %rax
callq 0xebe6
leaq 0x8281(%rip), %rax      # 0x184f6
incw (%rax)
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleINC(dsemu::cpu::OpCode const&)
int handleINC(const OpCode &op) {
    ushort val = 0;
    ushort prev = 0;

    switch(op.params[0]) {
        case A: prev = regAF.hi++; val = regAF.hi; break;
        case B: prev = regBC.hi++; val = regBC.hi; break;
        case C: prev = regBC.lo++; val = regBC.lo; break;
        case D: prev = regDE.hi++; val = regDE.hi; break;
        case E: prev = regDE.lo++; val = regDE.lo; break;
        case H: prev = regHL.hi++; val = regHL.hi; break;
        case L: prev = regHL.lo++; val = regHL.lo; break;
        case BC: prev = (*getReg16Pointer(regBC))++; val = (getReg16Value(regBC));  return 0;
        case DE: prev = (*getReg16Pointer(regDE))++; val = (getReg16Value(regDE)); return 0;
        case SP: prev = (*getReg16Pointer(regSP))++; val = (getReg16Value(regSP)); return 0;
        case HL: {
            if (op.mode == ATypeA) {
                byte b = bus::read((getReg16Value(regHL)));
                prev = b++;
                bus::write((getReg16Value(regHL)), b);
                val = b;

            } else {
                prev = (*getReg16Pointer(regHL))++; 
                val = (getReg16Value(regHL)); 
                return 0;
            }
        } break;
        default:
            cout << "INVALID INC FLAG" << endl;
            exit(-1);
            return 0;
    }

    setFlag(FlagZ, val == 0);
    setFlag(FlagN, 0);
    setFlag(FlagH, (prev & 0xF) == 0xF);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl 0x1c(%rdi), %eax
cmpq $0xa, %rax
ja 0x1037a
leaq 0x30cc(%rip), %rcx      # 0x13360
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x824c(%rip), %rax      # 0x184f0
jmp 0x1030d
leaq 0x8247(%rip), %rax      # 0x184f4
jmp 0x10320
cmpl $0xc, 0x18(%rdi)
leaq 0x823c(%rip), %r14      # 0x184f6
movzwl (%r14), %eax
jne 0x10372
movzwl %ax, %edi
callq 0xb94c
movl %eax, %ebx
movl %eax, %ebp
incb %bpl
movzwl (%r14), %edi
movzbl %bpl, %esi
callq 0xb9cd
jmp 0x10328
leaq 0x8209(%rip), %rax      # 0x184f2
jmp 0x10320
leaq 0x8202(%rip), %rax      # 0x184f4
jmp 0x1030d
leaq 0x81f7(%rip), %rax      # 0x184f2
jmp 0x10368
leaq 0x81ee(%rip), %rax      # 0x184f2
jmp 0x1030d
leaq 0x81e9(%rip), %rax      # 0x184f6
movb 0x1(%rax), %bl
leal 0x1(%rbx), %ebp
movb %bpl, 0x1(%rax)
jmp 0x10328
leaq 0x81d6(%rip), %rax      # 0x184f6
movb (%rax), %bl
leal 0x1(%rbx), %ebp
movb %bpl, (%rax)
testb %bpl, %bpl
sete %al
leaq 0x81bb(%rip), %rcx      # 0x184f0
movb (%rcx), %dl
andb $0x3f, %dl
shlb $0x7, %al
orb %dl, %al
notb %bl
movl %eax, %edx
andb $-0x61, %dl
orb $0x20, %al
testb $0xf, %bl
movzbl %al, %eax
movzbl %dl, %edx
cmovel %eax, %edx
movb %dl, (%rcx)
jmp 0x1036b
leaq 0x819d(%rip), %rax      # 0x184fc
jmp 0x10368
leaq 0x818c(%rip), %rax      # 0x184f4
incw (%rax)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
incl %eax
movw %ax, (%r14)
jmp 0x1036b
movq 0x7c4f(%rip), %rdi      # 0x17fd0
leaq 0x312d(%rip), %rsi      # 0x134b5
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleDEC(dsemu::cpu::OpCode const&)
int handleDEC(const OpCode &op) {
    ushort val = 0;

    switch(op.params[0]) {
        case A: regAF.hi--; val = regAF.hi; break;
        case B: regBC.hi--; val = regBC.hi; break;
        case C: regBC.lo--; val = regBC.lo; break;
        case D: regDE.hi--; val = regDE.hi; break;
        case E: regDE.lo--; val = regDE.lo; break;
        case H: regHL.hi--; val = regHL.hi; break;
        case L: regHL.lo--; val = regHL.lo; break;
        case BC: (*getReg16Pointer(regBC))--; val = (getReg16Value(regBC)); return 0;
        case DE: (*getReg16Pointer(regDE))--; val = (getReg16Value(regDE)); return 0;
        case SP: (*getReg16Pointer(regSP))--; val = (getReg16Value(regSP)); return 0;
        case HL: {
            if (op.mode == ATypeA) {
                byte b = bus::read((getReg16Value(regHL)));
                b--;
                bus::write((getReg16Value(regHL)), b);
                val = b;
            } else {
                (*getReg16Pointer(regHL))--; 
                val = (getReg16Value(regHL)); 
                return 0;
            }
        } break;
        default:
            cout << "INVALID DEC FLAG" << endl;
            exit(-1);
            return 0;
    }

    setFlag(FlagZ, val == 0);
    setFlag(FlagN, 1);
    setFlag(FlagH, (val & 0xF) == 0x0F);
    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl 0x1c(%rdi), %eax
cmpq $0xa, %rax
ja 0x1049a
leaq 0x2fd5(%rip), %rcx      # 0x1338c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8129(%rip), %rax      # 0x184f0
jmp 0x1042c
leaq 0x8124(%rip), %rax      # 0x184f4
jmp 0x1043d
cmpl $0xc, 0x18(%rdi)
leaq 0x8119(%rip), %r14      # 0x184f6
movzwl (%r14), %eax
jne 0x10492
movzwl %ax, %edi
callq 0xb94c
movl %eax, %ebx
decb %bl
movzwl (%r14), %edi
movzbl %bl, %esi
callq 0xb9cd
jmp 0x10443
leaq 0x80ea(%rip), %rax      # 0x184f2
jmp 0x1043d
leaq 0x80e3(%rip), %rax      # 0x184f4
jmp 0x1042c
leaq 0x80d8(%rip), %rax      # 0x184f2
jmp 0x10485
leaq 0x80cf(%rip), %rax      # 0x184f2
jmp 0x1042c
leaq 0x80ca(%rip), %rax      # 0x184f6
movb 0x1(%rax), %bl
decb %bl
movb %bl, 0x1(%rax)
jmp 0x10443
leaq 0x80b9(%rip), %rax      # 0x184f6
movb (%rax), %bl
decb %bl
movb %bl, (%rax)
testb %bl, %bl
sete %al
leaq 0x80a1(%rip), %rcx      # 0x184f0
movb (%rcx), %dl
andb $0x3f, %dl
shlb $0x7, %al
orb %dl, %al
notb %bl
movl %eax, %edx
andb $-0x61, %dl
orb $0x40, %dl
orb $0x60, %al
testb $0xf, %bl
movzbl %al, %eax
movzbl %dl, %edx
cmovel %eax, %edx
movb %dl, (%rcx)
jmp 0x10488
leaq 0x8080(%rip), %rax      # 0x184fc
jmp 0x10485
leaq 0x806f(%rip), %rax      # 0x184f4
decw (%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
decl %eax
movw %ax, (%r14)
jmp 0x10488
movq 0x7b2f(%rip), %rdi      # 0x17fd0
leaq 0x301e(%rip), %rsi      # 0x134c6
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleRLCA(dsemu::cpu::OpCode const&)
int handleRLCA(const OpCode &op) {
    byte b = !!(regAF.hi & 0x80);
    regAF.hi <<= 1;
    regAF.hi |= b;
    
    setFlag(FlagC, b);
    setFlag(FlagZ, false);
    setFlag(FlagH, false);
    setFlag(FlagN, false);

    return 0;
}

// Assembly:
leaq 0x7ff8(%rip), %rax      # 0x184f0
movb 0x1(%rax), %cl
movl %ecx, %edx
rolb %dl
movb (%rax), %sil
movb %dl, 0x1(%rax)
andb $0xf, %sil
shrb $0x3, %cl
andb $0x10, %cl
orb %sil, %cl
movb %cl, (%rax)
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/common.h
// Function: dsemu::cpu::handleCCF(dsemu::cpu::OpCode const&)
inline void setBit(byte &b, byte n, bool on) {
    if (on) {
        b |= (1 << n);
    } else {
        b &= ~(1 << n);
    }
}

// Assembly:
leaq 0x7f42(%rip), %rax      # 0x184f0
movb (%rax), %cl
movl %ecx, %edx
andb $-0x71, %dl
leal 0x10(%rdx), %esi
testb $0x10, %cl
movzbl %dl, %ecx
movzbl %sil, %edx
cmovnel %ecx, %edx
movb %dl, (%rax)
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleRST(dsemu::cpu::OpCode const&)
int handleRST(const OpCode &op) {
    push((ushort)(regPC + 1));

    switch(op.params[0]) {
        case x00: regPC = 0x00; break;
        case x08: regPC = 0x08; break;
        case x10: regPC = 0x10; break;
        case x18: regPC = 0x18; break;
        case x20: regPC = 0x20; break;
        case x28: regPC = 0x28; break;
        case x30: regPC = 0x30; break;
        case x38: regPC = 0x38; break;
        default: {
            cout << "UNKNOWN RST" << endl;
            exit(-1);
        }
    }

    regPC -= 1;
    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x7f26(%rip), %r14      # 0x184fe
movzwl (%r14), %eax
incl %eax
movzwl %ax, %edi
callq 0xc4e4
movl 0x1c(%rbx), %eax
addl $-0xf, %eax
cmpl $0x8, %eax
jae 0x1060e
movl %eax, %eax
leaq 0x2efc(%rip), %rcx      # 0x134f6
movzwl (%rcx,%rax,2), %eax
decl %eax
movw %ax, (%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x79bb(%rip), %rdi      # 0x17fd0
leaq 0x2ebb(%rip), %rsi      # 0x134d7
callq 0x3290
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handle_op(dsemu::cpu::OpCode&)
int handle_op(OpCode &opCode) {
    std::map<Op, HANDLER>::iterator it = handlerMap.find(opCode.op);

    if (it == handlerMap.end()) {
        cout << "UNKNOWN OP CODE: " << Byte(opCode.value) << endl;
        exit(-1);
    }

    int ret = it->second(opCode);

    if (opCode.op != EI && eiCalled) {
        eiCalled = false;
        interruptsEnabled = true;
    }

    return ret;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x27ac4(%rip), %rdx     # 0x385c8
leaq 0x27ab5(%rip), %rax     # 0x385c0
movq %rax, %rcx
testq %rdx, %rdx
je 0x10b34
movl 0x10(%rbx), %esi
leaq 0x27aa3(%rip), %rcx     # 0x385c0
xorl %edi, %edi
cmpl %esi, 0x20(%rdx)
setl %dil
cmovgeq %rdx, %rcx
movq 0x10(%rdx,%rdi,8), %rdx
testq %rdx, %rdx
jne 0x10b1d
movq %rax, %rdx
cmpq %rax, %rcx
je 0x10b4d
movl 0x10(%rbx), %edx
cmpl 0x20(%rcx), %edx
leaq 0x27a77(%rip), %rdx     # 0x385c0
cmovgeq %rcx, %rdx
cmpq %rax, %rdx
je 0x10b77
movq %rbx, %rdi
callq *0x28(%rdx)
cmpl $0x1d, 0x10(%rbx)
je 0x10b75
cmpb $0x1, 0x27ab3(%rip)     # 0x38618
jne 0x10b75
movb $0x0, 0x27aaa(%rip)     # 0x38618
movb $0x1, 0x27aa4(%rip)     # 0x38619
popq %rbx
retq
movq 0x7452(%rip), %rdi      # 0x17fd0
leaq 0x295e(%rip), %rsi      # 0x134e3
callq 0x3290
movl (%rbx), %esi
movq %rax, %rdi
callq 0x10ce4
movq %rax, %rdi
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/ppu.cpp
// Function: dsemu::ppu::init()
void init() {
    currentFrame = 0;
    currentLine = 0;
    scrollInfo.x = 0;
    scrollInfo.y = 0;
    memset(oamRAM, 0, sizeof(oamRAM));

    videoBuffer = new unsigned long[256 * 256];
    memset(videoBuffer, 0, 256 * 256 * sizeof(unsigned long));

    cout << "VID BUFF: " << Int64((uint64_t)videoBuffer) << endl;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl $0x0, 0x2c0e5(%rip)     # 0x3d678
movb $0x0, 0x2c0e2(%rip)     # 0x3d67c
movw $0x0, 0x2c0d0(%rip)     # 0x3d673
leaq 0x2c0d6(%rip), %rdi     # 0x3d680
movl $0xa0, %edx
xorl %esi, %esi
callq 0x3170
movl $0x80000, %edi          # imm = 0x80000
callq 0x3030
movq %rax, 0x2c159(%rip)     # 0x3d720
movl $0x80000, %edx          # imm = 0x80000
movq %rax, %rdi
xorl %esi, %esi
callq 0x3170
movq 0x69f3(%rip), %rbx      # 0x17fd0
leaq 0x25c8(%rip), %rsi      # 0x13bac
movl $0xa, %edx
movq %rbx, %rdi
callq 0x3300
movq 0x2c128(%rip), %r14     # 0x3d720
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r15
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0x1163b
movq %r15, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x30, 0xe0(%r15)
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0x10, 0x10(%rbx,%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3190
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x31a0
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/ppu.cpp
// Function: dsemu::ppu::getSpritesOnLine(int)
vector<OAMEntry *> getSpritesOnLine(int lineNum) {

    vector<OAMEntry *> entries;

    for (int i=0; i<160; i += 4) {
        OAMEntry *entry = (OAMEntry *)&oamRAM[i];
        
        if (entry->y >= lineNum + 8 && entry->y < lineNum + 16) {
            entries.push_back(entry);
        }
    }

    return entries;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leal 0x8(%r14), %ebp
addl $0x10, %r14d
xorl %r12d, %r12d
leaq 0x2bf8d(%rip), %r13     # 0x3d680
movq %rsp, %r15
leaq (%r12,%r13), %rax
movq %rax, (%rsp)
movzbl (%r12,%r13), %ecx
cmpl %ecx, %ebp
setle %dl
cmpl %ecx, %r14d
setg %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x11734
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x11729
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x11734
movq %rbx, %rdi
movq %r15, %rdx
callq 0x11c6c
leaq 0x4(%r12), %rax
cmpq $0x9c, %r12
movq %rax, %r12
jb 0x116f6
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x1176e
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %r14, %rdi
callq 0x3440
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/ui.cpp
// Function: dsemu::ui::displayTile(SDL_Surface*, unsigned short, unsigned short, int, int)
void displayTile(SDL_Surface *surface, ushort startLocation, ushort tileNum, int x, int y) {

    SDL_Rect rc;

    for (int tileY=0; tileY<16; tileY += 2) {
        byte b1 = bus::read(startLocation + (tileNum * 16) + tileY);
        byte b2 = bus::read(startLocation + (tileNum * 16) + 1 + tileY);
        
        for (int bit=7, n=0; bit >= 0; bit--, n++) {
            byte hi = !!(b1 & (1 << bit)) << 1;
            byte lo = !!(b2 & (1 << bit));

            byte color = hi|lo;

            rc.x = x + (n * scale);
            rc.y = y + (tileY / 2 * scale);
            rc.w = scale;
            rc.h = scale;

            SDL_FillRect(surface, &rc, colors[color]);
        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movq %rdi, 0x38(%rsp)
shll $0x4, %edx
leal (%rdx,%rsi), %eax
movq %rax, 0x30(%rsp)
leal (%rdx,%rsi), %eax
incl %eax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movl 0x8(%rsp), %r13d
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %rax
leal (%r14,%rax), %edi
movl $0xffff, %ebx           # imm = 0xFFFF
andl %ebx, %edi
callq 0xb94c
movl %eax, %r12d
movq 0x28(%rsp), %rax
leal (%rax,%r14), %edi
andl %ebx, %edi
callq 0xb94c
movzbl %r12b, %ecx
movl %ecx, 0x14(%rsp)
movzbl %al, %eax
movl %eax, 0x10(%rsp)
movq %r14, 0x40(%rsp)
movl %r14d, %ebx
shrl %ebx
movl $0x7, %r12d
xorl %ebp, %ebp
movl 0xc(%rsp), %r14d
movl 0x14(%rsp), %eax
movl %r12d, %ecx
shrl %cl, %eax
andl $0x1, %eax
xorl %ecx, %ecx
movl 0x10(%rsp), %edx
btl %r12d, %edx
setb %cl
leal (%rcx,%rax,2), %eax
movl 0x62b0(%rip), %ecx      # 0x18264
movl %ecx, %edx
imull %ebp, %edx
addl %r13d, %edx
movl %edx, 0x18(%rsp)
movl %ecx, %edx
imull %ebx, %edx
addl %r14d, %edx
movl %edx, 0x1c(%rsp)
movl %ecx, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
leaq 0x1c05(%rip), %rcx      # 0x13be0
movl (%rcx,%rax,8), %edx
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3070
incl %ebp
addl $-0x1, %r12d
jb 0x11f92
movq 0x40(%rsp), %rcx
leal 0x2(%rcx), %eax
cmpl $0xe, %ecx
movl %eax, %r14d
jb 0x11f44
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/rockytriton[P]dreamsys_emu_gb/src/ui.cpp
// Function: dsemu::ui::updateDebugWindow()
void updateDebugWindow() {
    int xDraw = 0;
    int yDraw = 0;
    int tileNum = 0;

    for (int y=0; y<32; y++) {
        for (int x=0; x<16; x++) {
            displayTile(debugScreen, 0x8000, tileNum, xDraw + (x * scale), yDraw + (y * scale));
            xDraw += (7 * scale);
            tileNum++;
        }
        yDraw += (7 * scale);
        xDraw = 0;
    }


	SDL_UpdateTexture(sdlDebugTexture, NULL, debugScreen->pixels, debugScreen->pitch);
	SDL_RenderClear(sdlDebugRenderer);
	SDL_RenderCopy(sdlDebugRenderer, sdlDebugTexture, NULL, NULL);
	SDL_RenderPresent(sdlDebugRenderer);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x2b74e(%rip), %rdi     # 0x3d780
leal (%r14,%r15), %eax
movl 0x6227(%rip), %r8d      # 0x18264
movl %r8d, %ecx
imull %r15d, %ecx
addl %r12d, %ecx
imull %ebx, %r8d
addl %ebp, %r8d
movzwl %ax, %edx
movl $0x8000, %esi           # imm = 0x8000
callq 0x11f06
movl 0x6203(%rip), %eax      # 0x18264
leal (,%rax,8), %ecx
subl %eax, %ecx
addl %ecx, %r12d
incl %r15d
cmpl $0x10, %r15d
jne 0x1202b
movl 0x61e8(%rip), %eax      # 0x18264
leal (,%rax,8), %ecx
subl %eax, %ecx
addl %ecx, %ebp
incl %ebx
addl %r15d, %r14d
cmpl $0x20, %ebx
jne 0x12025
movq 0x2b6e0(%rip), %rdi     # 0x3d778
movq 0x2b6e1(%rip), %rax     # 0x3d780
movq 0x20(%rax), %rdx
movl 0x18(%rax), %ecx
xorl %esi, %esi
callq 0x3200
movq 0x2b6bc(%rip), %rdi     # 0x3d770
callq 0x3270
movq 0x2b6b0(%rip), %rdi     # 0x3d770
movq 0x2b6b1(%rip), %rsi     # 0x3d778
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x32e0
movq 0x2b699(%rip), %rdi     # 0x3d770
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3080
// File: /workspace/github_cpp_makefile_star2_O1/Bartor[P]kompilator/front/compiler.l.c
// Function: yy_create_buffer(_IO_FILE*, int)
YY_BUFFER_STATE yy_create_buffer  (FILE * file, int  size )
{
	YY_BUFFER_STATE b;
    
	b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state )  );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_buf_size = size;

	/* yy_ch_buf has to be 2 characters longer than the size given because
	 * we need to put in 2 end-of-buffer characters.
	 */
	b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2)  );
	if ( ! b->yy_ch_buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_is_our_buffer = 1;

	yy_init_buffer( b, file );

	return b;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %rbx
movl $0x40, %edi
callq 0x52d0
testq %rax, %rax
je 0x7675
movq %rax, %r14
movl %r15d, 0x18(%rax)
addl $0x2, %r15d
movslq %r15d, %rdi
callq 0x52d0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x7675
movl $0x1, 0x20(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x783b
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1880f(%rip), %rdi     # 0x1fe8b
callq 0x775a