// File: /workspace/github_c_makefile_star2_O1/comfies[P]custard/src/xcb/window.c
// Function: close_window
void close_window(xcb_window_t window_id) {
    xcb_get_property_cookie_t protocols_cookie;
    protocols_cookie = xcb_icccm_get_wm_protocols(xcb_connection, window_id,
        ewmh_connection->WM_PROTOCOLS);

    xcb_intern_atom_cookie_t delete_cookie;
    delete_cookie = xcb_intern_atom(xcb_connection, 0, 16, "WM_DELETE_WINDOW");

    xcb_icccm_get_wm_protocols_reply_t protocols;
    xcb_icccm_get_wm_protocols_reply(xcb_connection, protocols_cookie,
        &protocols, NULL);

    xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(xcb_connection,
        delete_cookie, NULL);

    if (reply) {
        for (unsigned int index = 0; index < protocols.atoms_len; index++) {
            if (protocols.atoms[index] == reply->atom) {

                xcb_client_message_event_t event = {
                    .response_type = XCB_CLIENT_MESSAGE,
                    .format        = 32,
                    .sequence      = 0,
                    .window        = window_id,
                    .type          = ewmh_connection->WM_PROTOCOLS,
                    .data.data32   = {
                        reply->atom, XCB_CURRENT_TIME
                    }
                };

                xcb_send_event(xcb_connection, 0, window_id,
                    XCB_EVENT_MASK_NO_EVENT, (char*)&event);
                xcb_icccm_get_wm_protocols_reply_wipe(&protocols);

                log_debug("Window(%08x) closed(WM_PROTOCOLS)", window_id);
                return;
            }
        }
    }

    xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
    xcb_kill_client(xcb_connection, window_id);

    log_debug("Window(%08x) closed(xcb_kill_client)", window_id);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl %edi, %ebx
leaq 0x4ff9(%rip), %r15      # 0xc8f8
movq (%r15), %rdi
leaq 0x5017(%rip), %r12      # 0xc920
movq (%r12), %rax
movl 0xc8(%rax), %edx
movl %ebx, %esi
callq 0x3100
movl %eax, %ebp
movq (%r15), %rdi
leaq 0x1002(%rip), %rcx      # 0x8928
xorl %esi, %esi
movl $0x10, %edx
callq 0x32d0
movl %eax, %r14d
movq (%r15), %rdi
leaq 0x8(%rsp), %rdx
movl %ebp, %esi
xorl %ecx, %ecx
callq 0x31b0
movq (%r15), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x34c0
testq %rax, %rax
je 0x7977
movl 0x8(%rsp), %ecx
testq %rcx, %rcx
je 0x7977
movq 0x10(%rsp), %rdx
movl 0x8(%rax), %esi
xorl %edi, %edi
cmpl %esi, (%rdx,%rdi,4)
je 0x79c1
incq %rdi
cmpl %edi, %ecx
jne 0x796b
leaq 0x8(%rsp), %rdi
callq 0x30f0
movq (%r15), %rdi
movl %ebx, %esi
callq 0x3690
leaq 0xec0(%rip), %rsi       # 0x8852
leaq 0xfa0(%rip), %rdx       # 0x8939
leaq 0xfc8(%rip), %r8        # 0x8968
movl $0x3, %edi
movl $0x6e, %ecx
movl %ebx, %r9d
xorl %eax, %eax
callq 0x5206
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %r8
movl $0x2021, (%r8)          # imm = 0x2021
movl %ebx, 0x4(%r8)
movq (%r12), %rcx
movl 0xc8(%rcx), %ecx
movl %ecx, 0x8(%r8)
xorps %xmm0, %xmm0
movups %xmm0, 0xc(%r8)
movl $0x0, 0x1c(%r8)
movl 0x8(%rax), %eax
movl %eax, 0xc(%r8)
movq (%r15), %rdi
xorl %esi, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x3570
leaq 0x8(%rsp), %rdi
callq 0x30f0
leaq 0xe3d(%rip), %rsi       # 0x8852
leaq 0xf1d(%rip), %rdx       # 0x8939
leaq 0xf23(%rip), %r8        # 0x8946
movl $0x3, %edi
movl $0x65, %ecx
jmp 0x79aa