// File: /workspace/github_c_makefile_star2_O0/tkln[P]mcwm/mcwm.c
// Function: setupkeys
int setupkeys(void)
{
    xcb_key_symbols_t *keysyms;
    unsigned i;
    
    /* Get all the keysymbols. */
    keysyms = xcb_key_symbols_alloc(conn);

    /*
     * Find out what keys generates our MODKEY mask. Unfortunately it
     * might be several keys.
     */
    if (NULL != modkeys.keycodes)
    {
        free(modkeys.keycodes);
    }
    modkeys = getmodkeys(MODKEY);

    if (0 == modkeys.len)
    {
        fprintf(stderr, "We couldn't find any keycodes to our main modifier "
                "key!\n");
        return -1;
    }

    for (i = 0; i < modkeys.len; i ++)
    {
        /*
         * Grab the keys that are bound to MODKEY mask with any other
         * modifier.
         */
        xcb_grab_key(conn, 1, screen->root, XCB_MOD_MASK_ANY,
                     modkeys.keycodes[i],
                     XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);    
    }
    
    /* Now grab the rest of the keys with the MODKEY modifier. */
    for (i = 0; i < sizeof(keys)/sizeof(keys[0]); i ++)
    {
        if (XK_VoidSymbol == keys[i].keysym)
        {
            keys[i].keycode = 0;
            continue;
        }

        keys[i].keycode = keysymtokeycode(keys[i].keysym, keysyms);        
        if (0 == keys[i].keycode)
        {
            /* Couldn't set up keys! */
    
            /* Get rid of key symbols. */
            xcb_key_symbols_free(keysyms);

            return -1;
        }
            
        /* Grab other keys with a modifier mask. */
        xcb_grab_key(conn, 1, screen->root, MODKEY, keys[i].keycode,
                     XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);

        /*
         * XXX Also grab it's shifted counterpart. A bit ugly here
         * because we grab all of them not just the ones we want.
         */
        xcb_grab_key(conn, 1, screen->root, MODKEY | SHIFTMOD,
                     keys[i].keycode,
                     XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
    } /* for */

    /* Need this to take effect NOW! */
    xcb_flush(conn);
    
    /* Get rid of the key symbols table. */
    xcb_key_symbols_free(keysyms);
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x7b59(%rip), %rdi      # 0xd978
callq 0x3120
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq 0x7aff(%rip), %rax      # 0xd930
je 0x5e3f
movq 0x7af6(%rip), %rdi      # 0xd930
callq 0x3040
movl $0x40, %edi
callq 0x85d0
movq %rax, -0x28(%rbp)
movl %edx, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq %rax, 0x7ad5(%rip)      # 0xd930
movq -0x20(%rbp), %rax
movq %rax, 0x7ad2(%rip)      # 0xd938
xorl %eax, %eax
cmpl 0x7aca(%rip), %eax      # 0xd938
jne 0x5e94
movq 0x7181(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x468c(%rip), %rsi      # 0xa50d
movb $0x0, %al
callq 0x32d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6056
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x7a94(%rip), %eax      # 0xd938
jae 0x5ef0
movq 0x7acb(%rip), %rdi      # 0xd978
movq 0x7a94(%rip), %rax      # 0xd948
movl (%rax), %edx
movq 0x7a73(%rip), %rax      # 0xd930
movl -0x14(%rbp), %ecx
movl %ecx, %r8d
movl $0x1, %r9d
movl $0x8000, %ecx           # imm = 0x8000
movl %r9d, %esi
movzbl (%rax,%r8), %r8d
movl $0x1, (%rsp)
callq 0x32f0
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5e9b
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpq $0x25, %rax
jae 0x603a
movl -0x14(%rbp), %eax
leaq 0x73d2(%rip), %rcx      # 0xd2e0
imulq $0x28, %rax, %rax
addq %rax, %rcx
movl $0xffffff, %eax         # imm = 0xFFFFFF
cmpl (%rcx), %eax
jne 0x5f3a
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x73b6(%rip), %rax      # 0xd2e0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4(%rax)
jmp 0x602c
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x739a(%rip), %rax      # 0xd2e0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edi
movq -0x10(%rbp), %rsi
callq 0x8740
movb %al, %cl
movl -0x14(%rbp), %eax
movl %eax, %edx
leaq 0x737a(%rip), %rax      # 0xd2e0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x4(%rax)
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x7364(%rip), %rax      # 0xd2e0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movzbl 0x4(%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x5fa2
movq -0x10(%rbp), %rdi
callq 0x33b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6056
movq 0x79cf(%rip), %rdi      # 0xd978
movq 0x7998(%rip), %rax      # 0xd948
movl (%rax), %edx
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x7322(%rip), %rax      # 0xd2e0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x1, %r9d
movl $0x40, %ecx
movl %r9d, %esi
movzbl 0x4(%rax), %r8d
movl $0x1, (%rsp)
callq 0x32f0
movl %eax, -0x30(%rbp)
movq 0x798a(%rip), %rdi      # 0xd978
movq 0x7953(%rip), %rax      # 0xd948
movl (%rax), %edx
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x72dd(%rip), %rax      # 0xd2e0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x1, %r9d
movl $0x41, %ecx
movl %r9d, %esi
movzbl 0x4(%rax), %r8d
movl $0x1, (%rsp)
callq 0x32f0
movl %eax, -0x34(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5ef7
movq 0x7937(%rip), %rdi      # 0xd978
callq 0x3140
movq -0x10(%rbp), %rdi
callq 0x33b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop