// File: /workspace/github_c_makefile_star2_O2/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 0x5504(%rip), %r15      # 0xc8e8
movq (%r15), %rdi
leaq 0x5522(%rip), %r12      # 0xc910
movq (%r12), %rax
movl 0xc8(%rax), %edx
movl %ebx, %esi
callq 0x3100
movl %eax, %ebp
movq (%r15), %rdi
leaq 0x157b(%rip), %rcx      # 0x8986
pushq $0x10
popq %rdx
xorl %esi, %esi
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 0x34b0
testq %rax, %rax
je 0x74b4
movl 0x8(%rsp), %ecx
movq 0x10(%rsp), %rdx
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x74b4
movl (%rdx,%rdi,4), %esi
incq %rdi
cmpl 0x8(%rax), %esi
jne 0x7446
leaq 0x20(%rsp), %r8
movl $0x2021, (%r8)          # imm = 0x2021
movl %ebx, 0x4(%r8)
movq (%r12), %rax
movl 0xc8(%rax), %eax
movl %eax, 0x8(%r8)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r8)
movl %esi, 0xc(%r8)
movq (%r15), %rdi
xorl %esi, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x3560
leaq 0x8(%rsp), %rdi
callq 0x30f0
leaq 0x1411(%rip), %rsi      # 0x88b0
leaq 0x14f1(%rip), %rdx      # 0x8997
leaq 0x14f7(%rip), %r8       # 0x89a4
pushq $0x3
popq %rdi
pushq $0x65
jmp 0x74e2
leaq 0x8(%rsp), %rdi
callq 0x30f0
movq (%r15), %rdi
movl %ebx, %esi
callq 0x3680
leaq 0x13e1(%rip), %rsi      # 0x88b0
leaq 0x14c1(%rip), %rdx      # 0x8997
leaq 0x14e9(%rip), %r8       # 0x89c6
pushq $0x3
popq %rdi
pushq $0x6e
popq %rcx
movl %ebx, %r9d
xorl %eax, %eax
callq 0x50dd
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq