// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x5b19(%rip), %rdi      # 0xa978
callq 0x3130
movq %rax, 0x10(%rsp)
movq 0x5ac0(%rip), %rdi      # 0xa930
callq 0x3040
movq 0x5afc(%rip), %rdi      # 0xa978
callq 0x3590
movq 0x5af0(%rip), %rdi      # 0xa978
movl %eax, %esi
xorl %edx, %edx
callq 0x3560
testq %rax, %rax
je 0x5034
movq %rax, %r14
movzbl 0x1(%rax), %edi
pushq $0x1
popq %rsi
callq 0x3260
testq %rax, %rax
je 0x5034
movq %rax, %r15
movq %r14, %rdi
callq 0x30b0
xorl %r12d, %r12d
xorl %ecx, %ecx
cmpl $0x6, %ecx
je 0x4ed0
cmpl $0x8, %ecx
je 0x4ef8
incl %ecx
jmp 0x4ec2
movzbl 0x1(%r14), %edx
imulq $0x6, %rdx, %rsi
addq %rax, %rsi
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x4ecc
movb (%rsi,%rdi), %r8b
testb %r8b, %r8b
je 0x4ef3
movb %r8b, (%r15,%rdi)
incl %r12d
incq %rdi
jmp 0x4ede
movq %r14, %rdi
callq 0x3040
movq %r15, 0x5a29(%rip)      # 0xa930
movl %r12d, 0x5a2a(%rip)     # 0xa938
testl %r12d, %r12d
je 0x5043
xorl %r14d, %r14d
pushq $0x1
popq %rbp
movl %r12d, %eax
cmpq %rax, %r14
jae 0x4f63
movq 0x5a4c(%rip), %rdi      # 0xa978
movq 0x5a15(%rip), %rax      # 0xa948
movl (%rax), %edx
movq 0x59f4(%rip), %rax      # 0xa930
movzbl (%rax,%r14), %r8d
movl $0x1, (%rsp)
movl %ebp, %esi
movl $0x8000, %ecx           # imm = 0x8000
movl %ebp, %r9d
callq 0x32f0
incq %r14
movl 0x59d7(%rip), %r12d     # 0xa938
jmp 0x4f1d
pushq $0x4
popq %r12
leaq 0x5372(%rip), %r13      # 0xa2e0
pushq $0x40
popq %r14
pushq $0x41
popq %r15
cmpq $0x5cc, %r12            # imm = 0x5CC
je 0x500e
movl -0x4(%r12,%r13), %esi
cmpl $0xffffff, %esi         # imm = 0xFFFFFF
jne 0x4f97
movb $0x0, (%r12,%r13)
jmp 0x5005
movq 0x10(%rsp), %rdi
callq 0x32c0
testq %rax, %rax
je 0x5071
movb (%rax), %bl
movq %rax, %rdi
callq 0x3040
movb %bl, (%r12,%r13)
testb %bl, %bl
je 0x5028
movq 0x59b5(%rip), %rdi      # 0xa978
movq 0x597e(%rip), %rax      # 0xa948
movl (%rax), %edx
movl %ebp, (%rsp)
movzbl %bl, %r8d
movl %ebp, %esi
movl %r14d, %ecx
movl %ebp, %r9d
callq 0x32f0
movq 0x5991(%rip), %rdi      # 0xa978
movq 0x595a(%rip), %rax      # 0xa948
movl (%rax), %edx
movzbl (%r12,%r13), %r8d
movl %ebp, (%rsp)
movl %ebp, %esi
movl %r15d, %ecx
movl %ebp, %r9d
callq 0x32f0
addq $0x28, %r12
jmp 0x4f76
movq 0x5963(%rip), %rdi      # 0xa978
callq 0x3150
movq 0x10(%rsp), %rdi
callq 0x33b0
xorl %eax, %eax
jmp 0x5062
movq 0x10(%rsp), %rdi
callq 0x33b0
jmp 0x505f
andq $0x0, 0x58f4(%rip)      # 0xa930
andl $0x0, 0x58f5(%rip)      # 0xa938
movq 0x4fae(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x22fd(%rip), %rdi      # 0x7351
pushq $0x38
popq %rsi
pushq $0x1
popq %rdx
callq 0x3510
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4f80(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x2308(%rip), %rdi      # 0x738a
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x3510
pushq $0x1
popq %rdi
callq 0x3500