// File: /workspace/github_c_makefile_star2_O1/comfies[P]custard/src/wm/custard.c
// Function: manage_pre_existing_windows
void manage_pre_existing_windows() {
    unsigned int index = 0;
    xcb_query_tree_cookie_t query_cookie;
    query_cookie = xcb_query_tree(xcb_connection,
        xcb_screen->root);

    xcb_query_tree_reply_t *tree_reply;
    tree_reply = xcb_query_tree_reply(xcb_connection, query_cookie, NULL);

    if (!tree_reply)
        return;

    window_t *window = NULL;
    xcb_window_t child;
    xcb_window_t *children = xcb_query_tree_children(tree_reply);
    unsigned int number_of_children = (unsigned int)
        xcb_query_tree_children_length(tree_reply);

    for (; index < number_of_children; index++) {
        child = children[index];

        if (window_should_be_managed(child)) {
            window = manage_window(child);
            map_window(child);
            xcb_grab_button(xcb_connection, 0, child,
                XCB_EVENT_MASK_BUTTON_PRESS,
                XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
                XCB_NONE, XCB_NONE,  XCB_BUTTON_INDEX_ANY, XCB_MOD_MASK_ANY);
            decorate(window);
            log_debug("Pre-existing window(%08x) managed",
                child, window->workspace);
        }

    }

    if (window) {
    // Raise and focus the last window
        focused_window = window->id;
        xcb_ungrab_button(xcb_connection,
            XCB_BUTTON_INDEX_ANY, focused_window, XCB_MOD_MASK_ANY);
        raise_window(window->parent);
        focus_window(window->id);
        decorate(window);
    }

    apply();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x7284(%rip), %rbx      # 0xc8f8
movq (%rbx), %rdi
leaq 0x7282(%rip), %rax      # 0xc900
movq (%rax), %rax
movl (%rax), %esi
callq 0x3270
movq (%rbx), %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x3330
testq %rax, %rax
je 0x576b
movq %rax, %rbx
movq %rax, %rdi
callq 0x32e0
movq %rax, %r14
movq %rbx, %rdi
callq 0x3410
xorl %r15d, %r15d
testl %eax, %eax
je 0x577a
movl %eax, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
movl (%r14,%r13,4), %ebp
movl %ebp, %edi
callq 0x6c30
testw %ax, %ax
je 0x575d
movl %ebp, %edi
callq 0x6dc8
movq %rax, %rbx
movl %ebp, %edi
callq 0x76d4
leaq 0x7206(%rip), %rax      # 0xc8f8
movq (%rax), %rdi
xorl %esi, %esi
movl %ebp, %edx
movl $0x4, %ecx
movl $0x1, %r8d
movl $0x1, %r9d
pushq $0x8000                 # imm = 0x8000
pushq %r15
pushq %r15
pushq %r15
callq 0x3360
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x58c3
movl 0x24(%rbx), %r10d
subq $0x8, %rsp
movl $0x3, %edi
leaq 0x2c95(%rip), %rsi      # 0x83cf
leaq 0x2e55(%rip), %rdx      # 0x8596
movl $0xab, %ecx
leaq 0x2e65(%rip), %r8       # 0x85b2
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
callq 0x5206
addq $0x10, %rsp
incq %r13
cmpq %r13, %r12
jne 0x56c6
jmp 0x577c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x57b9
movl (%rbx), %edx
leaq 0x7166(%rip), %rax      # 0xc8f0
movl %edx, (%rax)
leaq 0x7165(%rip), %rax      # 0xc8f8
movq (%rax), %rdi
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
callq 0x3500
movl 0x4(%rbx), %edi
callq 0x77ea
movl (%rbx), %edi
callq 0x7750
movq %rbx, %rdi
callq 0x58c3
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7451