// File: /workspace/github_c_makefile_star2_O2/tkln[P]mcwm/mcwm.c
// Function: getoutputs
void getoutputs(xcb_randr_output_t *outputs, int len, xcb_timestamp_t timestamp)
{
    char *name;
    xcb_randr_get_crtc_info_cookie_t icookie;
    xcb_randr_get_crtc_info_reply_t *crtc = NULL;
    xcb_randr_get_output_info_reply_t *output;
    struct monitor *mon;
    struct monitor *clonemon;
    xcb_randr_get_output_info_cookie_t ocookie[len];
    int i;
    
    for (i = 0; i < len; i++)
    {
        ocookie[i] = xcb_randr_get_output_info(conn, outputs[i], timestamp);
    }

    /* Loop through all outputs. */
    for (i = 0; i < len; i ++)
    {
        output = xcb_randr_get_output_info_reply(conn, ocookie[i], NULL);
        
        if (output == NULL)
        {
            continue;
        }

        asprintf(&name, "%.*s",
                 xcb_randr_get_output_info_name_length(output),
                 xcb_randr_get_output_info_name(output));

        PDEBUG("Name: %s\n", name);
        PDEBUG("id: %d\n" , outputs[i]);
        PDEBUG("Size: %d x %d mm.\n", output->mm_width, output->mm_height);

        if (XCB_NONE != output->crtc)
        {
            icookie = xcb_randr_get_crtc_info(conn, output->crtc, timestamp);
            crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL);
            if (NULL == crtc)
            {
                return;
            }
            
            PDEBUG("CRTC: at %d, %d, size: %d x %d.\n", crtc->x, crtc->y,
                   crtc->width, crtc->height);

            /* Check if it's a clone. */
            clonemon = findclones(outputs[i], crtc->x, crtc->y);
            if (NULL != clonemon)
            {
                PDEBUG("Monitor %s, id %d is a clone of %s, id %d. Skipping.\n",
                       name, outputs[i],
                       clonemon->name, clonemon->id);
                continue;
            }

            /* Do we know this monitor already? */
            if (NULL == (mon = findmonitor(outputs[i])))
            {
                PDEBUG("Monitor not known, adding to list.\n");
                addmonitor(outputs[i], name, crtc->x, crtc->y, crtc->width,
                           crtc->height);
            }
            else
            {
                bool changed = false;
                
                /*
                 * We know this monitor. Update information. If it's
                 * smaller than before, rearrange windows.
                 */
                PDEBUG("Known monitor. Updating info.\n");

                if (crtc->x != mon->x)
                {
                    mon->x = crtc->x;
                    changed = true;
                }
                if (crtc->y != mon->y)
                {
                    mon->y = crtc->y;
                    changed = true;
                }

                if (crtc->width != mon->width)
                {
                    mon->width = crtc->width;                    
                    changed = true;
                }
                if (crtc->height != mon->height)
                {
                    mon->height = crtc->height;                    
                    changed = true;
                }
                
                if (changed)
                {
                    arrbymon(mon);
                }
            }

            free(crtc);
        }
        else
        {
            PDEBUG("Monitor not used at the moment.\n");
            /*
             * Check if it was used before. If it was, do something.
             */
            if ((mon = findmonitor(outputs[i])))
            {
                struct item *item;
                struct client *client;

                /* Check all windows on this monitor and move them to
                 * the next or to the first monitor if there is no
                 * next.
                 *
                 * FIXME: Use per monitor workspace list instead of
                 * global window list.
                 */
                for (item = winlist; item != NULL; item = item->next)
                {
                    client = item->data;
                    if (client->monitor == mon)
                    {
                        if (NULL == client->monitor->item->next)
                        {
                            if (NULL == monlist)
                            {
                                client->monitor = NULL;
                            }
                            else
                            {
                                client->monitor = monlist->data;
                            }
                        }
                        else
                        {
                            client->monitor =
                                client->monitor->item->next->data;
                        }

                        fitonscreen(client);
                    }
                } /* for */
                
                /* It's not active anymore. Forget about it. */
                delmonitor(mon);
            }
        }

        free(output);
    } /* for */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %r12
movq %rsp, -0x48(%rbp)
movl %esi, %eax
movq %rsp, %r13
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
xorl %ebx, %ebx
testl %esi, %esi
cmovlel %ebx, %r15d
cmpq %rbx, %r15
je 0x6588
movq 0x4406(%rip), %rdi      # 0xa978
movl (%r12,%rbx,4), %esi
movl %r14d, %edx
callq 0x3580
movl %eax, (%r13,%rbx,4)
incq %rbx
jmp 0x6566
movq %r13, -0x68(%rbp)
movq %r12, -0x40(%rbp)
movl %r14d, -0x34(%rbp)
xorl %ecx, %ecx
movq %r15, -0x60(%rbp)
cmpq %r15, %rcx
je 0x680c
movq 0x43ce(%rip), %rdi      # 0xa978
movq -0x68(%rbp), %rax
movq %rcx, -0x30(%rbp)
movl (%rax,%rcx,4), %esi
xorl %edx, %edx
callq 0x34f0
testq %rax, %rax
je 0x67de
movq %rax, %r13
movq %rax, %rdi
callq 0x30e0
movl %eax, %ebx
movq %r13, %rdi
callq 0x3360
leaq -0x70(%rbp), %rdi
leaq 0xce3(%rip), %rsi       # 0x72c8
movl %ebx, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x33e0
movl 0xc(%r13), %esi
testl %esi, %esi
je 0x66c7
movq 0x4374(%rip), %rdi      # 0xa978
movl -0x34(%rbp), %edx
callq 0x3340
movq 0x4365(%rip), %rdi      # 0xa978
movl %eax, %esi
xorl %edx, %edx
callq 0x34a0
testq %rax, %rax
movq -0x30(%rbp), %rcx
je 0x680c
movq %rax, %r12
movq -0x40(%rbp), %rax
movl (%rax,%rcx,4), %ebx
movzwl 0xc(%r12), %r14d
movzwl 0xe(%r12), %r15d
leaq 0x428a(%rip), %rax      # 0xa8d0
movq (%rax), %rax
testq %rax, %rax
je 0x666d
movq (%rax), %rcx
cmpl %ebx, (%rcx)
je 0x6667
cmpw %r14w, 0x10(%rcx)
jne 0x6667
cmpw %r15w, 0x12(%rcx)
je 0x67de
addq $0x10, %rax
jmp 0x6646
movl %ebx, %edi
callq 0x681f
testq %rax, %rax
je 0x674d
cmpw 0x10(%rax), %r14w
setne %cl
je 0x668c
movw %r14w, 0x10(%rax)
cmpw 0x12(%rax), %r15w
je 0x669a
movw %r15w, 0x12(%rax)
movb $0x1, %cl
movzwl 0x10(%r12), %edx
cmpw 0x14(%rax), %dx
jne 0x67ac
movzwl 0x12(%r12), %edx
cmpw 0x16(%rax), %dx
jne 0x67bc
testb %cl, %cl
jne 0x67c6
jmp 0x67ce
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x681f
testq %rax, %rax
je 0x67d6
movq %rax, %rbx
leaq 0x41de(%rip), %r14      # 0xa8c8
movq (%r14), %r14
testq %r14, %r14
je 0x672d
movq (%r14), %rdi
movq 0x38(%rdi), %rax
cmpq %rbx, %rax
jne 0x6723
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x6717
movq 0x41be(%rip), %rax      # 0xa8d0
testq %rax, %rax
je 0x6729
movq (%rax), %rax
movq %rax, 0x38(%rdi)
callq 0x4135
addq $0x10, %r14
jmp 0x66ea
xorl %eax, %eax
jmp 0x671a
movq 0x8(%rbx), %rdi
callq 0x3040
movq 0x18(%rbx), %rdx
leaq 0x418f(%rip), %rdi      # 0xa8d0
xorl %esi, %esi
callq 0x6ba3
jmp 0x67d6
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movss 0x10(%r12), %xmm0
movaps %xmm0, -0x80(%rbp)
leaq 0x4169(%rip), %rdi      # 0xa8d0
callq 0x6b39
testq %rax, %rax
je 0x67ee
movq %rax, -0x50(%rbp)
pushq $0x20
popq %rdi
callq 0x3350
testq %rax, %rax
je 0x67ee
movq -0x50(%rbp), %rdx
movq %rax, (%rdx)
movl %ebx, (%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rax)
movw %r14w, 0x10(%rax)
movw %r15w, 0x12(%rax)
movaps -0x80(%rbp), %xmm0
movss %xmm0, 0x14(%rax)
movq %rdx, 0x18(%rax)
jmp 0x67ce
movw %dx, 0x14(%rax)
movzwl 0x12(%r12), %edx
cmpw 0x16(%rax), %dx
je 0x67c6
movq %rax, %rcx
addq $0x16, %rcx
movw %dx, (%rcx)
movq %rax, %rdi
callq 0x4103
movq %r12, %rdi
callq 0x3040
movq %r13, %rdi
callq 0x3040
movq -0x30(%rbp), %rcx
incq %rcx
movq -0x60(%rbp), %r15
jmp 0x659a
movq 0x3803(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0xbe4(%rip), %rdi       # 0x73e3
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x3510
jmp 0x67ce
movq -0x48(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq