#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 void *xcb_gc_t;
typedef int xcb_font_t;
typedef int /*<<< orphan*/ xcb_connection_t;
typedef int uint32_t;

/* Variables and functions */
int XCB_GC_BACKGROUND;
int XCB_GC_FONT;
int XCB_GC_FOREGROUND;
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ testCookie(int /*<<< orphan*/, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ xcb_close_font_checked(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ xcb_create_gc_checked(int /*<<< orphan*/ *, void *,
                                         int /*<<< orphan*/, int, int *);
void *xcb_generate_id(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_open_font_checked(int /*<<< orphan*/ *, int,
                                         int /*<<< orphan*/, char const *);
xcb_gc_t getFontGC(xcb_connection_t *connection, xcb_screen_t *screen,
                   xcb_window_t window, const char *font_name) {
  xcb_font_t font = xcb_generate_id(connection);
  xcb_void_cookie_t fontCookie =
      xcb_open_font_checked(connection, font, strlen(font_name), font_name);
  testCookie(fontCookie, connection, "can't open font");
  xcb_gcontext_t gc = xcb_generate_id(connection);
  uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
  uint32_t value_list[3] = {screen->black_pixel, screen->white_pixel, font};
  xcb_void_cookie_t gcCookie =
      xcb_create_gc_checked(connection, gc, window, mask, value_list);
  testCookie(gcCookie, connection, "can't create gc");
  fontCookie = xcb_close_font_checked(connection, font);
  testCookie(fontCookie, connection, "can't close font");
  return gc;
}


x86 assembly (clang, -O0):
<getFontGC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <xcb_generate_id@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%esi
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
call   1050 <xcb_open_font_checked@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    0xe43(%rip),%rdx
call   1060 <testCookie@plt>
mov    -0x8(%rbp),%rdi
call   1040 <xcb_generate_id@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    0x2df9(%rip),%rcx
or     (%rcx),%eax
mov    0x2de8(%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    -0x24(%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   1070 <xcb_create_gc_checked@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    0xde2(%rip),%rdx
call   1060 <testCookie@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1080 <xcb_close_font_checked@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    0xdd0(%rip),%rdx
call   1060 <testCookie@plt>
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFontGC>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbp
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%rbx
call   1040 <xcb_generate_id@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   1050 <xcb_open_font_checked@plt>
lea    0xe5f(%rip),%rdx
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <testCookie@plt>
mov    %rbx,%rdi
call   1040 <xcb_generate_id@plt>
mov    %rax,%r12
mov    0x2e33(%rip),%rax
mov    0x2e14(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e01(%rip),%rax
or     (%rax),%ecx
mov    0x0(%r13),%eax
mov    %eax,0xc(%rsp)
mov    0x4(%r13),%eax
mov    %eax,0x10(%rsp)
mov    %r14d,0x14(%rsp)
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1070 <xcb_create_gc_checked@plt>
lea    0xe10(%rip),%rdx
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <testCookie@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <xcb_close_font_checked@plt>
lea    0xe04(%rip),%rdx
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <testCookie@plt>
mov    %r12,%rax
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 = [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.1 = [16 x i8] c"can't create gc\00"
@.str.2 = [17 x i8] c"can't close font\00"
define i8* @getFontGC(i32* %0, %struct.TYPE_3__* %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca %struct.TYPE_3__*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [3 x i32]
%14 = alloca i32
store i32* %0, i32** %5
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%15 = load i32*, i32** %5
%16 = call i8* @xcb_generate_id(i32* %15)
%17 = ptrtoint i8* %16 to i32
store i32 %17, i32* %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %9
%20 = load i8*, i8** %8
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %8
%23 = call i32 @xcb_open_font_checked(i32* %18, i32 %19, i32 %21, i8* %22)
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, i64 0, i64 0))
%27 = load i32*, i32** %5
%28 = call i8* @xcb_generate_id(i32* %27)
store i8* %28, i8** %11
%29 = load i32, i32* @XCB_GC_FOREGROUND
%30 = load i32, i32* @XCB_GC_BACKGROUND
%31 = or i32 %29, %30
%32 = load i32, i32* @XCB_GC_FONT
%33 = or i32 %31, %32
store i32 %33, i32* %12
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%35 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
%37 = load i32, i32* %36
store i32 %37, i32* %34
%38 = getelementptr inbounds i32, i32* %34, i64 1
%39 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %39, i32 0, i32 1
%41 = load i32, i32* %40
store i32 %41, i32* %38
%42 = getelementptr inbounds i32, i32* %38, i64 1
%43 = load i32, i32* %9
store i32 %43, i32* %42
%44 = load i32*, i32** %5
%45 = load i8*, i8** %11
%46 = load i32, i32* %7
%47 = load i32, i32* %12
%48 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%49 = call i32 @xcb_create_gc_checked(i32* %44, i8* %45, i32 %46, i32 %47, i32* %48)
store i32 %49, i32* %14
%50 = load i32, i32* %14
%51 = load i32*, i32** %5
%52 = call i32 @testCookie(i32 %50, i32* %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%53 = load i32*, i32** %5
%54 = load i32, i32* %9
%55 = call i32 @xcb_close_font_checked(i32* %53, i32 %54)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = load i32*, i32** %5
%58 = call i32 @testCookie(i32 %56, i32* %57, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%59 = load i8*, i8** %11
ret i8* %59
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [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.1 = [16 x i8] c"can't create gc\00"
@.str.2 = [17 x i8] c"can't close font\00"
define i8* @getFontGC(i32* %0, %struct.TYPE_3__* nocapture %1, i32 %2, i8* %3) {
%5 = alloca [3 x i32]
%6 = tail call i8* @xcb_generate_id(i32* %0)
%7 = ptrtoint i8* %6 to i64
%8 = trunc i64 %7 to i32
%9 = tail call i32 @strlen(i8* %3)
%10 = tail call i32 @xcb_open_font_checked(i32* %0, i32 %8, i32 %9, i8* %3)
%11 = tail call i32 @testCookie(i32 %10, i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = tail call i8* @xcb_generate_id(i32* %0)
%13 = load i32, i32* @XCB_GC_FOREGROUND
%14 = load i32, i32* @XCB_GC_BACKGROUND
%15 = or i32 %14, %13
%16 = load i32, i32* @XCB_GC_FONT
%17 = or i32 %15, %16
%18 = bitcast [3 x i32]* %5 to i8*
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%21 = load i32, i32* %20
store i32 %21, i32* %19
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%24 = load i32, i32* %23
store i32 %24, i32* %22
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
store i32 %8, i32* %25
%26 = call i32 @xcb_create_gc_checked(i32* %0, i8* %12, i32 %2, i32 %17, i32* %19)
%27 = call i32 @testCookie(i32 %26, i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @xcb_close_font_checked(i32* %0, i32 %8)
%29 = call i32 @testCookie(i32 %28, i32* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
ret i8* %12
}