// File: /workspace/github_c_makefile_star2_O2/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 0x73fa(%rip), %rbx      # 0xc8e8
movq (%rbx), %rdi
leaq 0x73f8(%rip), %rax      # 0xc8f0
movq (%rax), %rax
movl (%rax), %esi
callq 0x3270
movq (%rbx), %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x3330
testq %rax, %rax
je 0x5624
movq %rax, %rbx
movq %rax, %rdi
callq 0x32e0
movq %rax, %r14
movq %rbx, %rdi
callq 0x3400
movl %eax, %ebp
pushq $0x1
popq %r15
xorl %r12d, %r12d
xorl %ebx, %ebx
cmpq %r12, %rbp
je 0x55d4
movl (%r14,%r12,4), %r13d
movl %r13d, %edi
callq 0x67fc
testw %ax, %ax
je 0x55cc
movl %r13d, %edi
callq 0x6976
movq %rax, %rbx
movl %r13d, %edi
callq 0x7244
leaq 0x737c(%rip), %rax      # 0xc8e8
movq (%rax), %rdi
xorl %esi, %esi
movl %r13d, %edx
pushq $0x4
popq %rcx
movl %r15d, %r8d
movl %r15d, %r9d
pushq $0x8000                 # imm = 0x8000
pushq $0x0
pushq $0x0
pushq $0x0
callq 0x3360
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x5726
movl 0x24(%rbx), %r10d
subq $0x8, %rsp
pushq $0x3
popq %rdi
leaq 0x2e20(%rip), %rsi      # 0x83cb
leaq 0x2fe0(%rip), %rdx      # 0x8592
movl $0xab, %ecx
leaq 0x2ff0(%rip), %r8       # 0x85ae
movl %r13d, %r9d
xorl %eax, %eax
pushq %r10
callq 0x50dd
popq %rax
popq %rcx
incq %r12
jmp 0x5538
testq %rbx, %rbx
je 0x5611
movl (%rbx), %edx
leaq 0x72fe(%rip), %rax      # 0xc8e0
movl %edx, (%rax)
leaq 0x72fd(%rip), %rax      # 0xc8e8
movq (%rax), %rdi
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
callq 0x34f0
movl 0x4(%rbx), %edi
callq 0x7348
movl (%rbx), %edi
callq 0x72b8
movq %rbx, %rdi
callq 0x5726
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6fd5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop