// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq 0x5969(%rip), %rdi      # 0xa978
callq 0x3130
movq %rax, %rbx
movq 0x5912(%rip), %rdi      # 0xa930
testq %rdi, %rdi
je 0x5028
callq 0x3040
movq 0x5949(%rip), %rdi      # 0xa978
callq 0x3590
movq 0x593d(%rip), %rdi      # 0xa978
xorl %r12d, %r12d
movl %eax, %esi
xorl %edx, %edx
callq 0x3560
movl $0x0, %r15d
testq %rax, %rax
je 0x50c8
movq %rax, %r14
movzbl 0x1(%rax), %edi
movl $0x1, %esi
callq 0x3260
testq %rax, %rax
je 0x50c2
movq %rax, %r15
movq %r14, %rdi
callq 0x30b0
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpl $0x6, %ecx
jne 0x50b0
movb 0x1(%r14), %sil
testb %sil, %sil
je 0x50b0
xorl %edx, %edx
movzbl %sil, %esi
imulq %rcx, %rsi
addq %rax, %rsi
movb (%rdx,%rsi), %sil
testb %sil, %sil
je 0x50a3
movb %sil, (%r15,%rdx)
incl %r12d
incq %rdx
movzbl 0x1(%r14), %esi
cmpq %rsi, %rdx
jb 0x5088
incq %rcx
cmpl $0x8, %ecx
jne 0x5078
movq %r14, %rdi
callq 0x3040
jmp 0x50c8
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r15, 0x5861(%rip)      # 0xa930
movl %r12d, 0x5862(%rip)     # 0xa938
testl %r12d, %r12d
je 0x521f
cmpl $0x0, 0x5852(%rip)      # 0xa938
je 0x5131
xorl %r14d, %r14d
movq 0x5886(%rip), %rdi      # 0xa978
movq 0x584f(%rip), %rax      # 0xa948
movl (%rax), %edx
movq 0x582e(%rip), %rax      # 0xa930
movzbl (%rax,%r14), %r8d
movl $0x1, (%rsp)
movl $0x1, %esi
movl $0x8000, %ecx           # imm = 0x8000
movl $0x1, %r9d
callq 0x32f0
incq %r14
movl 0x580c(%rip), %eax      # 0xa938
cmpq %rax, %r14
jb 0x50eb
movl $0x4, %r14d
leaq 0x51a2(%rip), %r15      # 0xa2e0
movl $0x1, %ebp
movl -0x4(%r14,%r15), %esi
cmpl $0xffffff, %esi         # imm = 0xFFFFFF
jne 0x515a
movb $0x0, (%r14,%r15)
jmp 0x51dc
movq %rbx, %rdi
callq 0x32c0
testq %rax, %rax
je 0x5226
movb (%rax), %r12b
movq %rax, %rdi
callq 0x3040
movb %r12b, (%r14,%r15)
testb %r12b, %r12b
je 0x5205
movq 0x57ee(%rip), %rdi      # 0xa978
movq 0x57b7(%rip), %rax      # 0xa948
movl (%rax), %edx
movl %ebp, (%rsp)
movzbl %r12b, %r8d
movl $0x1, %esi
movl $0x40, %ecx
movl $0x1, %r9d
callq 0x32f0
movq 0x57c2(%rip), %rdi      # 0xa978
movq 0x578b(%rip), %rax      # 0xa948
movl (%rax), %edx
movzbl (%r14,%r15), %r8d
movl %ebp, (%rsp)
movl $0x1, %esi
movl $0x41, %ecx
movl $0x1, %r9d
callq 0x32f0
addq $0x28, %r14
cmpq $0x5cc, %r14            # imm = 0x5CC
jne 0x5143
movq 0x5784(%rip), %rdi      # 0xa978
callq 0x3150
movq %rbx, %rdi
callq 0x33b0
xorl %eax, %eax
jmp 0x5212
movq %rbx, %rdi
callq 0x33b0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x3622
jmp 0x520d
callq 0x35fd