LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/kbd.h
// Function: kbd_update
void kbd_update(kbd_t* kbd, uint32_t frame_time_us) {
    CHIPS_ASSERT(kbd);
    kbd->cur_time += frame_time_us;
    /* check for sticky keys that should be released */
    for (int i = 0; i < KBD_MAX_PRESSED_KEYS; i++) {
        key_state_t* k = &kbd->key_buffer[i];
        if (k->released) {
            /* properly handle cur_time wraparound */
            if ((kbd->cur_time < k->pressed_time) ||
                (kbd->cur_time > (k->pressed_time + kbd->sticky_time))) {
                k->mask = 0;
                k->key = 0;
                k->pressed_time = 0;
                k->released = false;
            }
        }
    }
    _kbd_update_scanout_masks(kbd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x47f8
jmp 0x4817
leaq 0x2063a(%rip), %rdi     # 0x24e39
leaq 0x20637(%rip), %rsi     # 0x24e3d
movl $0x139, %edx            # imm = 0x139
leaq 0x2077b(%rip), %rcx     # 0x24f8d
callq 0x3180
movl -0xc(%rbp), %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x0, -0x10(%rbp)
cmpl $0x4, -0x10(%rbp)
jge 0x48c4
movq -0x8(%rbp), %rax
addq $0x420, %rax            # imm = 0x420
movslq -0x10(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0x48b4
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x4889
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x8(%rbp), %rdx
movl 0x8(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x48b2
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x10(%rax)
jmp 0x48b4
jmp 0x48b6
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x482d
movq -0x8(%rbp), %rdi
callq 0x48e0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/kbd.h
// Function: kbd_update_scanout_masks
static void _kbd_update_scanout_masks(kbd_t* kbd) {
    for (int line = 0; line < KBD_MAX_LINES; line++) {
        kbd->scanout_column_masks[line] = _kbd_test_columns(kbd, (1<<line));
    }
    for (int col = 0; col < KBD_MAX_COLUMNS; col++) {
        kbd->scanout_line_masks[col] = _kbd_test_lines(kbd, (1<<col));
    }
    kbd->cur_column_mask = 0;
    kbd->cur_scanout_line_mask = 0;
    kbd->cur_line_mask = 0;
    kbd->cur_scanout_column_mask = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0xc, -0xc(%rbp)
jge 0x492d
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movzwl %ax, %esi
callq 0x22f00
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movw %dx, 0x480(%rax,%rcx,2)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x48f3
movl $0x0, -0x10(%rbp)
cmpl $0xc, -0x10(%rbp)
jge 0x496e
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movzwl %ax, %esi
callq 0x23070
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movw %dx, 0x498(%rax,%rcx,2)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4934
movq -0x8(%rbp), %rax
movw $0x0, 0x4b0(%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x4b2(%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x4b4(%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x4b6(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/kbd.h
// Function: kbd_key_down
void kbd_key_down(kbd_t* kbd, int key) {
    CHIPS_ASSERT(kbd && (key >= 0) && (key < KBD_MAX_KEYS));
    /* first check if the key is already in the key buffer,
       if yes, just update its pressed-frame and return,
       otherwise find a new, free keybuffer slot
    */
    for (int i = 0; i < KBD_MAX_PRESSED_KEYS; i++) {
        key_state_t* k = &kbd->key_buffer[i];
        if (k->key == key) {
            k->pressed_time = kbd->cur_time;
            _kbd_update_scanout_masks(kbd);
            return;
        }
    }
    for (int i = 0; i < KBD_MAX_PRESSED_KEYS; i++) {
        key_state_t* k = &kbd->key_buffer[i];
        if (0 == k->mask) {
            k->key = key;
            k->mask = kbd->key_masks[key];
            k->pressed_time = kbd->cur_time;
            k->released = false;
            _kbd_update_scanout_masks(kbd);
            return;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x49d7
cmpl $0x0, -0xc(%rbp)
jl 0x49d7
cmpl $0x100, -0xc(%rbp)      # imm = 0x100
jge 0x49d7
jmp 0x49f6
leaq 0x205d2(%rip), %rdi     # 0x24fb0
leaq 0x20458(%rip), %rsi     # 0x24e3d
movl $0x14d, %edx            # imm = 0x14D
leaq 0x205e2(%rip), %rcx     # 0x24fd3
callq 0x3180
movl $0x0, -0x10(%rbp)
cmpl $0x4, -0x10(%rbp)
jge 0x4a51
movq -0x8(%rbp), %rax
addq $0x420, %rax            # imm = 0x420
movslq -0x10(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x4a44
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0x48e0
jmp 0x4acd
jmp 0x4a46
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x49fd
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0x4acd
movq -0x8(%rbp), %rax
addq $0x420, %rax            # imm = 0x420
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpl 0x4(%rcx), %eax
jne 0x4ac0
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl 0x10(%rax,%rcx,4), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x10(%rax)
movq -0x8(%rbp), %rdi
callq 0x48e0
jmp 0x4acd
jmp 0x4ac2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4a58
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/kbd.h
// Function: kbd_key_up
void kbd_key_up(kbd_t* kbd, int key) {
    CHIPS_ASSERT(kbd && (key >= 0) && (key < KBD_MAX_KEYS));
    /* find the key in the keybuffer, just set released_frame */
    for (int i = 0; i < KBD_MAX_PRESSED_KEYS; i++) {
        key_state_t* k = &kbd->key_buffer[i];
        if (key == k->key) {
            k->released = true;
        }
    }
    _kbd_update_scanout_masks(kbd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x4b07
cmpl $0x0, -0xc(%rbp)
jl 0x4b07
cmpl $0x100, -0xc(%rbp)      # imm = 0x100
jge 0x4b07
jmp 0x4b26
leaq 0x204a2(%rip), %rdi     # 0x24fb0
leaq 0x20328(%rip), %rsi     # 0x24e3d
movl $0x168, %edx            # imm = 0x168
leaq 0x204d2(%rip), %rcx     # 0x24ff3
callq 0x3180
movl $0x0, -0x10(%rbp)
cmpl $0x4, -0x10(%rbp)
jge 0x4b6c
movq -0x8(%rbp), %rax
addq $0x420, %rax            # imm = 0x420
movslq -0x10(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x4b5f
movq -0x18(%rbp), %rax
movb $0x1, 0x10(%rax)
jmp 0x4b61
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4b2d
movq -0x8(%rbp), %rdi
callq 0x48e0
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/kbd.h
// Function: kbd_test_lines
uint16_t kbd_test_lines(kbd_t* kbd, uint16_t column_mask) {
    if (column_mask != kbd->cur_column_mask) {
        kbd->cur_column_mask = column_mask;
        kbd->cur_scanout_line_mask = 0;
        for (int col = 0; col < KBD_MAX_COLUMNS; col++) {
            if (column_mask & (1<<col)) {
                kbd->cur_scanout_line_mask |= kbd->scanout_line_masks[col];
            }
        }
    }
    return kbd->cur_scanout_line_mask;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movw %si, %ax
movq %rdi, -0x8(%rbp)
movw %ax, -0xa(%rbp)
movzwl -0xa(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x4b0(%rcx), %ecx
cmpl %ecx, %eax
je 0x4c15
movw -0xa(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x4b0(%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x4b2(%rax)
movl $0x0, -0x10(%rbp)
cmpl $0xc, -0x10(%rbp)
jge 0x4c13
movzwl -0xa(%rbp), %eax
movl -0x10(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x4c06
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzwl 0x498(%rax,%rcx,2), %edx
movq -0x8(%rbp), %rax
movzwl 0x4b2(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x4b2(%rax)
jmp 0x4c08
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4bc5
jmp 0x4c15
movq -0x8(%rbp), %rax
movw 0x4b2(%rax), %ax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/kbd.h
// Function: kbd_test_columns
uint16_t kbd_test_columns(kbd_t* kbd, uint16_t line_mask) {
    if (line_mask != kbd->cur_line_mask) {
        kbd->cur_line_mask = line_mask;
        kbd->cur_scanout_column_mask = 0;
        for (int line = 0; line < KBD_MAX_COLUMNS; line++) {
            if (line_mask & (1<<line)) {
                kbd->cur_scanout_column_mask |= kbd->scanout_column_masks[line];
            }
        }
    }
    return kbd->cur_scanout_column_mask;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movw %si, %ax
movq %rdi, -0x8(%rbp)
movw %ax, -0xa(%rbp)
movzwl -0xa(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x4b4(%rcx), %ecx
cmpl %ecx, %eax
je 0x4cc5
movw -0xa(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x4b4(%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x4b6(%rax)
movl $0x0, -0x10(%rbp)
cmpl $0xc, -0x10(%rbp)
jge 0x4cc3
movzwl -0xa(%rbp), %eax
movl -0x10(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x4cb6
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzwl 0x480(%rax,%rcx,2), %edx
movq -0x8(%rbp), %rax
movzwl 0x4b6(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x4b6(%rax)
jmp 0x4cb8
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4c75
jmp 0x4cc5
movq -0x8(%rbp), %rax
movw 0x4b6(%rax), %ax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/mem.h
// Function: mem_init
void mem_init(mem_t* m) {
    CHIPS_ASSERT(m);
    memset(m, 0, sizeof(*m));
    memset(&m->unmapped_page, 0xFF, sizeof(m->unmapped_page));
    mem_unmap_all(m);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x4d95
jmp 0x4db4
leaq 0x20275(%rip), %rdi     # 0x25011
leaq 0x20270(%rip), %rsi     # 0x25013
movl $0x10e, %edx            # imm = 0x10E
leaq 0x2026e(%rip), %rcx     # 0x2501d
callq 0x3180
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x1c00, %edx           # imm = 0x1C00
callq 0x31c0
movq -0x8(%rbp), %rdi
addq $0x1400, %rdi           # imm = 0x1400
movl $0xff, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x31c0
movq -0x8(%rbp), %rdi
callq 0x3220
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/mem.h
// Function: mem_unmap_all
void mem_unmap_all(mem_t* m) {
    for (int layer_index = 0; layer_index < MEM_NUM_LAYERS; layer_index++) {
        for (int page_index = 0; page_index < MEM_NUM_PAGES; page_index++) {
            mem_page_t* page = &m->layers[layer_index][page_index];
            page->read_ptr = 0; 
            page->write_ptr = 0;
        }
    }
    for (int page_index = 0; page_index < MEM_NUM_PAGES; page_index++) {
        _mem_update_page_table(m, page_index);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x4, -0xc(%rbp)
jge 0x4e63
movl $0x0, -0x10(%rbp)
cmpl $0x40, -0x10(%rbp)
jge 0x4e56
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4e10
jmp 0x4e58
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x4e03
movl $0x0, -0x1c(%rbp)
cmpl $0x40, -0x1c(%rbp)
jge 0x4e87
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x52d0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4e6a
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/mem.h
// Function: mem_unmap_layer
void mem_unmap_layer(mem_t* m, int layer) {
    CHIPS_ASSERT(m);
    CHIPS_ASSERT((layer >= 0) && (layer < MEM_NUM_LAYERS));
    for (int page_index = 0; page_index < MEM_NUM_PAGES; page_index++) {
        mem_page_t* page = &m->layers[layer][page_index];
        page->read_ptr = 0; 
        page->write_ptr = 0;
        _mem_update_page_table(m, page_index);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x5218
jmp 0x5237
leaq 0x1fdf2(%rip), %rdi     # 0x25011
leaq 0x1fded(%rip), %rsi     # 0x25013
movl $0x152, %edx            # imm = 0x152
leaq 0x1fee8(%rip), %rcx     # 0x2511a
callq 0x3180
cmpl $0x0, -0xc(%rbp)
jl 0x5245
cmpl $0x4, -0xc(%rbp)
jge 0x5245
jmp 0x5264
leaq 0x1fc88(%rip), %rdi     # 0x24ed4
leaq 0x1fdc0(%rip), %rsi     # 0x25013
movl $0x153, %edx            # imm = 0x153
leaq 0x1febb(%rip), %rcx     # 0x2511a
callq 0x3180
movl $0x0, -0x10(%rbp)
cmpl $0x40, -0x10(%rbp)
jge 0x52bd
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x52d0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x526b
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/mem.h
// Function: mem_update_page_table
static void _mem_update_page_table(mem_t* m, int page_index) {
    /* find highest priority layer which maps this memory page */
    int layer_index;
    for (layer_index = 0; layer_index < MEM_NUM_LAYERS; layer_index++) {
        if (m->layers[layer_index][page_index].read_ptr) {
            /* found highest priority layer with valid mapping */
            break;
        }
    }
    if (layer_index != MEM_NUM_LAYERS) { 
        /* found a valid mapping */
        m->page_table[page_index] = m->layers[layer_index][page_index];
    }
    else {
        /* no mapping exists for this page, set to special 'unmapped page' */
        m->page_table[page_index].read_ptr = m->unmapped_page;
        m->page_table[page_index].write_ptr = m->junk_page;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
cmpl $0x4, -0x10(%rbp)
jge 0x5317
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x530a
jmp 0x5317
jmp 0x530c
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x52e2
cmpl $0x4, -0x10(%rbp)
je 0x535c
movq -0x8(%rbp), %rax
addq $0x1000, %rax           # imm = 0x1000
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x10(%rbp), %rdx
shlq $0xa, %rdx
addq %rdx, %rcx
movslq -0xc(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x53a3
movq -0x8(%rbp), %rcx
addq $0x1400, %rcx           # imm = 0x1400
movq -0x8(%rbp), %rax
addq $0x1000, %rax           # imm = 0x1000
movslq -0xc(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rcx
addq $0x1800, %rcx           # imm = 0x1800
movq -0x8(%rbp), %rax
addq $0x1000, %rax           # imm = 0x1000
movslq -0xc(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/mem.h
// Function: mem_layer_rd
uint8_t mem_layer_rd(mem_t* mem, int layer, uint16_t addr) {
    CHIPS_ASSERT((layer >= 0) && (layer < MEM_NUM_LAYERS));
    if (mem->layers[layer][addr>>MEM_PAGE_SHIFT].read_ptr) {
        return mem->layers[layer][addr>>MEM_PAGE_SHIFT].read_ptr[addr&MEM_PAGE_MASK];
    }
    else {
        return 0xFF;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movw %ax, -0x16(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x5504
cmpl $0x4, -0x14(%rbp)
jge 0x5504
jmp 0x5523
leaq 0x1f9c9(%rip), %rdi     # 0x24ed4
leaq 0x1fb01(%rip), %rsi     # 0x25013
movl $0x175, %edx            # imm = 0x175
leaq 0x1fc47(%rip), %rcx     # 0x25165
callq 0x3180
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movzwl -0x16(%rbp), %ecx
sarl $0xa, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x5581
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movzwl -0x16(%rbp), %ecx
sarl $0xa, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movzwl -0x16(%rbp), %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x5585
movb $-0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/z80.h
// Function: z80_init
void z80_init(z80_t* cpu, const z80_desc_t* desc) {
    CHIPS_ASSERT(_FA == 0);
    CHIPS_ASSERT(cpu && desc);
    CHIPS_ASSERT(desc->tick_cb);
    memset(cpu, 0, sizeof(*cpu));
    z80_reset(cpu);
    cpu->tick_cb = desc->tick_cb;
    cpu->user_data = desc->user_data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x6230
cmpq $0x0, -0x10(%rbp)
je 0x6230
jmp 0x624f
leaq 0x1ef8e(%rip), %rdi     # 0x251c5
leaq 0x1ef93(%rip), %rsi     # 0x251d1
movl $0x2c7, %edx            # imm = 0x2C7
leaq 0x1ef91(%rip), %rcx     # 0x251db
callq 0x3180
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x625b
jmp 0x627a
leaq 0x1efa4(%rip), %rdi     # 0x25206
leaq 0x1ef68(%rip), %rsi     # 0x251d1
movl $0x2c8, %edx            # imm = 0x2C8
leaq 0x1ef66(%rip), %rcx     # 0x251db
callq 0x3180
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x31c0
movq -0x8(%rbp), %rdi
callq 0x3120
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/z80.h
// Function: z80_reset
void z80_reset(z80_t* cpu) {
    CHIPS_ASSERT(cpu);
    /* set AF to 0xFFFF, all other regs are undefined, set to 0xFFFF to */
    cpu->bc_de_hl_fa = cpu->bc_de_hl_fa_ = 0xFFFFFFFFFFFFFFFFULL;
    z80_set_ix(cpu, 0xFFFF);
    z80_set_iy(cpu, 0xFFFF);
    z80_set_wz(cpu, 0xFFFF);
    /* set SP to 0xFFFF, PC to 0x0000 */
    z80_set_sp(cpu, 0xFFFF);
    z80_set_pc(cpu, 0x0000);
    /* IFF1 and IFF2 are off */
    z80_set_iff1(cpu, false);
    z80_set_iff2(cpu, false);
    /* IM is set to 0 */
    z80_set_im(cpu, 0);
    /* after power-on or reset, R is set to 0 (see z80-documented.pdf) */
    z80_set_ir(cpu, 0x0000);
    cpu->im_ir_pc_bits &= ~(_BIT_EI|_BIT_USE_IX|_BIT_USE_IY);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x62d5
jmp 0x62f4
leaq 0x1ef38(%rip), %rdi     # 0x25214
leaq 0x1eeee(%rip), %rsi     # 0x251d1
movl $0x2d0, %edx            # imm = 0x2D0
leaq 0x1ef29(%rip), %rcx     # 0x25218
callq 0x3180
movq -0x8(%rbp), %rax
movq $-0x1, 0x10(%rax)
movq -0x8(%rbp), %rax
movq $-0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x3310
movq -0x8(%rbp), %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x30f0
movq -0x8(%rbp), %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x3250
movq -0x8(%rbp), %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x3540
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x30d0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3570
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x32d0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3050
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3300
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rcx
andq $-0x14, %rcx
movq %rcx, 0x20(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/z80.h
// Function: z80_map_regs
static inline uint64_t _z80_map_regs(uint64_t r0, uint64_t r1, uint64_t r2) {
    uint64_t ws = r0;
    if (r2 & _BIT_USE_IX) {
        ws = (ws & ~(0xFFFFULL<<_HL)) | (((r1>>_IX)<<_HL) & (0xFFFFULL<<_HL));
    }
    else if (r2 & _BIT_USE_IY) {
        ws = (ws & ~(0xFFFFULL<<_HL)) | (((r1>>_IY)<<_HL) & (0xFFFFULL<<_HL));
    }
    return ws;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x20216
movabsq $-0xffff0001, %rax      # imm = 0xFFFFFFFF0000FFFF
andq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
shrq $0x20, %rcx
shlq $0x10, %rcx
movabsq $0xffff0000, %rdx       # imm = 0xFFFF0000
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x20254
movq -0x18(%rbp), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x20252
movabsq $-0xffff0001, %rax      # imm = 0xFFFFFFFF0000FFFF
andq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
shrq $0x10, %rcx
shlq $0x10, %rcx
movabsq $0xffff0000, %rdx       # imm = 0xFFFF0000
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x20254
movq -0x20(%rbp), %rax
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/z80.h
// Function: z80_flush_r0
static inline uint64_t _z80_flush_r0(uint64_t ws, uint64_t r0, uint64_t map_bits) {
    if (map_bits & _BITS_USE_IXIY) {
        r0 = (r0 & (0xFFFFULL<<_HL)) | (ws & ~(0xFFFFULL<<_HL));
    }
    else {
        r0 = ws;
    }
    return r0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
andq $0x3, %rax
cmpq $0x0, %rax
je 0x202a3
movabsq $0xffff0000, %rax       # imm = 0xFFFF0000
andq -0x10(%rbp), %rax
movabsq $-0xffff0001, %rcx      # imm = 0xFFFFFFFF0000FFFF
andq -0x8(%rbp), %rcx
orq %rcx, %rax
movq %rax, -0x10(%rbp)
jmp 0x202ab
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/z80.h
// Function: z80_flush_r1
static inline uint64_t _z80_flush_r1(uint64_t ws, uint64_t r1, uint64_t map_bits) {
    if (map_bits & _BIT_USE_IX) {
        r1 = (r1 & ~(0xFFFFULL<<_IX)) | (((ws>>_HL)<<_IX) & (0xFFFFULL<<_IX));
    }
    else if (map_bits & _BIT_USE_IY) {
        r1 = (r1 & ~(0xFFFFULL<<_IY)) | (((ws>>_HL)<<_IY) & (0xFFFFULL<<_IY));
    }
    return r1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x2030e
movabsq $-0xffff00000001, %rax  # imm = 0xFFFF0000FFFFFFFF
andq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
shrq $0x10, %rcx
shlq $0x20, %rcx
movabsq $0xffff00000000, %rdx   # imm = 0xFFFF00000000
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x10(%rbp)
jmp 0x2034c
movq -0x18(%rbp), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x2034a
movabsq $-0xffff0001, %rax      # imm = 0xFFFFFFFF0000FFFF
andq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
shrq $0x10, %rcx
shlq $0x10, %rcx
movabsq $0xffff0000, %rdx       # imm = 0xFFFF0000
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x10(%rbp)
jmp 0x2034c
movq -0x10(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/z80.h
// Function: z80_daa
static inline uint64_t _z80_daa(uint64_t ws) {
    uint8_t a = _G8(ws,_A);
    uint8_t v = a;
    uint8_t f = _G8(ws,_F);
    if (f & Z80_NF) {
        if (((a & 0xF)>0x9) || (f & Z80_HF)) {
            v -= 0x06;
        }
        if ((a > 0x99) || (f & Z80_CF)) {
            v -= 0x60;
        }
    }
    else {
        if (((a & 0xF)>0x9) || (f & Z80_HF)) {
            v += 0x06;
        }
        if ((a > 0x99) || (f & Z80_CF)) {
            v += 0x60;
        }
    }
    f &= Z80_CF|Z80_NF;
    f |= (a>0x99) ? Z80_CF : 0;
    f |= (a ^ v) & Z80_HF;
    f |= _z80_szp[v];
    _S8(ws,_A,v);
    _S8(ws,_F,f);
    return ws;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
shrq $0x0, %rax
andq $0xff, %rax
movb %al, -0x9(%rbp)
movb -0x9(%rbp), %al
movb %al, -0xa(%rbp)
movq -0x8(%rbp), %rax
shrq $0x8, %rax
andq $0xff, %rax
movb %al, -0xb(%rbp)
movzbl -0xb(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x203e1
movzbl -0x9(%rbp), %eax
andl $0xf, %eax
cmpl $0x9, %eax
jg 0x203b4
movzbl -0xb(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x203be
movzbl -0xa(%rbp), %eax
subl $0x6, %eax
movb %al, -0xa(%rbp)
movzbl -0x9(%rbp), %eax
cmpl $0x99, %eax
jg 0x203d5
movzbl -0xb(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x203df
movzbl -0xa(%rbp), %eax
subl $0x60, %eax
movb %al, -0xa(%rbp)
jmp 0x20426
movzbl -0x9(%rbp), %eax
andl $0xf, %eax
cmpl $0x9, %eax
jg 0x203f9
movzbl -0xb(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x20403
movzbl -0xa(%rbp), %eax
addl $0x6, %eax
movb %al, -0xa(%rbp)
movzbl -0x9(%rbp), %eax
cmpl $0x99, %eax
jg 0x2041a
movzbl -0xb(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x20424
movzbl -0xa(%rbp), %eax
addl $0x60, %eax
movb %al, -0xa(%rbp)
jmp 0x20426
movzbl -0xb(%rbp), %eax
andl $0x3, %eax
movb %al, -0xb(%rbp)
movzbl -0x9(%rbp), %edx
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x99, %edx
cmovgl %eax, %ecx
movzbl -0xb(%rbp), %eax
orl %ecx, %eax
movb %al, -0xb(%rbp)
movzbl -0x9(%rbp), %ecx
movzbl -0xa(%rbp), %eax
xorl %eax, %ecx
andl $0x10, %ecx
movzbl -0xb(%rbp), %eax
orl %ecx, %eax
movb %al, -0xb(%rbp)
movzbl -0xa(%rbp), %eax
movl %eax, %ecx
leaq 0x8e60(%rip), %rax      # 0x292d0
movzbl (%rax,%rcx), %ecx
movzbl -0xb(%rbp), %eax
orl %ecx, %eax
movb %al, -0xb(%rbp)
movq -0x8(%rbp), %rax
andq $-0x100, %rax
movzbl -0xa(%rbp), %ecx
andq $0xff, %rcx
shlq $0x0, %rcx
orq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
andq $-0xff01, %rax          # imm = 0xFFFF00FF
movzbl -0xb(%rbp), %ecx
andq $0xff, %rcx
shlq $0x8, %rcx
orq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/zx.h
// Function: zx_init_memory_map
static void _zx_init_memory_map(zx_t* sys) {
    mem_init(&sys->mem);
    if (sys->type == ZX_TYPE_128) {
        mem_map_ram(&sys->mem, 0, 0x4000, 0x4000, sys->ram[5]);
        mem_map_ram(&sys->mem, 0, 0x8000, 0x4000, sys->ram[2]);
        mem_map_ram(&sys->mem, 0, 0xC000, 0x4000, sys->ram[0]);
        mem_map_rom(&sys->mem, 0, 0x0000, 0x4000, sys->rom[0]);
    }
    else {
        mem_map_ram(&sys->mem, 0, 0x4000, 0x4000, sys->ram[0]);
        mem_map_ram(&sys->mem, 0, 0x8000, 0x4000, sys->ram[1]);
        mem_map_ram(&sys->mem, 0, 0xC000, 0x4000, sys->ram[2]);
        mem_map_rom(&sys->mem, 0, 0x0000, 0x4000, sys->rom[0]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
callq 0x3240
movq -0x8(%rbp), %rax
cmpl $0x1, 0x1114(%rax)
jne 0x21026
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x4230, %r8            # imm = 0x4230
addq $0x14000, %r8           # imm = 0x14000
xorl %esi, %esi
movl $0x4000, %ecx           # imm = 0x4000
movl %ecx, %edx
callq 0x3400
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x4230, %r8            # imm = 0x4230
addq $0x8000, %r8            # imm = 0x8000
xorl %esi, %esi
movl $0x8000, %edx           # imm = 0x8000
movl $0x4000, %ecx           # imm = 0x4000
callq 0x3400
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x4230, %r8            # imm = 0x4230
xorl %esi, %esi
movl $0xc000, %edx           # imm = 0xC000
movl $0x4000, %ecx           # imm = 0x4000
callq 0x3400
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x24230, %r8           # imm = 0x24230
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
movl %edx, %esi
callq 0x3080
jmp 0x210ca
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x4230, %r8            # imm = 0x4230
xorl %esi, %esi
movl $0x4000, %ecx           # imm = 0x4000
movl %ecx, %edx
callq 0x3400
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x4230, %r8            # imm = 0x4230
addq $0x4000, %r8            # imm = 0x4000
xorl %esi, %esi
movl $0x8000, %edx           # imm = 0x8000
movl $0x4000, %ecx           # imm = 0x4000
callq 0x3400
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x4230, %r8            # imm = 0x4230
addq $0x8000, %r8            # imm = 0x8000
xorl %esi, %esi
movl $0xc000, %edx           # imm = 0xC000
movl $0x4000, %ecx           # imm = 0x4000
callq 0x3400
movq -0x8(%rbp), %rdi
addq $0x1610, %rdi           # imm = 0x1610
movq -0x8(%rbp), %r8
addq $0x24230, %r8           # imm = 0x24230
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
movl %edx, %esi
callq 0x3080
addq $0x10, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/zx.h
// Function: zx_reset
void zx_reset(zx_t* sys) {
    CHIPS_ASSERT(sys && sys->valid);
    z80_reset(&sys->cpu);
    beeper_reset(&sys->beeper);
    if (sys->type == ZX_TYPE_128) {
        ay38910_reset(&sys->ay);
    }
    sys->memory_paging_disabled = false;
    sys->kbd_joymask = 0;
    sys->joy_joymask = 0;
    sys->last_fe_out = 0;
    sys->scanline_counter = sys->scanline_period;
    sys->scanline_y = 0;
    sys->blink_counter = 0;
    if (sys->type == ZX_TYPE_48K) {
        sys->display_ram_bank = 0;
    }
    else {
        sys->display_ram_bank = 5;
    }
    _zx_init_memory_map(sys);
    z80_set_pc(&sys->cpu, 0x0000);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x21422
movq -0x8(%rbp), %rax
testb $0x1, 0x1110(%rax)
je 0x21422
jmp 0x21441
leaq 0x3f74(%rip), %rdi      # 0x2539d
leaq 0x3e3a(%rip), %rsi      # 0x2526a
movl $0x133, %edx            # imm = 0x133
leaq 0x3f8b(%rip), %rcx      # 0x253c7
callq 0x3180
movq -0x8(%rbp), %rdi
callq 0x3120
movq -0x8(%rbp), %rdi
addq $0x50, %rdi
callq 0x3230
movq -0x8(%rbp), %rax
cmpl $0x1, 0x1114(%rax)
jne 0x21474
movq -0x8(%rbp), %rdi
addq $0x870, %rdi            # imm = 0x870
callq 0x3530
movq -0x8(%rbp), %rax
movb $0x0, 0x111c(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x111d(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x111e(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x1125(%rax)
movq -0x8(%rbp), %rax
movl 0x1130(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1134(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x1138(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x1126(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1114(%rax)
jne 0x214ea
movq -0x8(%rbp), %rax
movl $0x0, 0x113c(%rax)
jmp 0x214f8
movq -0x8(%rbp), %rax
movl $0x5, 0x113c(%rax)
movq -0x8(%rbp), %rdi
callq 0x20f50
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x30d0
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/zx.h
// Function: zx_exec
void zx_exec(zx_t* sys, uint32_t micro_seconds) {
    CHIPS_ASSERT(sys && sys->valid);
    uint32_t ticks_to_run = clk_ticks_to_run(&sys->clk, micro_seconds);
    uint32_t ticks_executed = z80_exec(&sys->cpu, ticks_to_run);
    clk_ticks_executed(&sys->clk, ticks_executed);
    kbd_update(&sys->kbd, micro_seconds);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x21545
movq -0x8(%rbp), %rax
testb $0x1, 0x1110(%rax)
je 0x21545
jmp 0x21564
leaq 0x3e51(%rip), %rdi      # 0x2539d
leaq 0x3d17(%rip), %rsi      # 0x2526a
movl $0x14b, %edx            # imm = 0x14B
leaq 0x3e7e(%rip), %rcx      # 0x253dd
callq 0x3180
movq -0x8(%rbp), %rdi
addq $0x1148, %rdi           # imm = 0x1148
movl -0xc(%rbp), %esi
callq 0x3170
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x3040
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rdi
addq $0x1148, %rdi           # imm = 0x1148
movl -0x14(%rbp), %esi
callq 0x3410
movq -0x8(%rbp), %rdi
addq $0x1158, %rdi           # imm = 0x1158
movl -0xc(%rbp), %esi
callq 0x3440
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: retro_set_environment
void retro_set_environment(retro_environment_t const cb) {
    zx48k.env_cb = cb;

    bool yes = true;
    cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &yes);

    struct retro_get_proc_address_interface get_proc_if = {zx48k_get_proc};
    cb(RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK, &get_proc_if);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, 0x8b0a1(%rip)     # 0xad668
movb $0x1, -0x9(%rbp)
movl $0x12, %edi
leaq -0x9(%rbp), %rsi
callq *-0x8(%rbp)
movq 0x6672(%rip), %rax      # 0x28c50
movq %rax, -0x18(%rbp)
movl $0x21, %edi
leaq -0x18(%rbp), %rsi
callq *-0x8(%rbp)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: retro_init
void retro_init() {
    zx48k.log_cb = dummy_log;

    struct retro_log_callback log;

    if (zx48k.env_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) {
        zx48k.log_cb = log.log;
    }

    zx48k_reset();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0x41(%rip), %rax        # 0x22720
movq %rax, 0x8af7a(%rip)     # 0xad660
movl $0x1b, %edi
leaq -0x8(%rbp), %rsi
callq *0x8af73(%rip)          # 0xad668
testb $0x1, %al
jne 0x226fb
jmp 0x22706
movq -0x8(%rbp), %rax
movq %rax, 0x8af5a(%rip)     # 0xad660
callq 0x22730
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: zx48k_reset
static void zx48k_reset(void) {
    zx_init(&zx48k.zx, &(zx_desc_t) {
        .type = ZX_TYPE_48K,
        .joystick_type = ZX_JOYSTICKTYPE_KEMPSTON,
        .pixel_buffer = zx48k.pixel_buffer,
        .pixel_buffer_size = sizeof(zx48k.pixel_buffer),
        .user_data = NULL,
        .audio_cb = zx48k_audio_cb,
        .audio_num_samples = ZX_DEFAULT_AUDIO_SAMPLES,
        .audio_sample_rate = 44100,
        .rom_zx48k = rom,
        .rom_zx48k_size = rom_len
    });

    /* Keep these around for the video callback */
    zx48k.width = zx_display_width(&zx48k.zx);
    zx48k.height = zx_display_height(&zx48k.zx);

    /* Reset the keyboard and register our own keys */
    zx48k.key_states = 0;
    kbd_init(&zx48k.zx.kbd, 1);

    int code = 128;

    for (int col = 0; col < 8; col++) {
        for (int row = 0; row < 5; row++, code++) {
            kbd_register_key(&zx48k.zx.kbd, code, col, row, 0);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x60(%rbp)
movl $0x1, -0x5c(%rbp)
leaq 0xacc3(%rip), %rax      # 0x2d410
addq $0x30238, %rax          # imm = 0x30238
movq %rax, -0x58(%rbp)
movl $0x50000, -0x50(%rbp)   # imm = 0x50000
movq $0x0, -0x48(%rbp)
leaq 0x1403(%rip), %rax      # 0x23b70
movq %rax, -0x40(%rbp)
movl $0x80, -0x38(%rbp)
movl $0xac44, -0x34(%rbp)    # imm = 0xAC44
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
leaq 0x6c6a(%rip), %rax      # 0x29400
movq %rax, -0x28(%rbp)
movl $0x4000, -0x20(%rbp)    # imm = 0x4000
movq $0x0, -0x18(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x0, -0x8(%rbp)
movl $0x0, -0x4(%rbp)
leaq 0xac4a(%rip), %rdi      # 0x2d410
leaq -0x60(%rbp), %rsi
callq 0x3130
leaq 0xac3a(%rip), %rdi      # 0x2d410
callq 0x31f0
movl %eax, 0x8ae67(%rip)     # 0xad648
leaq 0xac28(%rip), %rdi      # 0x2d410
callq 0x32f0
movl %eax, 0x8ae59(%rip)     # 0xad64c
movq $0x0, 0x3ae42(%rip) # 0x5d640
leaq 0xac0b(%rip), %rdi      # 0x2d410
addq $0x1158, %rdi           # imm = 0x1158
movl $0x1, %esi
callq 0x32a0
movl $0x80, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
cmpl $0x8, -0x68(%rbp)
jge 0x22877
movl $0x0, -0x6c(%rbp)
cmpl $0x5, -0x6c(%rbp)
jge 0x2286a
movl -0x64(%rbp), %esi
movl -0x68(%rbp), %edx
movl -0x6c(%rbp), %ecx
leaq 0xabc9(%rip), %rdi      # 0x2d410
addq $0x1158, %rdi           # imm = 0x1158
xorl %r8d, %r8d
callq 0x3350
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x22831
jmp 0x2286c
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x22824
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: retro_deinit
void retro_deinit(void) {
    if (zx48k.data != NULL) {
        free((void*)zx48k.data);
        zx48k.data = NULL;
        zx48k.size = 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpq $0x0, 0x8adc4(%rip)     # 0xad650
je 0x228b0
movq 0x8adbb(%rip), %rdi     # 0xad650
callq 0x3060
movq $0x0, 0x8adab(%rip) # 0xad650
movq $0x0, 0x8ada8(%rip) # 0xad658
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: retro_get_system_info
void retro_get_system_info(struct retro_system_info* const info) {
    info->library_name = "zx48k";
    info->library_version = "0.0.1";
    info->need_fullpath = false;
    info->block_extract = false;
    info->valid_extensions = "z80";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
leaq 0x2c26(%rip), %rcx      # 0x25509
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
leaq 0x2c1e(%rip), %rcx      # 0x2550f
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x18(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x19(%rax)
movq -0x8(%rbp), %rax
leaq 0x2c05(%rip), %rcx      # 0x25515
movq %rcx, 0x10(%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: retro_get_system_av_info
void retro_get_system_av_info(struct retro_system_av_info* const info) {
    info->geometry.base_width = zx48k.width;
    info->geometry.base_height = zx48k.height;
    info->geometry.max_width = zx48k.width;
    info->geometry.max_height = zx48k.height;
    info->geometry.aspect_ratio = 0.0f;
    info->timing.fps = ZX48K_FRAMES_PER_SECOND;
    info->timing.sample_rate = 44100.0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl 0x8ad1a(%rip), %ecx     # 0xad648
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl 0x8ad12(%rip), %ecx     # 0xad64c
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movl 0x8ad01(%rip), %ecx     # 0xad648
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movl 0x8acf8(%rip), %ecx     # 0xad64c
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x10(%rax)
movq -0x8(%rbp), %rax
movsd 0x2325(%rip), %xmm0     # 0x24c98
movsd %xmm0, 0x18(%rax)
movq -0x8(%rbp), %rax
movsd 0x230c(%rip), %xmm0     # 0x24c90
movsd %xmm0, 0x20(%rax)
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: retro_load_game
bool retro_load_game(struct retro_game_info const* const info) {
    if (info == NULL) {
        return false;
    }

    enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888;

    if (!zx48k.env_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
        zx48k.log_cb( RETRO_LOG_ERROR, "XRGB8888 is not supported\n" );
        return false;
    }

    bool const ok = zx48k_load(info->data, info->size);

    struct retro_memory_descriptor desc[4] = {
        {RETRO_MEMDESC_CONST,      zx48k.zx.rom[0], 0, 0x0000, 0, 0, 0x4000, NULL},
        {RETRO_MEMDESC_SYSTEM_RAM, zx48k.zx.ram[0], 0, 0x4000, 0, 0, 0x4000, NULL},
        {RETRO_MEMDESC_SYSTEM_RAM, zx48k.zx.ram[1], 0, 0x8000, 0, 0, 0x4000, NULL},
        {RETRO_MEMDESC_SYSTEM_RAM, zx48k.zx.ram[2], 0, 0xc000, 0, 0, 0x4000, NULL}
    };

    struct retro_memory_map memory_map = {desc, 4};
    zx48k.env_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &memory_map);

    return ok;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x22a0f
movb $0x0, -0x1(%rbp)
jmp 0x22aa7
movl $0x1, -0x14(%rbp)
movl $0xa, %edi
leaq -0x14(%rbp), %rsi
callq *0x8ac43(%rip)          # 0xad668
testb $0x1, %al
jne 0x22a43
movl $0x3, %edi
leaq 0x2b0b(%rip), %rsi      # 0x25540
movb $0x0, %al
callq *0x8ac23(%rip)          # 0xad660
movb $0x0, -0x1(%rbp)
jmp 0x22aa7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x22ac0
andb $0x1, %al
movb %al, -0x15(%rbp)
leaq -0x120(%rbp), %rdi
leaq 0x61f5(%rip), %rsi      # 0x28c60
movl $0x100, %edx            # imm = 0x100
callq 0x32e0
leaq -0x120(%rbp), %rax
movq %rax, -0x130(%rbp)
movl $0x4, -0x128(%rbp)
movl $0x10024, %edi          # imm = 0x10024
leaq -0x130(%rbp), %rsi
callq *0x8abc9(%rip)          # 0xad668
movb -0x15(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: zx48k_load
static bool zx48k_load(void const* const data, size_t const size) {
    if (zx48k.data != NULL) {
        free((void*)zx48k.data);
        zx48k.data = NULL;
        zx48k.size = 0;
    }

    bool ok = true;

    if (data != NULL) {
        if (!zx_quickload(&zx48k.zx, data, size)) {
            return false;
        }

        /* Copy the content since the frontend won't keep it around */
        void* copy = malloc(size);

        if (copy == NULL) {
            zx48k.log_cb(RETRO_LOG_ERROR, "Error allocating memory for content, retro_reset won't reload the content");
            return false;
        }

        memcpy(copy, data, size);
        zx48k.data = copy;
        zx48k.size = size;
    }
    else {
        zx48k_reset();
    }

    return ok;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, 0x8ab78(%rip)     # 0xad650
je 0x22afc
movq 0x8ab6f(%rip), %rdi     # 0xad650
callq 0x3060
movq $0x0, 0x8ab5f(%rip) # 0xad650
movq $0x0, 0x8ab5c(%rip) # 0xad658
movb $0x1, -0x19(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x22b7e
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xa8f8(%rip), %rdi      # 0x2d410
callq 0x3270
testb $0x1, %al
jne 0x22b27
movb $0x0, -0x1(%rbp)
jmp 0x22b8b
movq -0x18(%rbp), %rdi
callq 0x3330
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x22b55
movl $0x3, %edi
leaq 0x2bef(%rip), %rsi      # 0x25736
movb $0x0, %al
callq *0x8ab11(%rip)          # 0xad660
movb $0x0, -0x1(%rbp)
jmp 0x22b8b
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x32e0
movq -0x28(%rbp), %rax
movq %rax, 0x8aadf(%rip)     # 0xad650
movq -0x18(%rbp), %rax
movq %rax, 0x8aadc(%rip)     # 0xad658
jmp 0x22b83
callq 0x22730
movb -0x19(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: main_region_peek
static uint8_t main_region_peek(uint64_t address) {
    switch (address >> 14) {
        case 0: return zx48k.zx.rom[0][address & 0x3fff];
        case 1: return zx48k.zx.ram[0][address & 0x3fff];
        case 2: return zx48k.zx.ram[1][address & 0x3fff];
        case 3: return zx48k.zx.ram[2][address & 0x3fff];
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
shrq $0xe, %rax
movq %rax, -0x18(%rbp)
subq $0x3, %rax
ja 0x23a9a
movq -0x18(%rbp), %rax
leaq 0xf2f(%rip), %rcx       # 0x24948
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x99dc(%rip), %rax      # 0x2d410
movb 0x24230(%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x23a9e
movq -0x10(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x99be(%rip), %rax      # 0x2d410
movb 0x4230(%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x23a9e
movq -0x10(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x99a0(%rip), %rax      # 0x2d410
movb 0x8230(%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x23a9e
movq -0x10(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x9982(%rip), %rax      # 0x2d410
movb 0xc230(%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x23a9e
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/leiradel[P]zx48k-libretro/src/main.c
// Function: main_region_poke
static int main_region_poke(uint64_t address, uint8_t value) {
    switch (address >> 14) {
        case 0: zx48k.zx.rom[0][address & 0x3fff] = value; break;
        case 1: zx48k.zx.ram[0][address & 0x3fff] = value; break;
        case 2: zx48k.zx.ram[1][address & 0x3fff] = value; break;
        case 3: zx48k.zx.ram[2][address & 0x3fff] = value; break;
    }

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
shrq $0xe, %rax
movq %rax, -0x18(%rbp)
subq $0x3, %rax
ja 0x23b5e
movq -0x18(%rbp), %rax
leaq 0xe79(%rip), %rcx       # 0x24958
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb -0x9(%rbp), %dl
movq -0x8(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x9913(%rip), %rax      # 0x2d410
movb %dl, 0x24230(%rax,%rcx)
jmp 0x23b5e
movb -0x9(%rbp), %dl
movq -0x8(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x98f5(%rip), %rax      # 0x2d410
movb %dl, 0x4230(%rax,%rcx)
jmp 0x23b5e
movb -0x9(%rbp), %dl
movq -0x8(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x98d7(%rip), %rax      # 0x2d410
movb %dl, 0x8230(%rax,%rcx)
jmp 0x23b5e
movb -0x9(%rbp), %dl
movq -0x8(%rbp), %rcx
andq $0x3fff, %rcx           # imm = 0x3FFF
leaq 0x98b9(%rip), %rax      # 0x2d410
movb %dl, 0xc230(%rax,%rcx)
movl $0x1, %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)