// File: /workspace/github_c_makefile_star2_O1/comfies[P]custard/src/xcb/connection.c
// Function: initialize_xcb
unsigned short initialize_xcb() {
    xcb_connection = xcb_connect(NULL, NULL);

    if (!xcb_connection || xcb_connection_has_error(xcb_connection)) {
        log_fatal("Unable to create XCB connection; is the X server running?");
        return 0;
    }

    xcb_screen = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data;

    unsigned int events[1] = {
        XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
        XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY   |
        XCB_EVENT_MASK_BUTTON_PRESS          |
        XCB_EVENT_MASK_ENTER_WINDOW          |
        XCB_EVENT_MASK_PROPERTY_CHANGE
    };

    xcb_void_cookie_t window_attributes_cookie;
    window_attributes_cookie = xcb_change_window_attributes(xcb_connection,
        xcb_screen->root, XCB_CW_EVENT_MASK, events);

    if (xcb_request_check(xcb_connection, window_attributes_cookie)) {
        log_fatal("It appears another window manager is running.");
        return 0;
    }

    events[0] ^= XCB_EVENT_MASK_ENTER_WINDOW;

    xcb_change_window_attributes_checked(xcb_connection, xcb_screen->root,
        XCB_CW_EVENT_MASK, events);

    xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(
        xcb_screen);

    if (depth_iterator.data) {
        xcb_visualtype_iterator_t visual_iterator;

        while (depth_iterator.rem) {

            if (depth_iterator.data->depth == 32) {
                visual_iterator = xcb_depth_visuals_iterator(
                    depth_iterator.data);

                screen_visual = visual_iterator.data;
            }

            xcb_depth_next(&depth_iterator);
        }
    }

    if (!screen_visual) {
        log_fatal("Unable to obtain a screen visual with depth of 32");
        return 0;
    }

    screen_colormap = xcb_generate_id(xcb_connection);
    xcb_create_colormap(xcb_connection, XCB_COLORMAP_ALLOC_NONE,
        screen_colormap, xcb_screen->root, screen_visual->visual_id);

    xcb_ungrab_key(xcb_connection, XCB_GRAB_ANY, xcb_screen->root,
        XCB_MOD_MASK_ANY);

    xcb_file_descriptor = xcb_get_file_descriptor(xcb_connection);

    return 1;
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
xorl %edi, %edi
xorl %esi, %esi
callq 0x31c0
movq %rax, 0x566f(%rip)      # 0xc8f8
testq %rax, %rax
je 0x729a
movq %rax, %rdi
callq 0x3540
testl %eax, %eax
je 0x72ca
leaq 0x14b9(%rip), %rsi      # 0x875a
leaq 0x14c7(%rip), %rdx      # 0x876f
leaq 0x14cf(%rip), %r8       # 0x877e
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x12, %ecx
xorl %eax, %eax
callq 0x5206
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
retq
movq 0x5627(%rip), %rdi      # 0xc8f8
callq 0x35a0
movq %rax, %rdi
callq 0x3350
movq %rax, 0x561b(%rip)      # 0xc900
leaq 0xc(%rsp), %rcx
movl $0x580014, (%rcx)       # imm = 0x580014
movq 0x5601(%rip), %rdi      # 0xc8f8
movl (%rax), %esi
movl $0x800, %edx            # imm = 0x800
callq 0x3170
movq 0x55ee(%rip), %rdi      # 0xc8f8
movl %eax, %esi
callq 0x3450
testq %rax, %rax
je 0x7339
leaq 0x143d(%rip), %rsi      # 0x875a
leaq 0x144b(%rip), %rdx      # 0x876f
leaq 0x148d(%rip), %r8       # 0x87b8
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x25, %ecx
jmp 0x72bb
leaq 0xc(%rsp), %rcx
xorb $0x10, (%rcx)
movq 0x55b0(%rip), %rdi      # 0xc8f8
movq 0x55b1(%rip), %rax      # 0xc900
movl (%rax), %esi
movl $0x800, %edx            # imm = 0x800
callq 0x3490
movq 0x559e(%rip), %rdi      # 0xc900
callq 0x3580
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
testq %rax, %rax
je 0x73a4
testl %edx, %edx
je 0x73a4
leaq 0x10(%rsp), %rbx
movq 0x10(%rsp), %rdi
cmpb $0x20, (%rdi)
jne 0x7395
callq 0x3650
movq %rax, 0x5573(%rip)      # 0xc908
movq %rbx, %rdi
callq 0x30a0
cmpl $0x0, 0x18(%rsp)
jne 0x737f
cmpq $0x0, 0x555c(%rip)      # 0xc908
je 0x741a
movq 0x5543(%rip), %rdi      # 0xc8f8
callq 0x3230
movl %eax, 0x5550(%rip)      # 0xc910
movq 0x5531(%rip), %rdi      # 0xc8f8
movq 0x5532(%rip), %rcx      # 0xc900
movl (%rcx), %ecx
movq 0x5531(%rip), %rdx      # 0xc908
movl (%rdx), %r8d
xorl %esi, %esi
movl %eax, %edx
callq 0x3680
movq 0x550e(%rip), %rdi      # 0xc8f8
movq 0x550f(%rip), %rax      # 0xc900
movl (%rax), %edx
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
callq 0x3610
movq 0x54f2(%rip), %rdi      # 0xc8f8
callq 0x30b0
movl %eax, 0x5503(%rip)      # 0xc914
movw $0x1, %bx
jmp 0x72c2
leaq 0x1339(%rip), %rsi      # 0x875a
leaq 0x1347(%rip), %rdx      # 0x876f
leaq 0x13b7(%rip), %r8       # 0x87e6
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x42, %ecx
jmp 0x72bb