// File: /workspace/github_c_makefile_star2_O3/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 0x5039(%rip), %r15      # 0xc8f8
movq (%r15), %rdi
leaq 0x5057(%rip), %r12      # 0xc920
movq (%r12), %rax
movl 0xc8(%rax), %edx
movl %ebx, %esi
callq 0x3100
movl %eax, %ebp
movq (%r15), %rdi
leaq 0x10b0(%rip), %rcx      # 0x8996
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 0x7938
movl 0x8(%rsp), %ecx
testq %rcx, %rcx
je 0x7938
movq 0x10(%rsp), %rdx
movl 0x8(%rax), %eax
xorl %esi, %esi
cmpl %eax, (%rdx,%rsi,4)
je 0x7982
incq %rsi
cmpq %rsi, %rcx
jne 0x792b
leaq 0x8(%rsp), %rdi
callq 0x30f0
movq (%r15), %rdi
movl %ebx, %esi
callq 0x3690
leaq 0xf6d(%rip), %rsi       # 0x88c0
leaq 0x104d(%rip), %rdx      # 0x89a7
leaq 0x1075(%rip), %r8       # 0x89d6
movl $0x3, %edi
movl $0x6e, %ecx
movl %ebx, %r9d
xorl %eax, %eax
callq 0x51d6
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, 0x10(%r8)
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 0xef5(%rip), %rsi       # 0x88c0
leaq 0xfd5(%rip), %rdx       # 0x89a7
leaq 0xfdb(%rip), %r8        # 0x89b4
movl $0x3, %edi
movl $0x65, %ecx
jmp 0x796b