// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x60, %rsp
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x31c0
movq %rax, 0x508d(%rip)      # 0xd8f8
cmpq $0x0, 0x5085(%rip)      # 0xd8f8
je 0x8886
movq 0x507c(%rip), %rdi      # 0xd8f8
callq 0x3550
cmpl $0x0, %eax
je 0x88b7
movl $0x1, %edi
leaq 0x1eaa(%rip), %rsi      # 0xa73c
leaq 0x1eb8(%rip), %rdx      # 0xa751
movl $0x12, %ecx
leaq 0x1ebb(%rip), %r8       # 0xa760
movb $0x0, %al
callq 0x5bf0
movw $0x0, -0x2(%rbp)
jmp 0x8a91
movq 0x503a(%rip), %rdi      # 0xd8f8
callq 0x35b0
movq %rax, %rdi
callq 0x3360
movq %rax, -0x18(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x18(%rbp), %rax
movq %rax, 0x5022(%rip)      # 0xd900
movl 0x1f18(%rip), %eax      # 0xa7fc
movl %eax, -0x1c(%rbp)
movq 0x500a(%rip), %rdi      # 0xd8f8
movq 0x500b(%rip), %rax      # 0xd900
movl (%rax), %esi
leaq -0x1c(%rbp), %rcx
movl $0x800, %edx            # imm = 0x800
callq 0x3170
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movq 0x4fe3(%rip), %rdi      # 0xd8f8
movl -0x20(%rbp), %esi
callq 0x3460
cmpq $0x0, %rax
je 0x8954
movl $0x1, %edi
leaq 0x1e0d(%rip), %rsi      # 0xa73c
leaq 0x1e1b(%rip), %rdx      # 0xa751
movl $0x25, %ecx
leaq 0x1e58(%rip), %r8       # 0xa79a
movb $0x0, %al
callq 0x5bf0
movw $0x0, -0x2(%rbp)
jmp 0x8a91
movl -0x1c(%rbp), %eax
xorl $0x10, %eax
movl %eax, -0x1c(%rbp)
movq 0x4f94(%rip), %rdi      # 0xd8f8
movq 0x4f95(%rip), %rax      # 0xd900
movl (%rax), %esi
leaq -0x1c(%rbp), %rcx
movl $0x800, %edx            # imm = 0x800
callq 0x34a0
movl %eax, -0x28(%rbp)
movq 0x4f7b(%rip), %rdi      # 0xd900
callq 0x3590
movq %rax, -0x38(%rbp)
movq %rdx, -0x30(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x89e6
jmp 0x899b
cmpl $0x0, -0x30(%rbp)
je 0x89e4
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x20, %eax
jne 0x89d9
movq -0x38(%rbp), %rdi
callq 0x3660
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq %rax, 0x4f2f(%rip)      # 0xd908
leaq -0x38(%rbp), %rdi
callq 0x30a0
jmp 0x899b
jmp 0x89e6
cmpq $0x0, 0x4f1a(%rip)      # 0xd908
jne 0x8a1e
movl $0x1, %edi
leaq 0x1d40(%rip), %rsi      # 0xa73c
leaq 0x1d4e(%rip), %rdx      # 0xa751
movl $0x42, %ecx
leaq 0x1db9(%rip), %r8       # 0xa7c8
movb $0x0, %al
callq 0x5bf0
movw $0x0, -0x2(%rbp)
jmp 0x8a91
movq 0x4ed3(%rip), %rdi      # 0xd8f8
callq 0x3230
movl %eax, 0x4ee0(%rip)      # 0xd910
movq 0x4ec1(%rip), %rdi      # 0xd8f8
movl 0x4ed3(%rip), %edx      # 0xd910
movq 0x4ebc(%rip), %rax      # 0xd900
movl (%rax), %ecx
movq 0x4ebb(%rip), %rax      # 0xd908
movl (%rax), %r8d
xorl %esi, %esi
callq 0x3690
movl %eax, -0x5c(%rbp)
movq 0x4e97(%rip), %rdi      # 0xd8f8
movq 0x4e98(%rip), %rax      # 0xd900
movl (%rax), %edx
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
callq 0x3620
movl %eax, -0x60(%rbp)
movq 0x4e78(%rip), %rdi      # 0xd8f8
callq 0x30b0
movl %eax, 0x4e89(%rip)      # 0xd914
movw $0x1, -0x2(%rbp)
movw -0x2(%rbp), %ax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)