// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %r12
movq %rsp, -0x50(%rbp)
movl %esi, %r13d
movq %rsp, %rcx
leaq 0xf(,%r13,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, %rsp
testl %esi, %esi
movq %rcx, -0x48(%rbp)
jle 0x674c
xorl %ebx, %ebx
movq 0x4247(%rip), %rdi      # 0xa978
movl (%r12,%rbx,4), %esi
movl %r14d, %edx
callq 0x3580
movq -0x48(%rbp), %rcx
movl %eax, (%rcx,%rbx,4)
incq %rbx
cmpq %rbx, %r13
jne 0x672a
movq %r13, -0x68(%rbp)
movq %r12, -0x38(%rbp)
movl %r14d, -0x30(%rbp)
testl %r15d, %r15d
jle 0x69d7
xorl %ebx, %ebx
movq 0x420e(%rip), %rdi      # 0xa978
movl (%rcx,%rbx,4), %esi
xorl %edx, %edx
callq 0x34f0
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x69b6
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0x30e0
movl %eax, %r15d
movq %r14, %rdi
callq 0x3360
leaq -0x70(%rbp), %rdi
leaq 0xaed(%rip), %rsi       # 0x7290
movl %r15d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x33e0
movl 0xc(%r14), %esi
testl %esi, %esi
je 0x6895
movq 0x41b5(%rip), %rdi      # 0xa978
movl -0x30(%rbp), %edx
callq 0x3340
movq 0x41a6(%rip), %rdi      # 0xa978
movl %eax, %esi
xorl %edx, %edx
callq 0x34a0
testq %rax, %rax
je 0x69d7
movq %rax, %r15
movq -0x38(%rbp), %rax
movl (%rax,%rbx,4), %r13d
movzwl 0xc(%r15), %r12d
movzwl 0xe(%r15), %r14d
movq 0x40d0(%rip), %rax      # 0xa8d0
testq %rax, %rax
je 0x6840
movq %rax, %rcx
movq (%rcx), %rdx
cmpl %r13d, (%rdx)
je 0x6822
cmpw %r12w, 0x10(%rdx)
jne 0x6822
cmpw %r14w, 0x12(%rdx)
je 0x69b6
movq 0x10(%rcx), %rcx
testq %rcx, %rcx
jne 0x6808
jmp 0x6831
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x6840
movq (%rax), %rdi
cmpl %r13d, (%rdi)
jne 0x682d
jmp 0x6842
xorl %edi, %edi
testq %rdi, %rdi
je 0x692c
cmpw 0x10(%rdi), %r12w
setne %al
je 0x685a
movw %r12w, 0x10(%rdi)
cmpw 0x12(%rdi), %r14w
je 0x6868
movw %r14w, 0x12(%rdi)
movb $0x1, %al
movzwl 0x10(%r15), %ecx
cmpw 0x14(%rdi), %cx
je 0x6879
movw %cx, 0x14(%rdi)
movb $0x1, %al
movzwl 0x12(%r15), %ecx
cmpw 0x16(%rdi), %cx
jne 0x699c
testb %al, %al
jne 0x69a0
jmp 0x69a5
movq 0x4034(%rip), %rax      # 0xa8d0
testq %rax, %rax
movq -0x38(%rbp), %rcx
je 0x68b9
movl (%rcx,%rbx,4), %ecx
movq (%rax), %r14
cmpl %ecx, (%r14)
je 0x68bc
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x68a8
xorl %r14d, %r14d
testq %r14, %r14
je 0x69ad
movq 0x3ffc(%rip), %r15      # 0xa8c8
testq %r15, %r15
je 0x690c
movq (%r15), %rdi
movq 0x38(%rdi), %rax
cmpq %r14, %rax
jne 0x6902
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x68f6
movq 0x3fdf(%rip), %rax      # 0xa8d0
testq %rax, %rax
je 0x6908
movq (%rax), %rax
movq %rax, 0x38(%rdi)
callq 0x42e8
movq 0x10(%r15), %r15
jmp 0x68cc
xorl %eax, %eax
jmp 0x68f9
movq 0x8(%r14), %rdi
callq 0x3040
movq 0x18(%r14), %rdx
leaq 0x3fb0(%rip), %rdi      # 0xa8d0
xorl %esi, %esi
callq 0x6d8c
jmp 0x69ad
movq -0x70(%rbp), %rax
movq %rax, -0x60(%rbp)
movzwl 0x10(%r15), %eax
movw %ax, -0x2c(%rbp)
movzwl 0x12(%r15), %eax
movw %ax, -0x2a(%rbp)
leaq 0x3f83(%rip), %rdi      # 0xa8d0
callq 0x6d0c
testq %rax, %rax
je 0x69c9
movq %rax, -0x58(%rbp)
movl $0x20, %edi
callq 0x3350
testq %rax, %rax
je 0x69d0
movq -0x58(%rbp), %rdx
movq %rax, (%rdx)
movl %r13d, (%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x8(%rax)
movw %r12w, 0x10(%rax)
movw %r14w, 0x12(%rax)
movzwl -0x2c(%rbp), %ecx
movw %cx, 0x14(%rax)
movzwl -0x2a(%rbp), %ecx
movw %cx, 0x16(%rax)
movq %rdx, 0x18(%rax)
jmp 0x69a5
movw %cx, 0x16(%rdi)
callq 0x42b6
movq %r15, %rdi
callq 0x3040
movq -0x40(%rbp), %rdi
callq 0x3040
incq %rbx
cmpq -0x68(%rbp), %rbx
movq -0x48(%rbp), %rcx
jne 0x6763
jmp 0x69d7
callq 0x36d0
jmp 0x69a5
callq 0x36ae
jmp 0x69a5
movq -0x50(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq