// File: /workspace/github_c_makefile_star2_O1/comfies[P]custard/src/xcb/ewmh.c
// Function: initialize_ewmh
unsigned short initialize_ewmh() {
    ewmh_window = xcb_generate_id(xcb_connection);

    unsigned int events[1] = {
        XCB_EVENT_MASK_POINTER_MOTION
    };

    xcb_create_window(xcb_connection, XCB_COPY_FROM_PARENT, ewmh_window,
        xcb_screen->root, 0, 0,
        xcb_screen->width_in_pixels, xcb_screen->height_in_pixels, 0,
        XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT,
        XCB_CW_EVENT_MASK, events);

    ewmh_connection = (xcb_ewmh_connection_t*)calloc(1,
        sizeof(xcb_ewmh_connection_t));

    xcb_intern_atom_cookie_t *initialize_atoms_cookie;
    initialize_atoms_cookie = xcb_ewmh_init_atoms(xcb_connection,
        ewmh_connection);

    if (!xcb_ewmh_init_atoms_replies(ewmh_connection, initialize_atoms_cookie,
        NULL)) {
        log_fatal("Unable to initialize atoms");
        free(ewmh_connection);
        return 0;
    }

    xcb_ewmh_set_wm_pid(ewmh_connection, ewmh_window, getpid());
    xcb_ewmh_set_wm_name(ewmh_connection, ewmh_window, 7, "custard");
    xcb_ewmh_set_supporting_wm_check(ewmh_connection, xcb_screen->root,
        ewmh_window);
    xcb_ewmh_set_supporting_wm_check(ewmh_connection, ewmh_window, ewmh_window);

    xcb_atom_t supported_atoms[] = {
        ewmh_connection->_NET_WM_NAME,
        ewmh_connection->_NET_ACTIVE_WINDOW,
        ewmh_connection->_NET_SUPPORTED,
        ewmh_connection->_NET_SUPPORTING_WM_CHECK,
        ewmh_connection->_NET_WM_PID,
        ewmh_connection->_NET_WM_STATE,
        ewmh_connection->_NET_CLOSE_WINDOW,
        ewmh_connection->_NET_WM_ACTION_CLOSE,
        ewmh_connection->_NET_WM_WINDOW_TYPE,
        ewmh_connection->_NET_WM_WINDOW_TYPE_DOCK,
        ewmh_connection->_NET_WM_WINDOW_TYPE_TOOLBAR,
        ewmh_connection->_NET_WM_WINDOW_TYPE_MENU,
        ewmh_connection->_NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
        ewmh_connection->_NET_WM_WINDOW_TYPE_POPUP_MENU,
        ewmh_connection->_NET_WM_WINDOW_TYPE_DIALOG,
        ewmh_connection->_NET_WM_WINDOW_TYPE_DESKTOP,
        ewmh_connection->_NET_WM_WINDOW_TYPE_SPLASH,
        ewmh_connection->_NET_WM_WINDOW_TYPE_DND,
        ewmh_connection->WM_PROTOCOLS
    };

    xcb_ewmh_set_supported(ewmh_connection, 0,
        sizeof(supported_atoms) / sizeof*(supported_atoms) + 1,
        supported_atoms);

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
leaq 0x5485(%rip), %rbx      # 0xc8f8
movq (%rbx), %rdi
callq 0x3230
movl %eax, 0x5497(%rip)      # 0xc918
leaq 0xc(%rsp), %r10
movl $0x40, (%r10)
movq (%rbx), %rdi
leaq 0x5469(%rip), %r14      # 0xc900
movq (%r14), %rdx
movl (%rdx), %ecx
movzwl 0x14(%rdx), %r11d
movzwl 0x16(%rdx), %r15d
subq $0x8, %rsp
xorl %r12d, %r12d
xorl %esi, %esi
movl %eax, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r10
pushq $0x800                  # imm = 0x800
pushq %r12
pushq $0x1
pushq %r12
pushq %r15
pushq %r11
callq 0x3150
addq $0x40, %rsp
movl $0x1, %edi
movl $0x168, %esi            # imm = 0x168
callq 0x3340
movq %rax, 0x5439(%rip)      # 0xc920
movq (%rbx), %rdi
movq %rax, %rsi
callq 0x31d0
movq 0x5427(%rip), %rdi      # 0xc920
movq %rax, %rsi
xorl %edx, %edx
callq 0x36d0
testb %al, %al
je 0x762b
movq 0x540e(%rip), %rbx      # 0xc920
movl 0x5400(%rip), %ebp      # 0xc918
callq 0x3190
movq %rbx, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x35e0
movq 0x53f0(%rip), %rdi      # 0xc920
movl 0x53e2(%rip), %esi      # 0xc918
leaq 0xea3(%rip), %rcx       # 0x83e0
movl $0x7, %edx
callq 0x3260
movq 0x53d2(%rip), %rdi      # 0xc920
movq (%r14), %rax
movl (%rax), %esi
movl 0x53bf(%rip), %edx      # 0xc918
callq 0x36b0
movq 0x53bb(%rip), %rdi      # 0xc920
movl 0x53ad(%rip), %edx      # 0xc918
movl %edx, %esi
callq 0x36b0
movq 0x53a7(%rip), %rdi      # 0xc920
movl 0x6c(%rdi), %eax
leaq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movl 0x40(%rdi), %eax
movl %eax, 0x4(%rcx)
movl 0x20(%rdi), %eax
movl %eax, 0x8(%rcx)
movl 0x48(%rdi), %eax
movl %eax, 0xc(%rcx)
movl 0x9c(%rdi), %eax
movl %eax, 0x10(%rcx)
movl 0x84(%rdi), %eax
movl %eax, 0x14(%rcx)
movl 0x58(%rdi), %eax
movl %eax, 0x18(%rcx)
movl 0x15c(%rdi), %eax
movl %eax, 0x1c(%rcx)
movl 0x80(%rdi), %eax
movl %eax, 0x20(%rcx)
movl 0xd4(%rdi), %eax
movl %eax, 0x24(%rcx)
movl 0xd8(%rdi), %eax
movl %eax, 0x28(%rcx)
movl 0xdc(%rdi), %eax
movl %eax, 0x2c(%rcx)
movl 0xec(%rdi), %eax
movl %eax, 0x30(%rcx)
movl 0xf0(%rdi), %eax
movl %eax, 0x34(%rcx)
movl 0xe8(%rdi), %eax
movl %eax, 0x38(%rcx)
movl 0xd0(%rdi), %eax
movl %eax, 0x3c(%rcx)
movl 0xe4(%rdi), %eax
movl %eax, 0x40(%rcx)
movl 0x100(%rdi), %eax
movl %eax, 0x44(%rcx)
movl 0xc8(%rdi), %eax
movl %eax, 0x48(%rcx)
xorl %esi, %esi
movl $0x14, %edx
callq 0x3560
movw $0x1, %bx
jmp 0x765f
leaq 0x11e6(%rip), %rsi      # 0x8818
leaq 0x11ee(%rip), %rdx      # 0x8827
leaq 0x11f7(%rip), %r8       # 0x8837
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x22, %ecx
xorl %eax, %eax
callq 0x5206
movq 0x52c6(%rip), %rdi      # 0xc920
callq 0x3060
movl %ebx, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq