#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ xcb_window_t;
typedef int /*<<< orphan*/ xcb_void_cookie_t;
struct TYPE_3__ {
  int black_pixel;
  int white_pixel;
};
typedef TYPE_1__ xcb_screen_t;
typedef void *xcb_gcontext_t;
typedef int xcb_font_t;
typedef int xcb_cursor_t;
typedef int /*<<< orphan*/ xcb_connection_t;
typedef int uint32_t;

/* Variables and functions */
int XCB_CW_CURSOR;
int XCB_GC_BACKGROUND;
int XCB_GC_FONT;
int XCB_GC_FOREGROUND;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ testCookie(int /*<<< orphan*/, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ xcb_change_window_attributes(int /*<<< orphan*/ *,
                                                int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ xcb_close_font_checked(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ xcb_create_gc_checked(int /*<<< orphan*/ *, void *,
                                         int /*<<< orphan*/, int, int *);
int /*<<< orphan*/
xcb_create_glyph_cursor(int /*<<< orphan*/ *, int, int, int, int, int,
                        int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ xcb_free_cursor(int /*<<< orphan*/ *, int);
void *xcb_generate_id(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_open_font_checked(int /*<<< orphan*/ *, int,
                                         int /*<<< orphan*/, char *);
void setCursor(xcb_connection_t *connection, xcb_screen_t *screen,
               xcb_window_t window, int cursorId) {
  xcb_font_t font = xcb_generate_id(connection);
  xcb_void_cookie_t fontCookie =
      xcb_open_font_checked(connection, font, strlen("cursor"), "cursor");
  testCookie(fontCookie, connection, "can't open font");
  xcb_cursor_t cursor = xcb_generate_id(connection);
  xcb_create_glyph_cursor(connection, cursor, font, font, cursorId,
                          cursorId + 1, 0, 0, 0, 0, 0, 0);
  xcb_gcontext_t gc = xcb_generate_id(connection);
  uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
  uint32_t values_list[3];
  values_list[0] = screen->black_pixel;
  values_list[1] = screen->white_pixel;
  values_list[2] = font;
  xcb_void_cookie_t gcCookie =
      xcb_create_gc_checked(connection, gc, window, mask, values_list);
  testCookie(gcCookie, connection, "can't create gc");
  mask = XCB_CW_CURSOR;
  uint32_t value_list = cursor;
  xcb_change_window_attributes(connection, window, mask, &value_list);
  xcb_free_cursor(connection, cursor);
  fontCookie = xcb_close_font_checked(connection, font);
  testCookie(fontCookie, connection, "can't close font");
}


x86 assembly (clang, -O0):
<setCursor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <xcb_generate_id@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    0xe36(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    %eax,%edx
lea    0xe21(%rip),%rcx
call   1060 <xcb_open_font_checked@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    0xe12(%rip),%rdx
call   1080 <testCookie@plt>
mov    -0x8(%rbp),%rdi
call   1050 <xcb_generate_id@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x18(%rbp),%r9d
add    $0x1,%r9d
xor    %eax,%eax
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
call   10b0 <xcb_create_glyph_cursor@plt>
mov    -0x8(%rbp),%rdi
call   1050 <xcb_generate_id@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    0x2d5e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    -0x40(%rbp),%r8
call   1090 <xcb_create_gc_checked@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    0xd56(%rip),%rdx
call   1080 <testCookie@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    -0x48(%rbp),%rcx
call   1030 <xcb_change_window_attributes@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <xcb_free_cursor@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <xcb_close_font_checked@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    0xd13(%rip),%rdx
call   1080 <testCookie@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setCursor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,0x4(%rsp)
mov    %rsi,%r12
mov    %rdi,%rbx
call   1050 <xcb_generate_id@plt>
mov    %rax,%r14
lea    0xe46(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   1060 <xcb_open_font_checked@plt>
lea    0xe2e(%rip),%rdx
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <testCookie@plt>
mov    %rbx,%rdi
call   1050 <xcb_generate_id@plt>
mov    %rax,%r13
lea    0x1(%r15),%r9d
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
call   10b0 <xcb_create_glyph_cursor@plt>
add    $0x30,%rsp
mov    %rbx,%rdi
call   1050 <xcb_generate_id@plt>
mov    0x2dcb(%rip),%rdx
mov    0x2da4(%rip),%rcx
mov    (%rcx),%ecx
or     (%rdx),%ecx
mov    0x2d91(%rip),%rdx
or     (%rdx),%ecx
mov    (%r12),%edx
mov    %edx,0xc(%rsp)
mov    0x4(%r12),%edx
mov    %edx,0x10(%rsp)
mov    %r14d,0x14(%rsp)
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
mov    %rax,%rsi
mov    0x4(%rsp),%ebp
mov    %ebp,%edx
call   1090 <xcb_create_gc_checked@plt>
lea    0xdab(%rip),%rdx
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <testCookie@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    %r13d,0x8(%rsp)
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <xcb_change_window_attributes@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1070 <xcb_free_cursor@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   10a0 <xcb_close_font_checked@plt>
lea    0xd77(%rip),%rdx
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <testCookie@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [7 x i8] c"cursor\00"
@.str.1 = [16 x i8] c"can't open font\00"
@XCB_GC_FOREGROUND = global i32 0
@XCB_GC_BACKGROUND = global i32 0
@XCB_GC_FONT = global i32 0
@.str.2 = [16 x i8] c"can't create gc\00"
@XCB_CW_CURSOR = global i32 0
@.str.3 = [17 x i8] c"can't close font\00"
define void @setCursor(i32* %0, %struct.TYPE_3__* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca %struct.TYPE_3__*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [3 x i32]
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %5
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%17 = load i32*, i32** %5
%18 = call i8* @xcb_generate_id(i32* %17)
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %9
%20 = load i32*, i32** %5
%21 = load i32, i32* %9
%22 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @xcb_open_font_checked(i32* %20, i32 %21, i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = load i32*, i32** %5
%26 = call i32 @testCookie(i32 %24, i32* %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32*, i32** %5
%28 = call i8* @xcb_generate_id(i32* %27)
%29 = ptrtoint i8* %28 to i32
store i32 %29, i32* %11
%30 = load i32*, i32** %5
%31 = load i32, i32* %11
%32 = load i32, i32* %9
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
%37 = call i32 @xcb_create_glyph_cursor(i32* %30, i32 %31, i32 %32, i32 %33, i32 %34, i32 %36, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
%38 = load i32*, i32** %5
%39 = call i8* @xcb_generate_id(i32* %38)
store i8* %39, i8** %12
%40 = load i32, i32* @XCB_GC_FOREGROUND
%41 = load i32, i32* @XCB_GC_BACKGROUND
%42 = or i32 %40, %41
%43 = load i32, i32* @XCB_GC_FONT
%44 = or i32 %42, %43
store i32 %44, i32* %13
%45 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds [3 x i32], [3 x i32]* %14, i64 0, i64 0
store i32 %47, i32* %48
%49 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds [3 x i32], [3 x i32]* %14, i64 0, i64 1
store i32 %51, i32* %52
%53 = load i32, i32* %9
%54 = getelementptr inbounds [3 x i32], [3 x i32]* %14, i64 0, i64 2
store i32 %53, i32* %54
%55 = load i32*, i32** %5
%56 = load i8*, i8** %12
%57 = load i32, i32* %7
%58 = load i32, i32* %13
%59 = getelementptr inbounds [3 x i32], [3 x i32]* %14, i64 0, i64 0
%60 = call i32 @xcb_create_gc_checked(i32* %55, i8* %56, i32 %57, i32 %58, i32* %59)
store i32 %60, i32* %15
%61 = load i32, i32* %15
%62 = load i32*, i32** %5
%63 = call i32 @testCookie(i32 %61, i32* %62, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%64 = load i32, i32* @XCB_CW_CURSOR
store i32 %64, i32* %13
%65 = load i32, i32* %11
store i32 %65, i32* %16
%66 = load i32*, i32** %5
%67 = load i32, i32* %7
%68 = load i32, i32* %13
%69 = call i32 @xcb_change_window_attributes(i32* %66, i32 %67, i32 %68, i32* %16)
%70 = load i32*, i32** %5
%71 = load i32, i32* %11
%72 = call i32 @xcb_free_cursor(i32* %70, i32 %71)
%73 = load i32*, i32** %5
%74 = load i32, i32* %9
%75 = call i32 @xcb_close_font_checked(i32* %73, i32 %74)
store i32 %75, i32* %10
%76 = load i32, i32* %10
%77 = load i32*, i32** %5
%78 = call i32 @testCookie(i32 %76, i32* %77, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [7 x i8] c"cursor\00"
@.str.1 = [16 x i8] c"can't open font\00"
@XCB_GC_FOREGROUND = global i32 0
@XCB_GC_BACKGROUND = global i32 0
@XCB_GC_FONT = global i32 0
@.str.2 = [16 x i8] c"can't create gc\00"
@XCB_CW_CURSOR = global i32 0
@.str.3 = [17 x i8] c"can't close font\00"
define void @setCursor(i32* %0, %struct.TYPE_3__* nocapture %1, i32 %2, i32 %3) {
%5 = alloca [3 x i32]
%6 = alloca i32
%7 = tail call i8* @xcb_generate_id(i32* %0)
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i32
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @xcb_open_font_checked(i32* %0, i32 %9, i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @testCookie(i32 %11, i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i8* @xcb_generate_id(i32* %0)
%14 = ptrtoint i8* %13 to i64
%15 = trunc i64 %14 to i32
%16 = add nsw i32 %3, 1
%17 = tail call i32 @xcb_create_glyph_cursor(i32* %0, i32 %15, i32 %9, i32 %9, i32 %3, i32 %16, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
%18 = tail call i8* @xcb_generate_id(i32* %0)
%19 = load i32, i32* @XCB_GC_FOREGROUND
%20 = load i32, i32* @XCB_GC_BACKGROUND
%21 = or i32 %20, %19
%22 = load i32, i32* @XCB_GC_FONT
%23 = or i32 %21, %22
%24 = bitcast [3 x i32]* %5 to i8*
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
store i32 %29, i32* %30
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
store i32 %9, i32* %31
%32 = call i32 @xcb_create_gc_checked(i32* %0, i8* %18, i32 %2, i32 %23, i32* %27)
%33 = call i32 @testCookie(i32 %32, i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @XCB_CW_CURSOR
%35 = bitcast i32* %6 to i8*
store i32 %15, i32* %6
%36 = call i32 @xcb_change_window_attributes(i32* %0, i32 %2, i32 %34, i32* %6)
%37 = call i32 @xcb_free_cursor(i32* %0, i32 %15)
%38 = call i32 @xcb_close_font_checked(i32* %0, i32 %9)
%39 = call i32 @testCookie(i32 %38, i32* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
ret void
}