// File: /workspace/github_c_makefile_star2_O3/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 0x72ba(%rip), %rbx      # 0xc8f8
movq (%rbx), %rdi
leaq 0x72b8(%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 0x5787
movq %rax, %r14
movq %rax, %rdi
callq 0x32e0
movq %rax, %rbx
movq %r14, %rdi
callq 0x3410
testl %eax, %eax
je 0x5774
movl %eax, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r14d, %r14d
movl (%rbx,%r13,4), %ebp
movl %ebp, %edi
callq 0x6bec
testw %ax, %ax
je 0x5728
movl %ebp, %edi
callq 0x6d80
movq %rax, %r14
movl %ebp, %edi
callq 0x7694
leaq 0x723b(%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 %r12
pushq %r12
pushq %r12
callq 0x3360
addq $0x20, %rsp
movq %r14, %rdi
callq 0x5882
movl 0x24(%r14), %r10d
subq $0x8, %rsp
movl $0x3, %edi
leaq 0x2cc6(%rip), %rsi      # 0x83cb
leaq 0x2e86(%rip), %rdx      # 0x8592
movl $0xab, %ecx
leaq 0x2e96(%rip), %r8       # 0x85ae
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
callq 0x51d6
addq $0x10, %rsp
incq %r13
cmpq %r13, %r15
jne 0x5691
testq %r14, %r14
je 0x5774
movl (%r14), %edx
leaq 0x71ad(%rip), %rax      # 0xc8f0
movl %edx, (%rax)
leaq 0x71ac(%rip), %rax      # 0xc8f8
movq (%rax), %rdi
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
callq 0x3500
movl 0x4(%r14), %edi
callq 0x77aa
movl (%r14), %edi
callq 0x7710
movq %r14, %rdi
callq 0x5882
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x741f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop