LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/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 0x297e3(%rip), %rdi     # 0x36600
callq 0xe246
movq %rax, %rcx
movl 0x18(%r14), %edx
xorl %eax, %eax
addl $-0x6, %edx
cmpl $0x4, %edx
ja 0xce8f
movb (%rcx), %cl
leaq 0x34dc(%rip), %rsi      # 0x10318
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
xorl %ecx, %ecx
jmp 0xce7f
leaq 0x9680(%rip), %rdx      # 0x164d0
testb $0x10, (%rdx)
jne 0xce7f
jmp 0xce8f
leaq 0x9672(%rip), %rdx      # 0x164d0
cmpb $0x0, (%rdx)
jns 0xce8f
jmp 0xce7f
leaq 0x9664(%rip), %rdx      # 0x164d0
testb $0x10, (%rdx)
je 0xce7f
jmp 0xce8f
leaq 0x9656(%rip), %rdx      # 0x164d0
cmpb $0x0, (%rdx)
js 0xce8f
leaq 0x9658(%rip), %rax      # 0x164de
movw %bp, (%rax)
movb $0x1, (%rbx)
movzbl %cl, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x9638(%rip), %r14      # 0x164de
movzwl (%r14), %eax
incl %eax
movzwl %ax, %edi
callq 0xa6ec
movl %eax, %ebp
cmpb $-0x2, %al
jne 0xcedd
movq 0x910f(%rip), %rdi      # 0x15fd0
leaq 0x356f(%rip), %rsi      # 0x10437
callq 0x3260
movq %rax, %rdi
callq 0x3130
pushq $0x5
popq %rdi
callq 0x31e0
movsbl %bpl, %eax
addw (%r14), %ax
movzwl %ax, %edi
leaq 0xf(%rsp), %rdx
movq %rbx, %rsi
callq 0xce0a
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xcf4f
cmpl $0xd, %eax
jne 0xcf7a
leaq 0x95c2(%rip), %r14      # 0x164de
movzwl (%r14), %edi
incl %edi
movl $0xffff, %r15d          # imm = 0xFFFF
andl %r15d, %edi
callq 0xa6ec
movl %eax, %ebp
movzwl (%r14), %edi
addl $0x2, %edi
andl %r15d, %edi
callq 0xa6ec
movzbl %al, %ecx
shll $0x8, %ecx
movzbl %bpl, %eax
orl %ecx, %eax
jmp 0xcf59
leaq 0x9580(%rip), %rax      # 0x164d6
movzwl (%rax), %eax
movzbl 0x14(%rbx), %ecx
subl %ecx, %eax
movzwl %ax, %edi
leaq 0x7(%rsp), %rdx
movq %rbx, %rsi
callq 0xce0a
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x904f(%rip), %rdi      # 0x15fd0
leaq 0x34ba(%rip), %rsi      # 0x10442
callq 0x3260
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x32d0
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movl 0x1c(%rdi), %edi
xorl %esi, %esi
callq 0xc723
movq %rax, %r14
callq 0xacb1
movl %eax, %ebx
movq 0x8f7a(%rip), %rdi      # 0x15fd0
leaq 0x33f3(%rip), %rsi      # 0x10450
callq 0x3260
movq %rax, %rdi
movl %ebx, %esi
callq 0xb2b0
movq %rax, %rdi
callq 0x3130
cmpq 0x8f4d(%rip), %r14      # 0x15fc8
je 0xd083
movw %bx, (%r14)
jmp 0xd093
andl $0xfff0, %ebx           # imm = 0xFFF0
leaq 0x9440(%rip), %rax      # 0x164d0
movw %bx, (%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
movl 0x1c(%rdi), %edi
xorl %esi, %esi
callq 0xc723
movq %rax, %rbx
movzwl (%rax), %edi
callq 0xac08
movq 0x8f16(%rip), %rdi      # 0x15fd0
leaq 0x339e(%rip), %rsi      # 0x1045f
callq 0x3260
movzwl (%rbx), %esi
movq %rax, %rdi
callq 0xb2b0
movq %rax, %rdi
callq 0x3130
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleCALL(dsemu::cpu::OpCode const&)
int handleCALL(const OpCode &op) {
    ushort lca = regPC + op.length;
    bool didJump;
    ushort location = toShort(bus::read(regPC + 1), bus::read(regPC + 2)) - op.length;
    //lastCallAddress = regPC + op.length;

    //for (int i=0; i<callSize; i++) {
    //    cout << " ";
    //}

    //char sz[256];
    //sprintf("%%dc", callSize);

    callSize++;

    if (callSize > 30) {
        callSize = callSize + 0;
    }

    cout << std::setfill('-') << std::setw(callSize) << "-" << "HANDLING CALL: " << Short(regPC) << " CALLSIZE: " << callSize << " STACK: ";


    if (regPC == 0x2200) {
        regPC += 0;
    }

    int ret = conditionalJump(location, op, didJump);

    if (didJump) {
        cpu::push((ushort)(lca));
        lastCallAddress = lca;
    } else {
        cout << "NO" << endl;
    }

    for (size_t i=0; i<THESTACK.size(); i++) {
        cout << Byte(THESTACK[i]) << "-";
    }
    
    cout << endl;

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x93ec(%rip), %r13      # 0x164de
movzwl (%r13), %r15d
movzbl 0x14(%rdi), %r12d
leal 0x1(%r15), %edi
movl $0xffff, %r14d          # imm = 0xFFFF
andl %r14d, %edi
callq 0xa6ec
movl %eax, %ebp
movzwl (%r13), %edi
addl $0x2, %edi
andl %r14d, %edi
callq 0xa6ec
movzbl %al, %eax
shll $0x8, %eax
movzbl %bpl, %ebp
orl %eax, %ebp
movzbl 0x14(%rbx), %eax
subl %eax, %ebp
incl 0x294fc(%rip)           # 0x36634
movq 0x8e91(%rip), %rdi      # 0x15fd0
pushq $0x2d
popq %rsi
callq 0x3360
movslq 0x294e6(%rip), %rcx     # 0x36634
movq (%rax), %rdx
movq -0x18(%rdx), %rdx
movq %rcx, 0x10(%rax,%rdx)
leaq 0x3307(%rip), %rsi      # 0x10468
movq %rax, %rdi
callq 0x3260
leaq 0x32fa(%rip), %rsi      # 0x1046a
movq %rax, %rdi
callq 0x3260
movzwl (%r13), %esi
movq %rax, %rdi
callq 0xb2b0
leaq 0x32ee(%rip), %rsi      # 0x1047a
movq %rax, %rdi
callq 0x3260
movl 0x2949a(%rip), %esi     # 0x36634
movq %rax, %rdi
callq 0x33e0
leaq 0x32dd(%rip), %rsi      # 0x10486
movq %rax, %rdi
callq 0x3260
andl %r14d, %ebp
leaq 0x7(%rsp), %r14
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xce0a
movl %eax, %ebx
cmpb $0x1, (%r14)
jne 0xd1e8
movzwl %r12w, %eax
addl %r15d, %eax
movzwl %ax, %ebp
movl %ebp, %edi
callq 0xac08
movw %bp, 0x2944a(%rip)      # 0x36630
jmp 0xd203
movq 0x8de1(%rip), %rdi      # 0x15fd0
leaq 0x3299(%rip), %rsi      # 0x1048f
callq 0x3260
movq %rax, %rdi
callq 0x3130
xorl %r12d, %r12d
leaq 0x92eb(%rip), %r13      # 0x164f8
movq 0x8dbc(%rip), %r14      # 0x15fd0
leaq 0x324d(%rip), %r15      # 0x10468
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
cmpq %rcx, %r12
jae 0xd248
movzbl (%rax,%r12), %esi
movq %r14, %rdi
callq 0xaba6
movq %rax, %rdi
movq %r15, %rsi
callq 0x3260
incq %r12
jmp 0xd21b
movq 0x8d81(%rip), %rdi      # 0x15fd0
callq 0x3130
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleRET(dsemu::cpu::OpCode const&)
int handleRET(const OpCode &op) {
    bool didJump = false;
    ushort location = cpu::spop();

    //cout << "HANDLING RET: " << Short(lastCallAddress) << " - " << Short(location) << endl;
    int ret = conditionalJump(location - 1, op, didJump);

    
    if (regPC == 0x3017) {
        regPC = regPC + 0;
    }

    if (didJump) {
        cout << std::setfill('-') << std::setw(callSize) << "-" << "RET - AFTER RET: " << ret << " - " << Short(regPC) << " / " << Short(location) << " CALLSIZE: " << callSize << " STACK: ";

        if (!cameFromI) {
            //for (int i=0; i<callSize; i++) {
            //    cout << " ";
            //}

            callSize--;
        }

        if (callSize < 0) {
            cout << "OOPS" << endl;
        }

        for (size_t i=0; i<THESTACK.size(); i++) {
            cout << Byte(THESTACK[i]) << "-";
        }
        
        cout << endl;
    }

    if (!didJump) {
        cpu::push(location);
    }

    return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xf(%rsp), %r15
movb $0x0, (%r15)
callq 0xacb1
movl %eax, %r14d
leal -0x1(%r14), %eax
movzwl %ax, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0xce0a
movl %eax, %ebx
cmpb $0x1, (%r15)
jne 0xd3de
movq 0x8d25(%rip), %rdi      # 0x15fd0
pushq $0x2d
popq %rsi
callq 0x3360
movslq 0x2937a(%rip), %rcx     # 0x36634
movq (%rax), %rdx
movq -0x18(%rdx), %rdx
movq %rcx, 0x10(%rax,%rdx)
leaq 0x319b(%rip), %rsi      # 0x10468
movq %rax, %rdi
callq 0x3260
leaq 0x31b6(%rip), %rsi      # 0x10492
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
movl %ebx, %esi
callq 0x33e0
leaq 0x2d24(%rip), %rsi      # 0x10019
movq %rax, %rdi
callq 0x3260
leaq 0x91da(%rip), %rcx      # 0x164de
movzwl (%rcx), %esi
movq %rax, %rdi
callq 0xb2b0
leaq 0x318e(%rip), %rsi      # 0x104a4
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
movl %r14d, %esi
callq 0xb2b0
leaq 0x314a(%rip), %rsi      # 0x1047a
movq %rax, %rdi
callq 0x3260
movl 0x292f6(%rip), %esi     # 0x36634
movq %rax, %rdi
callq 0x33e0
leaq 0x3139(%rip), %rsi      # 0x10486
movq %rax, %rdi
callq 0x3260
movl 0x292d9(%rip), %eax     # 0x36634
cmpb $0x0, 0x292d6(%rip)     # 0x36638
jne 0xd36c
decl %eax
movl %eax, 0x292c8(%rip)     # 0x36634
testl %eax, %eax
jns 0xd38b
movq 0x8c59(%rip), %rdi      # 0x15fd0
leaq 0x312a(%rip), %rsi      # 0x104a8
callq 0x3260
movq %rax, %rdi
callq 0x3130
xorl %r12d, %r12d
leaq 0x9163(%rip), %r13      # 0x164f8
movq 0x8c34(%rip), %r14      # 0x15fd0
leaq 0x30c5(%rip), %r15      # 0x10468
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
cmpq %rcx, %r12
jae 0xd3d0
movzbl (%rax,%r12), %esi
movq %r14, %rdi
callq 0xaba6
movq %rax, %rdi
movq %r15, %rsi
callq 0x3260
incq %r12
jmp 0xd3a3
movq 0x8bf9(%rip), %rdi      # 0x15fd0
callq 0x3130
jmp 0xd3e7
movzwl %r14w, %edi
callq 0xac08
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x90b5(%rip), %rax      # 0x164d0
movzbl (%rax), %r9d
movl %r9d, %r8d
andb $0x2f, %r8b
testl %edx, %edx
je 0xd489
movl %r9d, %edx
shrb $0x4, %dl
shrl $0x4, %r9d
movzbl %cl, %r11d
andl %r9d, %r11d
addl %esi, %r11d
addl %edi, %r11d
testb %r11b, %r11b
sete %r9b
shlb $0x7, %r9b
cmpl $0x100, %r11d           # imm = 0x100
setae %r10b
shlb $0x4, %r10b
orb %r9b, %r10b
orb %r8b, %r10b
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 0xd4ec
movl %r9d, %edx
shrb $0x4, %dl
movl %edi, %r10d
subl %esi, %r10d
shlb $0x3, %r9b
sarb $0x7, %r9b
movsbl %r9b, %r11d
xorl %r9d, %r9d
testb %cl, %cl
cmovnel %r11d, %r9d
addl %r10d, %r9d
testb %r9b, %r9b
sete %r10b
shlb $0x7, %r10b
shrl $0x1b, %r9d
andb $0x10, %r9b
orb %r10b, %r9b
orb %r8b, %r9b
andl $0xf, %edi
andl $0xf, %esi
subl %esi, %edi
andb %cl, %dl
movzbl %dl, %ecx
movl %r9d, %edx
andb $-0x61, %dl
orb $0x40, %dl
orb $0x60, %r9b
cmpl %ecx, %edi
movzbl %r9b, %esi
movzbl %dl, %ecx
cmovsl %esi, %ecx
movb %cl, (%rax)
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
movq %rdi, %rbx
movl 0x20(%rdi), %edi
pushq $0x1
popq %rsi
callq 0xc723
cmpb $-0x32, (%rbx)
jne 0xd5be
leaq 0x8fa9(%rip), %rax      # 0x164de
movzwl (%rax), %eax
incl %eax
movzwl %ax, %edi
callq 0xa6ec
leaq 0x8f87(%rip), %rcx      # 0x164d0
movzbl 0x1(%rcx), %edx
movzbl %al, %ebx
movzbl (%rcx), %esi
movl %esi, %edi
shrl $0x4, %edi
andl $0x1, %edi
leal (%rdx,%rdi), %eax
addl %ebx, %eax
andb $-0x61, %sil
movl %edx, %r8d
andl $0xf, %r8d
movl %ebx, %r9d
andl $0xf, %r9d
addl %edi, %r8d
addl %r9d, %r8d
leal 0x20(%rsi), %edi
cmpl $0x10, %r8d
movzbl %sil, %esi
movzbl %dil, %edi
cmovbl %esi, %edi
btl $0x4, %edi
adcb %dl, %bl
movl %edi, %edx
andb $-0x51, %dl
orb $0x10, %dil
cmpl $0x100, %eax            # imm = 0x100
movzbl %dil, %eax
movzbl %dl, %edx
cmovael %eax, %edx
movl %edx, %eax
andb $0x3f, %al
orb $-0x80, %dl
testb %bl, %bl
movzbl %dl, %edx
movzbl %al, %eax
cmovel %edx, %eax
movb %al, (%rcx)
jmp 0xd5e2
leaq 0x8f0b(%rip), %rcx      # 0x164d0
movzbl 0x1(%rcx), %edi
movzbl (%rax), %esi
movzbl (%rcx), %eax
btl $0x4, %eax
movl %esi, %ebx
adcb %dil, %bl
pushq $0x1
popq %rcx
movl %ecx, %edx
callq 0xd414
leaq 0x8ee7(%rip), %rax      # 0x164d0
movb %bl, 0x1(%rax)
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
pushq %rax
movl 0x1c(%rdi), %eax
cmpl $0xa, %eax
je 0xd63f
testl %eax, %eax
jne 0xd680
movl 0x20(%rdi), %edi
pushq $0x1
popq %rbx
movl %ebx, %esi
callq 0xc723
leaq 0x8eb8(%rip), %r12      # 0x164d0
movzbl 0x1(%r12), %r14d
movzbl (%rax), %r15d
movl %r14d, %edi
movl %r15d, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xd414
leal (%r15,%r14), %eax
movb %al, 0x1(%r12)
jmp 0xd6dc
leaq 0x8e98(%rip), %rax      # 0x164de
movzwl (%rax), %eax
incl %eax
movzwl %ax, %edi
callq 0xa6ec
leaq 0x8e82(%rip), %r14      # 0x164dc
movzbl (%r14), %edi
movzbl %al, %ebx
pushq $0x1
popq %rdx
movl %ebx, %esi
xorl %ecx, %ecx
callq 0xd414
movsbl %bl, %eax
addw %ax, (%r14)
leaq 0x8e55(%rip), %rax      # 0x164d0
andb $0x7f, (%rax)
jmp 0xd6dc
movl 0x20(%rdi), %edi
xorl %esi, %esi
callq 0xc723
leaq 0x8e45(%rip), %rsi      # 0x164d6
movzwl (%rsi), %ecx
movzwl (%rax), %edi
addl %ecx, %edi
cmpl $0x10000, %edi          # imm = 0x10000
setae %dl
leaq 0x8e27(%rip), %rax      # 0x164d0
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
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %rsi
callq 0xc723
leaq 0x8dd0(%rip), %r14      # 0x164d0
movzbl 0x1(%r14), %ebx
movzbl (%rax), %ebp
movl %ebx, %edi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xd414
subb %bpl, %bl
movb %bl, 0x1(%r14)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
movl 0x1c(%rdi), %edi
pushq $0x1
popq %rbx
movl %ebx, %esi
callq 0xc723
leaq 0x8d95(%rip), %r14      # 0x164d0
movzbl 0x1(%r14), %edi
movzbl (%rax), %esi
movl %edi, %eax
subb %sil, %al
movb (%r14), %bpl
shlb $0x3, %bpl
sarb $0x7, %bpl
addb %al, %bpl
xorl %edx, %edx
movl %ebx, %ecx
callq 0xd414
movb %bpl, 0x1(%r14)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %rsi
callq 0xc723
movb (%rax), %al
leaq 0x8d51(%rip), %rcx      # 0x164d0
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_O2/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
pushq $0x1
popq %rsi
callq 0xc723
movb (%rax), %al
leaq 0x8d24(%rip), %rcx      # 0x164d0
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_O2/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
pushq $0x1
popq %rsi
callq 0xc723
movb (%rax), %al
leaq 0x8cf9(%rip), %rcx      # 0x164d0
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_O2/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 0xd876
movl %edi, %eax
leaq 0x2b24(%rip), %rcx      # 0x1032c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8cb8(%rip), %rax      # 0x164d0
jmp 0xd868
leaq 0x8cbd(%rip), %rax      # 0x164de
movzwl (%rax), %eax
incl %eax
movzwl %ax, %edi
jmp 0xa6ec
leaq 0x8c9f(%rip), %rax      # 0x164d4
jmp 0xd873
leaq 0x8c98(%rip), %rax      # 0x164d6
jmp 0xd868
leaq 0x8c8b(%rip), %rax      # 0x164d2
jmp 0xd873
leaq 0x8c86(%rip), %rax      # 0x164d6
movzwl (%rax), %edi
jmp 0xa6ec
leaq 0x8c75(%rip), %rax      # 0x164d4
jmp 0xd868
leaq 0x8c6a(%rip), %rax      # 0x164d2
movb 0x1(%rax), %al
retq
leaq 0x8c63(%rip), %rax      # 0x164d6
movb (%rax), %al
retq
pushq %rax
movq 0x8752(%rip), %rdi      # 0x15fd0
leaq 0x2c28(%rip), %rsi      # 0x104ad
callq 0x3260
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x32d0
// File: /workspace/github_cpp_makefile_star2_O2/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 0xc89d
leaq 0x8c2f(%rip), %rax      # 0x164d6
decw (%rax)
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xc89d
leaq 0x8c1b(%rip), %rax      # 0x164d6
incw (%rax)
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xd9c0
leaq 0x2a86(%rip), %rcx      # 0x10360
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8be6(%rip), %rax      # 0x164d0
jmp 0xd953
leaq 0x8be1(%rip), %rax      # 0x164d4
jmp 0xd966
cmpl $0xc, 0x18(%rdi)
leaq 0x8bd6(%rip), %r14      # 0x164d6
movzwl (%r14), %eax
jne 0xd9b8
movzwl %ax, %edi
callq 0xa6ec
movl %eax, %ebx
movl %eax, %ebp
incb %bpl
movzwl (%r14), %edi
movzbl %bpl, %esi
callq 0xa76c
jmp 0xd96e
leaq 0x8ba3(%rip), %rax      # 0x164d2
jmp 0xd966
leaq 0x8b9c(%rip), %rax      # 0x164d4
jmp 0xd953
leaq 0x8b91(%rip), %rax      # 0x164d2
jmp 0xd9ae
leaq 0x8b88(%rip), %rax      # 0x164d2
jmp 0xd953
leaq 0x8b83(%rip), %rax      # 0x164d6
movb 0x1(%rax), %bl
leal 0x1(%rbx), %ebp
movb %bpl, 0x1(%rax)
jmp 0xd96e
leaq 0x8b70(%rip), %rax      # 0x164d6
movb (%rax), %bl
leal 0x1(%rbx), %ebp
movb %bpl, (%rax)
testb %bpl, %bpl
sete %al
leaq 0x8b55(%rip), %rcx      # 0x164d0
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 0xd9b1
leaq 0x8b37(%rip), %rax      # 0x164dc
jmp 0xd9ae
leaq 0x8b26(%rip), %rax      # 0x164d4
incw (%rax)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
incl %eax
movw %ax, (%r14)
jmp 0xd9b1
movq 0x8609(%rip), %rdi      # 0x15fd0
leaq 0x2ae7(%rip), %rsi      # 0x104b5
callq 0x3260
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x32d0
// File: /workspace/github_cpp_makefile_star2_O2/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 0xdade
leaq 0x2991(%rip), %rcx      # 0x1038c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8ac5(%rip), %rax      # 0x164d0
jmp 0xda70
leaq 0x8ac0(%rip), %rax      # 0x164d4
jmp 0xda81
cmpl $0xc, 0x18(%rdi)
leaq 0x8ab5(%rip), %r14      # 0x164d6
movzwl (%r14), %eax
jne 0xdad6
movzwl %ax, %edi
callq 0xa6ec
movl %eax, %ebx
decb %bl
movzwl (%r14), %edi
movzbl %bl, %esi
callq 0xa76c
jmp 0xda87
leaq 0x8a86(%rip), %rax      # 0x164d2
jmp 0xda81
leaq 0x8a7f(%rip), %rax      # 0x164d4
jmp 0xda70
leaq 0x8a74(%rip), %rax      # 0x164d2
jmp 0xdac9
leaq 0x8a6b(%rip), %rax      # 0x164d2
jmp 0xda70
leaq 0x8a66(%rip), %rax      # 0x164d6
movb 0x1(%rax), %bl
decb %bl
movb %bl, 0x1(%rax)
jmp 0xda87
leaq 0x8a55(%rip), %rax      # 0x164d6
movb (%rax), %bl
decb %bl
movb %bl, (%rax)
testb %bl, %bl
sete %al
leaq 0x8a3d(%rip), %rcx      # 0x164d0
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 0xdacc
leaq 0x8a1c(%rip), %rax      # 0x164dc
jmp 0xdac9
leaq 0x8a0b(%rip), %rax      # 0x164d4
decw (%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
decl %eax
movw %ax, (%r14)
jmp 0xdacc
movq 0x84eb(%rip), %rdi      # 0x15fd0
leaq 0x29da(%rip), %rsi      # 0x104c6
callq 0x3260
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x32d0
// File: /workspace/github_cpp_makefile_star2_O2/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 0x8996(%rip), %rax      # 0x164d0
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_O2/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 0x88d3(%rip), %r14      # 0x164de
movzwl (%r14), %eax
incl %eax
movzwl %ax, %edi
callq 0xac08
movl 0x1c(%rbx), %eax
addl $-0xf, %eax
cmpl $0x8, %eax
jae 0xdc3f
movl %eax, %eax
leaq 0x28c9(%rip), %rcx      # 0x104f6
movzwl (%rcx,%rax,2), %eax
movw %ax, (%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x838a(%rip), %rdi      # 0x15fd0
leaq 0x288a(%rip), %rsi      # 0x104d7
callq 0x3260
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x32d0
// File: /workspace/github_cpp_makefile_star2_O2/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
leaq 0x10(%rdi), %rsi
leaq 0x28464(%rip), %rdi     # 0x36598
callq 0xec16
leaq 0x28460(%rip), %rcx     # 0x365a0
cmpq %rcx, %rax
je 0xe16a
movq %rbx, %rdi
callq *0x28(%rax)
cmpl $0x1d, 0x10(%rbx)
je 0xe168
cmpb $0x1, 0x284a0(%rip)     # 0x365f8
jne 0xe168
movb $0x0, 0x28497(%rip)     # 0x365f8
movb $0x1, 0x28491(%rip)     # 0x365f9
popq %rbx
retq
movq 0x7e5f(%rip), %rdi      # 0x15fd0
leaq 0x236b(%rip), %rsi      # 0x104e3
callq 0x3260
movl (%rbx), %esi
movq %rax, %rdi
callq 0xaba6
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rdi
callq 0x32d0
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %rax
andl $0x0, 0x2ca04(%rip)     # 0x3b658
movb $0x0, 0x2ca01(%rip)     # 0x3b65c
andw $0x0, 0x2c9f0(%rip)     # 0x3b653
leaq 0x2c9f6(%rip), %rdi     # 0x3b660
movl $0xa0, %edx
xorl %esi, %esi
callq 0x3150
movl $0x80000, %edi          # imm = 0x80000
callq 0x3030
movq %rax, 0x2ca79(%rip)     # 0x3b700
movl $0x80000, %edx          # imm = 0x80000
movq %rax, %rdi
xorl %esi, %esi
callq 0x3150
movq 0x7333(%rip), %rdi      # 0x15fd0
leaq 0x1f08(%rip), %rsi      # 0x10bac
callq 0x3260
movq 0x2ca50(%rip), %rsi     # 0x3b700
movq %rax, %rdi
callq 0xb30f
movq %rax, %rdi
popq %rax
jmp 0x3130
// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, 0x10(%rdi)
leal 0x8(%r14), %ebp
addl $0x10, %r14d
xorl %r12d, %r12d
leaq 0x2c94e(%rip), %r13     # 0x3b660
movq %rsp, %r15
cmpq $0x9f, %r12
ja 0xed4d
leaq (%r12,%r13), %rax
movq %rax, (%rsp)
movzbl (%r12,%r13), %eax
cmpl %eax, %ebp
setle %cl
cmpl %eax, %r14d
setg %al
andb %cl, %al
cmpb $0x1, %al
jne 0xed47
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf12a
addq $0x4, %r12
jmp 0xed15
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
callq 0xf148
movq %r14, %rdi
callq 0x3400
// File: /workspace/github_cpp_makefile_star2_O2/rockytriton[P]dreamsys_emu_gb/src/ppu.cpp
// Function: dsemu::ppu::drawLine(int)
void drawLine(int lineNum) {
    int mapy = (lineNum + getYScroll()) % 256;
    byte tileY = ((lineNum) % 8) * 2;

    auto sprites = getSpritesOnLine(lineNum);

    for (int x=0; x<XRES; x += 1) {
        auto sprite = getSpriteOnX(sprites, x);

        int mapx = (x + getXScroll()) % 256;

        ushort bgTileNum = bus::read(ppu::bgMapStart() + (mapx/8) + ((mapy/8) * 32));

        if (ppu::bgTileStart() == 0x8800) {
            bgTileNum += 128;
        }

        if (sprite != nullptr) {
            bgTileNum = sprite->tile;
        }

        byte b1 = bus::read(ppu::bgTileStart() + (bgTileNum * 16) + tileY);
        byte b2 = bus::read(ppu::bgTileStart() + (bgTileNum * 16) + 1 + tileY);

        int bit = 7 - (x % 8);
        byte hi = !!(b1 & (1 << bit)) << 1;
        byte lo = !!(b2 & (1 << bit));
        byte color = hi|lo;
        unsigned long c = colors[color];

        videoBuffer[x + (lineNum * XRES)] = c;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %r14d
movzbl 0x2c895(%rip), %eax     # 0x3b654
addl %edi, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %edx, %ebp
pushq $0x8
popq %rcx
movl %edi, %eax
cltd
idivl %ecx
movl %edx, %r15d
addl %edx, %r15d
leaq 0x10(%rsp), %rdi
movl %r14d, %esi
callq 0xece4
movw $0x8, %cx
movl %ebp, %eax
cwtd
idivw %cx
movl %eax, %ebp
shll $0x5, %ebp
movzbl %r15b, %r12d
leal 0x1(%r12), %eax
movl %eax, 0xc(%rsp)
imull $0xa0, %r14d, %eax
movslq %eax, %rbx
shlq $0x3, %rbx
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
cmpq $0xa0, %r14
je 0xef0e
movl %r14d, %esi
callq 0xed72
movq %rax, %r15
movzbl 0x2c81b(%rip), %eax     # 0x3b653
movb 0x2c813(%rip), %cl      # 0x3b651
andb $0x8, %cl
shrb $0x3, %cl
addl %r14d, %eax
movzbl %cl, %ecx
shll $0xa, %ecx
shrb $0x3, %al
movzbl %al, %eax
orl %ebp, %eax
addl %ecx, %eax
addl $0xffff9800, %eax       # imm = 0xFFFF9800
movzwl %ax, %edi
callq 0xa6ec
movzbl %al, %ecx
movb 0x2c7e4(%rip), %al      # 0x3b651
leal 0x80(%rcx), %r13d
testb $0x10, %al
cmovnel %ecx, %r13d
testq %r15, %r15
je 0xee84
movzbl 0x2(%r15), %r13d
xorl %ecx, %ecx
testb $0x10, %al
sete %cl
shll $0xb, %ecx
orl %r12d, %ecx
shll $0x4, %r13d
leal (%rcx,%r13), %edi
addl $0x8000, %edi           # imm = 0x8000
callq 0xa6ec
movl %eax, %r15d
xorl %eax, %eax
testb $0x10, 0x2c7a1(%rip)    # 0x3b651
sete %al
shll $0xb, %eax
addl 0xc(%rsp), %r13d
leal (%rax,%r13), %edi
addl $0x8000, %edi           # imm = 0x8000
callq 0xa6ec
movzbl %r15b, %edx
movl %r14d, %ecx
notb %cl
andb $0x7, %cl
shrl %cl, %edx
andl $0x1, %edx
movzbl %al, %eax
movzbl %cl, %ecx
xorl %esi, %esi
btl %ecx, %eax
setb %sil
leal (%rsi,%rdx,2), %eax
leaq 0x1cec(%rip), %rcx      # 0x10be0
movq (%rcx,%rax,8), %rax
movq 0x2c801(%rip), %rcx     # 0x3b700
addq %rbx, %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0xee14
callq 0xf148
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xef26
jmp 0xef26
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xf148
movq %rbx, %rdi
callq 0x3400
// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %r8d, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movq %rdi, %r14
shll $0x4, %edx
leal (%rdx,%rsi), %eax
movq %rax, 0x28(%rsp)
leal (%rdx,%rsi), %eax
incl %eax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
cmpl $0x10, %ebx
jae 0xf4f6
movq 0x28(%rsp), %rax
leal (%rbx,%rax), %edi
movl $0xffff, %ebp           # imm = 0xFFFF
andl %ebp, %edi
callq 0xa6ec
movl %eax, %r12d
movq 0x20(%rsp), %rax
leal (%rax,%rbx), %edi
andl %ebp, %edi
callq 0xa6ec
movzbl %r12b, %r13d
movzbl %al, %r15d
movq %rbx, 0x30(%rsp)
shrl %ebx
xorl %ebp, %ebp
pushq $0x7
popq %r12
cmpl $0x8, %ebp
je 0xf4e9
movl %r13d, %eax
movl %r12d, %ecx
shrl %cl, %eax
andl $0x1, %eax
xorl %ecx, %ecx
btl %r12d, %r15d
setb %cl
leal (%rcx,%rax,2), %eax
movl 0x6d9b(%rip), %ecx      # 0x16244
movl %ecx, %edx
imull %ebp, %edx
addl 0x8(%rsp), %edx
movl %edx, 0x10(%rsp)
movl %ecx, %edx
imull %ebx, %edx
addl 0xc(%rsp), %edx
movl %edx, 0x14(%rsp)
movl %ecx, 0x18(%rsp)
movl %ecx, 0x1c(%rsp)
leaq 0x170e(%rip), %rcx      # 0x10be0
movl (%rcx,%rax,8), %edx
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3060
decl %r12d
incl %ebp
jmp 0xf487
movq 0x30(%rsp), %rbx
addl $0x2, %ebx
jmp 0xf443
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpl $0x20, %r14d
je 0xf57d
movzwl %bp, %r12d
xorl %r13d, %r13d
xorl %r15d, %r15d
cmpl $0x10, %r15d
je 0xf56c
leal (%r12,%r15), %eax
movq 0x2c228(%rip), %rdi     # 0x3b760
movl 0x6d05(%rip), %r8d      # 0x16244
movl %r8d, %ecx
imull %r15d, %ecx
addl %r13d, %ecx
imull %r14d, %r8d
addl %ebx, %r8d
movzwl %ax, %edx
movl $0x8000, %esi           # imm = 0x8000
callq 0xf412
imull $0x7, 0x6ce0(%rip), %eax # 0x16244
addl %eax, %r13d
incl %r15d
jmp 0xf527
imull $0x7, 0x6cd1(%rip), %eax # 0x16244
addl %eax, %ebx
incl %r14d
addl %r15d, %ebp
jmp 0xf517
movq 0x2c1d4(%rip), %rdi     # 0x3b758
movq 0x2c1d5(%rip), %rax     # 0x3b760
movq 0x20(%rax), %rdx
movl 0x18(%rax), %ecx
xorl %esi, %esi
callq 0x31d0
movq 0x2c1b0(%rip), %rdi     # 0x3b750
callq 0x3250
movq 0x2c1a4(%rip), %rdi     # 0x3b750
movq 0x2c1a5(%rip), %rsi     # 0x3b758
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x32b0
movq 0x2c18d(%rip), %rdi     # 0x3b750
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3070
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x40
popq %rdi
callq 0x5280
testq %rax, %rax
je 0x729c
movq %rax, %r14
movl %r15d, 0x18(%rax)
addl $0x2, %r15d
movslq %r15d, %rdi
callq 0x5280
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x729c
movl $0x1, 0x20(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x743b
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10b98(%rip), %rdi     # 0x17e3b
callq 0x73b1
// File: /workspace/github_cpp_makefile_star2_O2/Bartor[P]kompilator/front/compiler.l.c
// Function: yy_load_buffer_state()
static void yy_load_buffer_state  (void)
{
    	(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
	(yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
	yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
	(yy_hold_char) = *(yy_c_buf_p);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x1900d(%rip), %rax     # 0x202c0
movq 0x1900e(%rip), %rcx     # 0x202c8
movq (%rax,%rcx,8), %rdx
movl 0x1c(%rdx), %esi
movl %esi, 0x19021(%rip)     # 0x202e8
movq 0x10(%rdx), %rdx
movq %rdx, 0x18ffe(%rip)     # 0x202d0
movq %rdx, 0x18fd7(%rip)     # 0x202b0
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, 0x18fb1(%rip)     # 0x20298
movb (%rdx), %al
movb %al, 0x18fe9(%rip)      # 0x202d8
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Bartor[P]kompilator/front/compiler.l.c
// Function: yy_get_previous_state()
static yy_state_type yy_get_previous_state (void)
{
	yy_state_type yy_current_state;
	char *yy_cp;
    
	yy_current_state = (yy_start);

	for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
		{
		YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
		if ( yy_accept[yy_current_state] )
			{
			(yy_last_accepting_state) = yy_current_state;
			(yy_last_accepting_cpos) = yy_cp;
			}
		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
			{
			yy_current_state = (int) yy_def[yy_current_state];
			if ( yy_current_state >= 122 )
				yy_c = yy_meta[yy_c];
			}
		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
		}

	return yy_current_state;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x18fba(%rip), %eax     # 0x202bc
movq 0x18fa7(%rip), %rcx     # 0x202b0
movq 0x18fc0(%rip), %rdx     # 0x202d0
leaq 0x10449(%rip), %rsi     # 0x17760
leaq 0x106a2(%rip), %rdi     # 0x179c0
leaq 0x1053b(%rip), %r8      # 0x17860
leaq 0x108c4(%rip), %r9      # 0x17bf0
leaq 0x1078d(%rip), %r10     # 0x17ac0
leaq 0x10886(%rip), %r11     # 0x17bc0
leaq 0x1031f(%rip), %rbx     # 0x17660
cmpq %rdx, %rcx
jae 0x73a8
movzbl (%rcx), %r14d
testq %r14, %r14
je 0x7355
movb (%r14,%rbx), %r14b
jmp 0x7358
movb $0x1, %r14b
movslq %eax, %r15
cmpw $0x0, (%rsi,%r15,2)
je 0x7370
movl %eax, 0x18f73(%rip)     # 0x202dc
movq %rcx, 0x18f70(%rip)     # 0x202e0
movzbl %r14b, %r14d
movslq %eax, %r15
movswq (%rdi,%r15,2), %rax
addq %r14, %rax
movswl (%r8,%rax,2), %r12d
cmpl %r12d, %r15d
je 0x739e
movswl (%r10,%r15,2), %eax
addl $-0x3, %r15d
cmpl $0x1, %r15d
ja 0x7374
movb (%r14,%r11), %r14b
jmp 0x7370
movswl (%r9,%rax,2), %eax
incq %rcx
jmp 0x7341
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Bartor[P]kompilator/front/compiler.l.c
// Function: yyrestart(_IO_FILE*)
void yyrestart  (FILE * input_file )
{
    
	if ( ! YY_CURRENT_BUFFER ){
        yyensure_buffer_stack ();
		YY_CURRENT_BUFFER_LVALUE =
            yy_create_buffer( yyin, YY_BUF_SIZE );
	}

	yy_init_buffer( YY_CURRENT_BUFFER, input_file );
	yy_load_buffer_state(  );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x18ed8(%rip), %rax     # 0x202c0
testq %rax, %rax
je 0x73fd
movq 0x18ed4(%rip), %rcx     # 0x202c8
movq (%rax,%rcx,8), %rdi
testq %rdi, %rdi
jne 0x7428
callq 0x71a2
movq 0x18e8f(%rip), %rdi     # 0x20298
movl $0x4000, %esi           # imm = 0x4000
callq 0x7242
movq %rax, %rdi
movq 0x18ea3(%rip), %rax     # 0x202c0
movq 0x18ea4(%rip), %rcx     # 0x202c8
movq %rdi, (%rax,%rcx,8)
movq %rbx, %rsi
callq 0x743b
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x72a8