// File: /workspace/github_c_makefile_star2_O0/tkln[P]mcwm/mcwm.c
// Function: getmodkeys
struct modkeycodes getmodkeys(xcb_mod_mask_t modmask)
{
    xcb_get_modifier_mapping_cookie_t cookie;
    xcb_get_modifier_mapping_reply_t *reply;
    xcb_keycode_t *modmap;
    struct modkeycodes keycodes = {
        NULL,
        0
    };
    int mask;
    unsigned i;
    const xcb_mod_mask_t masks[8] = { XCB_MOD_MASK_SHIFT,
                                      XCB_MOD_MASK_LOCK,
                                      XCB_MOD_MASK_CONTROL,
                                      XCB_MOD_MASK_1,
                                      XCB_MOD_MASK_2,
                                      XCB_MOD_MASK_3,
                                      XCB_MOD_MASK_4,
                                      XCB_MOD_MASK_5 };

    cookie = xcb_get_modifier_mapping_unchecked(conn);

    if ((reply = xcb_get_modifier_mapping_reply(conn, cookie, NULL)) == NULL)
    {
        return keycodes;
    }

    if (NULL == (keycodes.keycodes = calloc(reply->keycodes_per_modifier,
                                            sizeof (xcb_keycode_t))))
    {
        PDEBUG("Out of memory.\n");
        return keycodes;
    }
    
    modmap = xcb_get_modifier_mapping_keycodes(reply);

    /*
     * The modmap now contains keycodes.
     *
     * The number of keycodes in the list is 8 *
     * keycodes_per_modifier. The keycodes are divided into eight
     * sets, with each set containing keycodes_per_modifier elements.
     *
     * Each set corresponds to a modifier in masks[] in the order
     * specified above.
     *
     * The keycodes_per_modifier value is chosen arbitrarily by the
     * server. Zeroes are used to fill in unused elements within each
     * set.
     */
    for (mask = 0; mask < 8; mask ++)
    {
        if (masks[mask] == modmask)
        {
            for (i = 0; i < reply->keycodes_per_modifier; i ++)
            {
                if (0 != modmap[mask * reply->keycodes_per_modifier + i])
                {
                    keycodes.keycodes[i]
                        = modmap[mask * reply->keycodes_per_modifier + i];
                    keycodes.len ++;
                }
            }
            
            PDEBUG("Got %d keycodes.\n", keycodes.len);
        }
    } /* for mask */
    
    free(reply);
    
    return keycodes;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x14(%rbp)
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x31c0
movq 0x1fee(%rip), %rax      # 0xa5e0
movq %rax, -0x50(%rbp)
movq 0x1feb(%rip), %rax      # 0xa5e8
movq %rax, -0x48(%rbp)
movq 0x1fe8(%rip), %rax      # 0xa5f0
movq %rax, -0x40(%rbp)
movq 0x1fe5(%rip), %rax      # 0xa5f8
movq %rax, -0x38(%rbp)
movq 0x535a(%rip), %rdi      # 0xd978
callq 0x3580
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x18(%rbp)
movq 0x5345(%rip), %rdi      # 0xd978
movl -0x18(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3550
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x864e
jmp 0x872c
movq -0x20(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x3260
movq %rax, %rcx
movq %rcx, -0x10(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x8675
jmp 0x872c
movq -0x20(%rbp), %rdi
callq 0x30b0
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x8, -0x2c(%rbp)
jge 0x8723
movslq -0x2c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %eax
cmpl -0x14(%rbp), %eax
jne 0x8713
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jae 0x8711
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rdx
movzbl 0x1(%rdx), %edx
imull %edx, %ecx
addl -0x30(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x8704
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rdx
movzbl 0x1(%rdx), %edx
imull %edx, %ecx
addl -0x30(%rbp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x8706
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x86a7
jmp 0x8713
jmp 0x8715
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x8689
movq -0x20(%rbp), %rdi
callq 0x3040
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %edx
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)