// File: /workspace/github_c_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x90, %rsp
leaq 0x58f2(%rip), %rbx      # 0xc8e8
movq (%rbx), %rdi
callq 0x3230
movl %eax, 0x5904(%rip)      # 0xc908
leaq 0x3c(%rsp), %rdx
movl $0x40, (%rdx)
movq (%rbx), %rdi
leaq 0x58d7(%rip), %r14      # 0xc8f0
movq (%r14), %rsi
movl (%rsi), %ecx
movzwl 0x14(%rsi), %r8d
movzwl 0x16(%rsi), %esi
movq %rdx, 0x30(%rsp)
movl %esi, 0x8(%rsp)
andl $0x0, 0x20(%rsp)
movl %r8d, (%rsp)
andl $0x0, 0x10(%rsp)
movl $0x800, 0x28(%rsp)      # imm = 0x800
movl $0x1, 0x18(%rsp)
xorl %esi, %esi
movl %eax, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3150
pushq $0x1
popq %rdi
movl $0x168, %esi            # imm = 0x168
callq 0x3340
movq %rax, 0x589f(%rip)      # 0xc910
movq (%rbx), %rdi
movq %rax, %rsi
callq 0x31d0
movq 0x588d(%rip), %rdi      # 0xc910
movq %rax, %rsi
xorl %edx, %edx
callq 0x36c0
testb %al, %al
je 0x71a4
movq 0x5874(%rip), %rbx      # 0xc910
movl 0x5866(%rip), %ebp      # 0xc908
callq 0x3190
movq %rbx, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x35d0
movq 0x5856(%rip), %rdi      # 0xc910
movl 0x5848(%rip), %esi      # 0xc908
leaq 0x1315(%rip), %rcx      # 0x83dc
pushq $0x7
popq %rdx
callq 0x3260
movq 0x583a(%rip), %rdi      # 0xc910
movq (%r14), %rax
movl (%rax), %esi
movl 0x5827(%rip), %edx      # 0xc908
callq 0x36a0
movq 0x5823(%rip), %rdi      # 0xc910
movl 0x5815(%rip), %edx      # 0xc908
movl %edx, %esi
callq 0x36a0
movq 0x580f(%rip), %rdi      # 0xc910
movl 0x6c(%rdi), %eax
leaq 0x40(%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)
movsd 0xec(%rdi), %xmm0
movsd 0xd8(%rdi), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movups %xmm1, 0x28(%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)
pushq $0x14
popq %rdx
xorl %esi, %esi
callq 0x3550
movw $0x1, %bx
jmp 0x71d4
leaq 0x16cb(%rip), %rsi      # 0x8876
leaq 0x16d3(%rip), %rdx      # 0x8885
leaq 0x16dc(%rip), %r8       # 0x8895
xorl %ebx, %ebx
pushq $0x1
popq %rdi
pushq $0x22
popq %rcx
xorl %eax, %eax
callq 0x50dd
movq 0x5741(%rip), %rdi      # 0xc910
callq 0x3060
movl %ebx, %eax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq