// File: /workspace/github_c_makefile_star2_O0/juliuswwj[P]emch55x/core.c
// Function: load_obj
int load_obj(struct em8051 *aCPU, char *aFilename)
{
    FILE *f;    
    if (aFilename == 0 || aFilename[0] == 0)
        return -1;
    f = fopen(aFilename, "r");
    if (!f) return -1;
    if (fgetc(f) != ':')
    {
    	  fclose(f);
        return -2; // unsupported file format
    }
    while (!feof(f))
    {
        int recordlength;
        int address;
        int recordtype;
        int checksum;
        int i;
        recordlength = readbyte(f);
        address = readbyte(f);
        address <<= 8;
        address |= readbyte(f);
        recordtype = readbyte(f);
        if (recordtype == 1)
            return 0; // we're done
        if (recordtype != 0)
            return -3; // unsupported record type
        checksum = recordtype + recordlength + (address & 0xff) + (address >> 8); // final checksum = 1 + not(checksum)
        for (i = 0; i < recordlength; i++)
        {
            int data = readbyte(f);
            checksum += data;
            aCPU->mCodeMem[address + i] = data;
        }
        i = readbyte(f);
        checksum &= 0xff;
        checksum = 256 - checksum;
        if (i != (checksum & 0xff))
            return -4; // checksum failure
        while (fgetc(f) != ':' && !feof(f)) {} // skip newline        
    }
	  fclose(f);
    return -5;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x71f3
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x71ff
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x73ae
movq -0x18(%rbp), %rdi
leaq 0xbea7(%rip), %rsi      # 0x130b1
callq 0x4140
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x7226
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x73ae
movq -0x20(%rbp), %rdi
callq 0x40b0
cmpl $0x3a, %eax
je 0x7249
movq -0x20(%rbp), %rdi
callq 0x4070
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x73ae
jmp 0x724b
movq -0x20(%rbp), %rdi
callq 0x40f0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7265
jmp 0x739e
movq -0x20(%rbp), %rdi
callq 0x7160
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
callq 0x7160
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x7160
orl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x7160
movl %eax, -0x2c(%rbp)
cmpl $0x1, -0x2c(%rbp)
jne 0x72b3
movl $0x0, -0x4(%rbp)
jmp 0x73ae
cmpl $0x0, -0x2c(%rbp)
je 0x72c5
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x73ae
movl -0x2c(%rbp), %eax
addl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
andl $0xff, %ecx
addl %ecx, %eax
movl -0x28(%rbp), %ecx
sarl $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x7328
movq -0x20(%rbp), %rdi
callq 0x7160
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x38(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x72e8
movq -0x20(%rbp), %rdi
callq 0x7160
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x30(%rbp)
movl $0x100, %eax            # imm = 0x100
subl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
movl -0x30(%rbp), %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
je 0x7363
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x73ae
jmp 0x7365
movq -0x20(%rbp), %rdi
callq 0x40b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x3a, %ecx
movb %al, -0x39(%rbp)
je 0x738e
movq -0x20(%rbp), %rdi
callq 0x40f0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x7397
jmp 0x7399
jmp 0x7365
jmp 0x724b
movq -0x20(%rbp), %rdi
callq 0x4070
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)