// File: /workspace/github_c_makefile_star2_O3/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, -0x2c(%rbp)
movq %rdi, -0x48(%rbp)
movq %rsp, -0x58(%rbp)
movl %esi, %eax
movq %rsp, %rcx
movq %rax, -0x50(%rbp)
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, %rsp
testl %esi, %esi
jle 0x6a74
movl %esi, -0x38(%rbp)
xorl %ebx, %ebx
movq -0x48(%rbp), %r14
movq -0x50(%rbp), %r13
movl -0x2c(%rbp), %r15d
movq 0x41a0(%rip), %rdi      # 0xa978
movl (%r14,%rbx,4), %esi
movq %rcx, %r12
movl %r15d, %edx
callq 0x3580
movq %r12, %rcx
movl %eax, (%r12,%rbx,4)
incq %rbx
cmpq %rbx, %r13
jne 0x67d1
cmpl $0x0, -0x38(%rbp)
jle 0x6a74
xorl %ebx, %ebx
movq 0x416f(%rip), %rdi      # 0xa978
movl (%rcx,%rbx,4), %esi
xorl %edx, %edx
callq 0x34f0
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x6a4e
movq -0x38(%rbp), %r14
movq %r14, %rdi
callq 0x30e0
movl %eax, %r15d
movq %r14, %rdi
callq 0x3360
leaq -0x70(%rbp), %rdi
leaq 0xa86(%rip), %rsi       # 0x72c8
movl %r15d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x33e0
movl 0xc(%r14), %esi
testl %esi, %esi
je 0x6952
movq 0x4116(%rip), %rdi      # 0xa978
movl -0x2c(%rbp), %edx
callq 0x3340
movq 0x4107(%rip), %rdi      # 0xa978
movl %eax, %esi
xorl %edx, %edx
callq 0x34a0
testq %rax, %rax
je 0x6a74
movq %rax, %rsi
movq -0x48(%rbp), %rax
movl (%rax,%rbx,4), %r15d
movzwl 0xc(%rsi), %r13d
movzwl 0xe(%rsi), %r14d
movq 0x4031(%rip), %rax      # 0xa8d0
testq %rax, %rax
je 0x68df
movq %rax, %rcx
movq (%rcx), %rdx
cmpl %r15d, (%rdx)
je 0x68c1
cmpw %r13w, 0x10(%rdx)
jne 0x68c1
cmpw %r14w, 0x12(%rdx)
je 0x6a4e
movq 0x10(%rcx), %rcx
testq %rcx, %rcx
jne 0x68a7
movq (%rax), %rdi
cmpl %r15d, (%rdi)
je 0x697f
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x68ca
movq -0x70(%rbp), %rax
movq %rax, -0x68(%rbp)
movq %rsi, -0x40(%rbp)
movss 0x10(%rsi), %xmm0
movaps %xmm0, -0x80(%rbp)
leaq 0x3fd5(%rip), %rdi      # 0xa8d0
callq 0x6d90
testq %rax, %rax
je 0x6a60
movq %rax, -0x60(%rbp)
movl $0x20, %edi
callq 0x3350
testq %rax, %rax
je 0x6a6a
movq -0x60(%rbp), %rdx
movq %rax, (%rdx)
movl %r15d, (%rax)
movq -0x68(%rbp), %rcx
movq %rcx, 0x8(%rax)
movw %r13w, 0x10(%rax)
movw %r14w, 0x12(%rax)
movaps -0x80(%rbp), %xmm0
movss %xmm0, 0x14(%rax)
movq %rdx, 0x18(%rax)
movq -0x40(%rbp), %rsi
jmp 0x6a3d
movq 0x3f77(%rip), %rax      # 0xa8d0
testq %rax, %rax
je 0x6a45
movq -0x48(%rbp), %rcx
movl (%rcx,%rbx,4), %ecx
movq (%rax), %r14
cmpl %ecx, (%r14)
je 0x69b9
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x6969
jmp 0x6a45
cmpw 0x10(%rdi), %r13w
setne %al
je 0x698e
movw %r13w, 0x10(%rdi)
cmpw 0x12(%rdi), %r14w
je 0x699c
movw %r14w, 0x12(%rdi)
movb $0x1, %al
movzwl 0x10(%rsi), %ecx
cmpw 0x14(%rdi), %cx
jne 0x6a1d
movzwl 0x12(%rsi), %ecx
cmpw 0x16(%rdi), %cx
jne 0x6a2b
testb %al, %al
jne 0x6a32
jmp 0x6a3d
movq 0x3f08(%rip), %r15      # 0xa8c8
testq %r15, %r15
je 0x6a00
movq (%r15), %rdi
movq 0x38(%rdi), %rax
cmpq %r14, %rax
jne 0x69f6
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x69ea
movq 0x3eeb(%rip), %rax      # 0xa8d0
testq %rax, %rax
je 0x69fc
movq (%rax), %rax
movq %rax, 0x38(%rdi)
callq 0x42d3
movq 0x10(%r15), %r15
jmp 0x69c0
xorl %eax, %eax
jmp 0x69ed
movq 0x8(%r14), %rdi
callq 0x3040
movq 0x18(%r14), %rdx
leaq 0x3ebc(%rip), %rdi      # 0xa8d0
xorl %esi, %esi
callq 0x6dff
jmp 0x6a45
movw %cx, 0x14(%rdi)
movzwl 0x12(%rsi), %ecx
cmpw 0x16(%rdi), %cx
je 0x6a32
leaq 0x16(%rdi), %rax
movw %cx, (%rax)
movq %rsi, %r14
callq 0x42a1
movq %r14, %rsi
movq %rsi, %rdi
callq 0x3040
movq -0x38(%rbp), %rdi
callq 0x3040
incq %rbx
cmpq -0x50(%rbp), %rbx
movq %r12, %rcx
jne 0x6802
jmp 0x6a74
callq 0x36d0
jmp 0x6949
callq 0x36ae
jmp 0x6949
movq -0x58(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq