// File: /workspace/github_cpp_makefile_star2_O3/mdpkh[P]retro6k/src/fake6502.c
// Function: adc
static void adc() {
    penaltyop = 1;
    value = getvalue();
#ifdef NES_CPU
    result = (uint16_t)a + value + (uint16_t)(status & FLAG_CARRY); // ORIGINAL BY MC
   
    carrycalc(result);
    zerocalc(result);
    overflowcalc(result, a, value);
    signcalc(result);
#else
    if (status & FLAG_DECIMAL) {
        // set or clear zero flag based on binary-mode result
        zerocalc((uint16_t)a + value + (uint16_t)(status & FLAG_CARRY));
        
        result = ((uint16_t)a & 0x0f) + ((uint16_t)value & 0x0f) + ((uint16_t)status & FLAG_CARRY); // MODIFIED BY MDPKH

        clearcarry();
        if (result > 0x09) {
            result = (result + 0x06) & 0x0f | 0x10;
        }
        result += ((uint16_t)a & 0xf0) + ((uint16_t)value & 0xf0); // MODIFIED BY MDPKH, PART 2 OF CALCULATION
        
        overflowcalc(result, a, value);
        signcalc(result);
        
        if (result > 0x9f) {
            result += 0x60;
            setcarry();
        }
        carrycalc(result);
        
        // clockticks6502++; // 65C02 only!
    } else {
        result = (uint16_t)a + value + (uint16_t)(status & FLAG_CARRY); // ORIGINAL BY MC
        
        carrycalc(result);
        zerocalc(result);
        overflowcalc(result, a, value);
        signcalc(result);
    }
#endif
    saveaccum(result);
}

// Assembly:
movb $0x1, 0x80f462(%rip)    # 0x821786
movzbl 0x80f45a(%rip), %eax    # 0x821785
leaq 0x8a7e(%rip), %rcx      # 0x1adb0
leaq -0x903(%rip), %rdx      # 0x11a36
cmpq %rdx, (%rcx,%rax,8)
je 0x12352
pushq %rax
movzwl 0x80f44b(%rip), %edi    # 0x821792
callq 0xe9ae
addq $0x8, %rsp
jmp 0x12358
movb 0x80f428(%rip), %al     # 0x821780
movzbl %al, %esi
movw %si, 0x80f434(%rip)     # 0x821796
movzbl 0x80f41a(%rip), %edi    # 0x821783
movl %edi, %eax
andl $0x1, %eax
movzbl 0x80f40b(%rip), %edx    # 0x821780
testb $0x8, %dil
jne 0x123eb
movzbl %al, %eax
movzwl %si, %ecx
movzwl %dx, %edx
addl %edx, %eax
addl %ecx, %eax
movl %edi, %esi
andb $-0xa, %sil
orb $0x1, %dil
cmpl $0x100, %eax            # imm = 0x100
movzbl %sil, %esi
movzbl %dil, %edi
cmovbl %esi, %edi
movl %edi, %esi
orb $0x2, %sil
andb $-0xb, %dil
movzbl %sil, %esi
movzbl %dil, %edi
testb %al, %al
cmovel %esi, %edi
xorl %eax, %edx
xorl %eax, %ecx
movl %edi, %esi
andb $-0x49, %sil
orb $0x40, %dil
testb %dl, %cl
movzbl %sil, %edx
movzbl %dil, %ecx
cmovnsl %edx, %ecx
movw %ax, 0x80f3bd(%rip)     # 0x821798
testb %al, %al
js 0x12487
andb $0x7f, %cl
jmp 0x1248a
movzwl %dx, %ecx
movzwl %si, %edx
addb %cl, %sil
addb %al, %sil
sete %sil
andb $-0x44, %dil
addb %sil, %sil
orb %dil, %sil
movl %ecx, %edi
andl $0xf, %edi
movl %edx, %r8d
andl $0xf, %r8d
movzwl %ax, %eax
addl %r8d, %eax
leal (%rax,%rdi), %r8d
addl %eax, %edi
addl $0x6, %edi
andl $0xf, %edi
orl $0x10, %edi
cmpw $0xa, %r8w
cmovbl %r8d, %edi
movl %ecx, %r8d
andl $-0x10, %r8d
movl %edx, %eax
andl $-0x10, %eax
addl %r8d, %eax
addl %edi, %eax
movw %ax, 0x80f351(%rip)     # 0x821798
xorl %eax, %ecx
xorl %eax, %edx
leal 0x40(%rsi), %edi
testb %cl, %dl
movzbl %sil, %ecx
movzbl %dil, %edx
cmovnsl %ecx, %edx
movl %edx, %ecx
andb $0x7e, %cl
orb $-0x80, %dl
testb %al, %al
movzbl %cl, %esi
movzbl %dl, %ecx
cmovnsl %esi, %ecx
cmpl $0xa0, %eax
jb 0x1248a
movzwl %ax, %eax
addl $0x60, %eax
movw %ax, 0x80f316(%rip)     # 0x821798
orb $0x1, %cl
jmp 0x1248a
orb $-0x80, %cl
movb %cl, 0x80f2f3(%rip)     # 0x821783
movb %al, 0x80f2ea(%rip)     # 0x821780
retq