// File: /workspace/github_c_makefile_star2_O0/kaugm[P]mmwm/mmwm.c
// Function: setup_keyboard
int setup_keyboard(void)
{
    xcb_get_modifier_mapping_reply_t *reply;
    xcb_keycode_t                    *modmap;
    xcb_keycode_t                    *numlock;

    if (!(keysyms = xcb_key_symbols_alloc(dis)))
        return -1;

    reply = xcb_get_modifier_mapping_reply(dis,
                            xcb_get_modifier_mapping_unchecked(dis), NULL);
                            /* TODO: error checking */
    if (!reply)
        return -1;

    modmap = xcb_get_modifier_mapping_keycodes(reply);
    if (!modmap) {
        free(reply);
        return -1;
    }

    numlock = xcb_get_keycodes(XK_Num_Lock);
    if (numlock) {
        for (unsigned int i = 0; i < 8; i++) {
            for (unsigned int j = 0; j < reply->keycodes_per_modifier; j++) {
                xcb_keycode_t keycode =
                        modmap[i * reply->keycodes_per_modifier +
                                               j];
                if (keycode == XCB_NO_SYMBOL)
                    continue;
                for (unsigned int n = 0; numlock[n] != XCB_NO_SYMBOL; n++) {
                    if (numlock[n] == keycode) {
                        DEBUGP("xcb: found num-lock %d\n", 1 << i);
                        numlockmask = 1 << i;
                        break;
                    }
                }
            }
        }
        free(numlock);
    }
    free(reply);


    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x9e01(%rip), %rdi      # 0xd7a0
callq 0x3150
movq %rax, 0x9dfd(%rip)      # 0xd7a8
cmpq $0x0, %rax
jne 0x39bd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b17
movq 0x9ddc(%rip), %rax      # 0xd7a0
movq %rax, -0x40(%rbp)
movq 0x9dd1(%rip), %rdi      # 0xd7a0
callq 0x3690
movq -0x40(%rbp), %rdi
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3630
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x39fe
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b17
movq -0x10(%rbp), %rdi
callq 0x30b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3a27
movq -0x10(%rbp), %rdi
callq 0x3050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b17
movl $0xff7f, %edi           # imm = 0xFF7F
callq 0x3b20
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3b07
movl $0x0, -0x28(%rbp)
cmpl $0x8, -0x28(%rbp)
jae 0x3afe
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jae 0x3aee
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rdx
movzbl 0x1(%rdx), %edx
imull %edx, %ecx
addl -0x2c(%rbp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x2d(%rbp)
movzbl -0x2d(%rbp), %eax
cmpq $0x0, %rax
jne 0x3a94
jmp 0x3ae0
movl $0x0, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpq $0x0, %rax
je 0x3ade
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x2d(%rbp), %ecx
cmpl %ecx, %eax
jne 0x3ad1
movl -0x28(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x9ce1(%rip)      # 0xd7b0
jmp 0x3ade
jmp 0x3ad3
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3a9b
jmp 0x3ae0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3a58
jmp 0x3af0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3a47
movq -0x20(%rbp), %rdi
callq 0x3050
movq -0x10(%rbp), %rdi
callq 0x3050
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq