// File: /workspace/github_c_makefile_star2_O0/juliuswwj[P]emch55x/opcodes.c
// Function: jbc_bitaddr_offset
static int jbc_bitaddr_offset(struct em8051 *aCPU)
{
    // "Note: when this instruction is used to test an output pin, the value used 
    // as the original data will be read from the output data latch, not the input pin"
    int address = OPERAND1;
    if (address > 0x7f)
    {
        int bit = address & 7;
        int bitmask = (1 << bit);
        int value;
        address &= 0xf8;        
        value = aCPU->mSFR[address - 0x80];
        
        if (value & bitmask)
        {
            aCPU->mSFR[address - 0x80] &= ~bitmask;
            PC += (signed char)OPERAND2 + 3;
            if (aCPU->sfrwrite)
                aCPU->sfrwrite(aCPU, address);
        }
        else
        {
            PC += 3;
        }
    }
    else
    {
        int bit = address & 7;
        int bitmask = (1 << bit);
        address >>= 3;
        address += 0x20;
        if (aCPU->mLowerData[address] & bitmask)
        {
            aCPU->mLowerData[address] &= ~bitmask;
            PC += (signed char)OPERAND2 + 3;
        }
        else
        {
            PC += 3;
        }
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rdx
movl 0x8(%rdx), %edx
subl $0x1, %edx
andl %edx, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0xc(%rbp)
cmpl $0x7f, -0xc(%rbp)
jle 0xc93e
movl -0xc(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0xf8, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl -0xc(%rbp), %ecx
subl $0x80, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
andl -0x14(%rbp), %eax
cmpl $0x0, %eax
je 0xc92c
movl -0x14(%rbp), %esi
xorl $-0x1, %esi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl -0xc(%rbp), %ecx
subl $0x80, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x2, %ecx
movq -0x8(%rbp), %rdx
movl 0x8(%rdx), %edx
subl $0x1, %edx
andl %edx, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %ecx
addl $0x3, %ecx
movq -0x8(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x1050(%rax)
je 0xc92a
movq -0x8(%rbp), %rax
movq 0x1050(%rax), %rax
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq *%rax
jmp 0xc939
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x3, %ecx
movl %ecx, 0x38(%rax)
jmp 0xc9db
movl -0xc(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x20(%rbp)
movl -0xc(%rbp), %eax
sarl $0x3, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addl $0x20, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl -0x20(%rbp), %eax
cmpl $0x0, %eax
je 0xc9cc
movl -0x20(%rbp), %esi
xorl $-0x1, %esi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x2, %ecx
movq -0x8(%rbp), %rdx
movl 0x8(%rdx), %edx
subl $0x1, %edx
andl %edx, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %ecx
addl $0x3, %ecx
movq -0x8(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
jmp 0xc9d9
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x3, %ecx
movl %ecx, 0x38(%rax)
jmp 0xc9db
movl $0x1, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)