// File: /workspace/github_c_makefile_star2_O0/tkln[P]mcwm/mcwm.c
// Function: setupscreen
int setupscreen(void)
{
    xcb_query_tree_reply_t *reply;
    xcb_query_pointer_reply_t *pointer;
    int i;
    int len;
    xcb_window_t *children;
    xcb_get_window_attributes_reply_t *attr;
    struct client *client;
    uint32_t ws;
    
    /* Get all children. */
    reply = xcb_query_tree_reply(conn,
                                 xcb_query_tree(conn, screen->root), 0);
    if (NULL == reply)
    {
        return -1;
    }

    len = xcb_query_tree_children_length(reply);    
    children = xcb_query_tree_children(reply);
    
    /* Set up all windows on this root. */
    for (i = 0; i < len; i ++)
    {
        attr = xcb_get_window_attributes_reply(
            conn, xcb_get_window_attributes(conn, children[i]), NULL);

        if (!attr)
        {
            fprintf(stderr, "Couldn't get attributes for window %d.",
                    children[i]);
            continue;
        }

        /*
         * Don't set up or even bother windows in override redirect
         * mode.
         *
         * This mode means they wouldn't have been reported to us
         * with a MapRequest if we had been running, so in the
         * normal case we wouldn't have seen them.
         *
         * Only handle visible windows. 
         */    
        if (!attr->override_redirect
            && attr->map_state == XCB_MAP_STATE_VIEWABLE)
        {
            client = setupwin(children[i]);
            if (NULL != client)
            {
                /*
                 * Find the physical output this window will be on if
                 * RANDR is active.
                 */
                if (-1 != randrbase)
                {
                    PDEBUG("Looking for monitor on %d x %d.\n", client->x,
                        client->y);
                    client->monitor = findmonbycoord(client->x, client->y);
#if DEBUG
                    if (NULL != client->monitor)
                    {
                        PDEBUG("Found client on monitor %s.\n",
                               client->monitor->name);
                    }
                    else
                    {
                        PDEBUG("Couldn't find client on any monitor.\n");
                    }
#endif
                }
                
                /* Fit window on physical screen. */
                fitonscreen(client);
                
                /*
                 * Check if this window has a workspace set already as
                 * a WM hint.
                 *
                 */
                ws = getwmdesktop(children[i]);

                if (ws == NET_WM_FIXED)
                {
                    /* Add to current workspace. */
                    addtoworkspace(client, curws);                    
                    /* Add to all other workspaces. */
                    fixwindow(client, false);
                }
                else if (MCWM_NOWS != ws && ws < WORKSPACES)
                {
                    addtoworkspace(client, ws);
                    /* If it's not our current workspace, hide it. */
                    if (ws != curws)
                    {
                        xcb_unmap_window(conn, client->id);
                    }
                }
                else
                {
                    /*
                     * No workspace hint at all. Just add it to our
                     * current workspace.
                     */
                    addtoworkspace(client, curws);
                }
            }
        }
        
        free(attr);
    } /* for */

    changeworkspace(0);
        
    /*
     * Get pointer position so we can set focus on any window which
     * might be under it.
     */
    pointer = xcb_query_pointer_reply(
        conn, xcb_query_pointer(conn, screen->root), 0);

    if (NULL == pointer)
    {
        focuswin = NULL;
    }
    else
    {
        setfocus(findclient(pointer->child));
        free(pointer);
    }
    
    xcb_flush(conn);
    
    free(reply);
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x7df9(%rip), %rax      # 0xd978
movq %rax, -0x58(%rbp)
movq 0x7dee(%rip), %rdi      # 0xd978
movq 0x7db7(%rip), %rax      # 0xd948
movl (%rax), %esi
callq 0x3180
movq -0x58(%rbp), %rdi
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3240
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq -0x10(%rbp), %rax
jne 0x5bc3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5dfa
movq -0x10(%rbp), %rdi
callq 0x3300
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x31d0
movq %rax, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x5d6e
movq 0x7d82(%rip), %rax      # 0xd978
movq %rax, -0x60(%rbp)
movq 0x7d77(%rip), %rdi      # 0xd978
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x3310
movq -0x60(%rbp), %rdi
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3190
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x5c57
movq 0x73c2(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x483e(%rip), %rsi      # 0xa489
movb $0x0, %al
callq 0x32d0
jmp 0x5d60
movq -0x30(%rbp), %rax
cmpb $0x0, 0x1b(%rax)
jne 0x5d57
movq -0x30(%rbp), %rax
movzbl 0x1a(%rax), %eax
cmpl $0x2, %eax
jne 0x5d57
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x8020
movq %rax, -0x38(%rbp)
xorl %eax, %eax
cmpq -0x38(%rbp), %rax
je 0x5d55
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0x7cf3(%rip), %eax      # 0xd994
je 0x5cc6
movq -0x38(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x38(%rbp), %rax
movswl %cx, %edi
movswl 0x8(%rax), %esi
callq 0x8340
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rdi
callq 0x4ac0
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x83f0
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x3c(%rbp)
jne 0x5d04
movq -0x38(%rbp), %rdi
movl 0x7bce(%rip), %esi      # 0xd8c0
callq 0x6fb0
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x6d70
jmp 0x5d53
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpl -0x3c(%rbp), %eax
je 0x5d42
cmpl $0xa, -0x3c(%rbp)
jae 0x5d42
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x6fb0
movl -0x3c(%rbp), %eax
cmpl 0x7b97(%rip), %eax      # 0xd8c0
je 0x5d40
movq 0x7c46(%rip), %rdi      # 0xd978
movq -0x38(%rbp), %rax
movl (%rax), %esi
callq 0x30c0
movl %eax, -0x48(%rbp)
jmp 0x5d51
movq -0x38(%rbp), %rdi
movl 0x7b74(%rip), %esi      # 0xd8c0
callq 0x6fb0
jmp 0x5d53
jmp 0x5d55
jmp 0x5d57
movq -0x30(%rbp), %rdi
callq 0x3040
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5be3
xorl %edi, %edi
callq 0x6be0
movq 0x7bfc(%rip), %rax      # 0xd978
movq %rax, -0x68(%rbp)
movq 0x7bf1(%rip), %rdi      # 0xd978
movq 0x7bba(%rip), %rax      # 0xd948
movl (%rax), %esi
callq 0x3290
movq -0x68(%rbp), %rdi
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x32b0
movq %rax, -0x18(%rbp)
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
jne 0x5dc1
movq $0x0, 0x7b81(%rip) # 0xd940
jmp 0x5dde
movq -0x18(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x84c0
movq %rax, %rdi
callq 0x71c0
movq -0x18(%rbp), %rdi
callq 0x3040
movq 0x7b93(%rip), %rdi      # 0xd978
callq 0x3140
movq -0x10(%rbp), %rdi
callq 0x3040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)