#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ root;
  int /*<<< orphan*/ height_in_pixels;
  int /*<<< orphan*/ width_in_pixels;
};
typedef TYPE_1__ xcb_screen_t;
typedef int /*<<< orphan*/ xcb_rectangle_t;
typedef int /*<<< orphan*/ xcb_gcontext_t;
typedef int /*<<< orphan*/ xcb_connection_t;
typedef scalar_t__ uint32_t;
struct TYPE_5__ {
  TYPE_1__ *data;
};

/* Variables and functions */
int /*<<< orphan*/ XCB_GC_FOREGROUND;
int /*<<< orphan*/ create_rectangles(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ lookup_color(int /*<<< orphan*/ *, TYPE_1__ *, char *,
                                scalar_t__ *);
int /*<<< orphan*/ *xcb_connect(char const *, int /*<<< orphan*/ *);
scalar_t__ xcb_connection_has_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_create_gc(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                 int /*<<< orphan*/, int /*<<< orphan*/,
                                 scalar_t__ *);
int /*<<< orphan*/ xcb_disconnect(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_generate_id(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_get_setup(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_poly_fill_rectangle_checked(int /*<<< orphan*/ *,
                                                   int /*<<< orphan*/,
                                                   int /*<<< orphan*/, int,
                                                   int /*<<< orphan*/ *);
TYPE_2__ xcb_setup_roots_iterator(int /*<<< orphan*/);
int xcb_draw_grid(const char *display) {
  uint32_t pixels[2];
  xcb_connection_t *c;
  xcb_screen_t *screen;
  xcb_gcontext_t red_fg;
  xcb_gcontext_t green_fg;
  xcb_rectangle_t red_rectangles[32];
  xcb_rectangle_t green_rectangles[32];
  c = xcb_connect(display, NULL);
  if (xcb_connection_has_error(c))
    return 1;
  screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
  red_fg = xcb_generate_id(c);
  lookup_color(c, screen, "red", &pixels[0]);
  pixels[1] = 0;
  xcb_create_gc(c, red_fg, screen->root, XCB_GC_FOREGROUND, pixels);
  green_fg = xcb_generate_id(c);
  lookup_color(c, screen, "green", &pixels[0]);
  pixels[1] = 0;
  xcb_create_gc(c, green_fg, screen->root, XCB_GC_FOREGROUND, pixels);
  create_rectangles(red_rectangles, green_rectangles, screen->width_in_pixels,
                    screen->height_in_pixels);
  xcb_poly_fill_rectangle_checked(c, screen->root, red_fg, 32, red_rectangles);
  xcb_poly_fill_rectangle_checked(c, screen->root, green_fg, 32,
                                  green_rectangles);
  xcb_flush(c);
  xcb_disconnect(c);
  return 0;
}


x86 assembly (clang, -O0):
<xcb_draw_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <xcb_connect@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <xcb_connection_has_error@plt>
cmp    $0x0,%rax
je     11ef <xcb_draw_grid+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    131d <xcb_draw_grid+0x16d>
mov    -0x28(%rbp),%rdi
call   10c0 <xcb_get_setup@plt>
mov    %eax,%edi
call   1080 <xcb_setup_roots_iterator@plt>
mov    %rax,-0x148(%rbp)
mov    -0x148(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <xcb_generate_id@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rcx
lea    0xdd0(%rip),%rdx
call   1030 <lookup_color@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    0x2d9f(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%r8
call   1050 <xcb_create_gc@plt>
mov    -0x28(%rbp),%rdi
call   1070 <xcb_generate_id@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rcx
lea    0xd89(%rip),%rdx
call   1030 <lookup_color@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    0x2d54(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%r8
call   1050 <xcb_create_gc@plt>
lea    -0xc0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%ecx
call   10b0 <create_rectangles@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    -0x34(%rbp),%edx
lea    -0xc0(%rbp),%r8
mov    $0x20,%ecx
call   10d0 <xcb_poly_fill_rectangle_checked@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%edx
lea    -0x140(%rbp),%r8
mov    $0x20,%ecx
call   10d0 <xcb_poly_fill_rectangle_checked@plt>
mov    -0x28(%rbp),%rdi
call   1060 <xcb_flush@plt>
mov    -0x28(%rbp),%rdi
call   1090 <xcb_disconnect@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_draw_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xor    %esi,%esi
call   1040 <xcb_connect@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <xcb_connection_has_error@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    12d7 <xcb_draw_grid+0x127>
mov    %rbx,%rdi
call   10c0 <xcb_get_setup@plt>
mov    %eax,%edi
call   1080 <xcb_setup_roots_iterator@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <xcb_generate_id@plt>
mov    %eax,%r15d
lea    0xdf8(%rip),%rdx
mov    %rsp,%r12
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rcx
call   1030 <lookup_color@plt>
movq   $0x0,0x8(%rsp)
mov    (%r14),%edx
mov    0x2dc4(%rip),%r13
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%r8
call   1050 <xcb_create_gc@plt>
mov    %rbx,%rdi
call   1070 <xcb_generate_id@plt>
mov    %eax,%ebp
lea    0xdb5(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rcx
call   1030 <lookup_color@plt>
movq   $0x0,0x8(%rsp)
mov    (%r14),%edx
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%r8
call   1050 <xcb_create_gc@plt>
mov    0x4(%r14),%ecx
mov    0x8(%r14),%edx
lea    0x90(%rsp),%r12
lea    0x10(%rsp),%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   10b0 <create_rectangles@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    $0x20,%ecx
mov    %r12,%r8
call   10d0 <xcb_poly_fill_rectangle_checked@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
mov    %ebp,%edx
mov    $0x20,%ecx
mov    %r13,%r8
call   10d0 <xcb_poly_fill_rectangle_checked@plt>
mov    %rbx,%rdi
call   1060 <xcb_flush@plt>
mov    %rbx,%rdi
call   1090 <xcb_disconnect@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32 }
%struct.TYPE_5__ = type { %struct.TYPE_4__* }
@.str = [4 x i8] c"red\00"
@XCB_GC_FOREGROUND = global i32 0
@.str.1 = [6 x i8] c"green\00"
define i32 @xcb_draw_grid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2 x i64]
%5 = alloca i32*
%6 = alloca %struct.TYPE_4__*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i32]
%10 = alloca [32 x i32]
%11 = alloca %struct.TYPE_5__
store i8* %0, i8** %3
%12 = load i8*, i8** %3
%13 = call i32* @xcb_connect(i8* %12, i32* null)
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = call i64 @xcb_connection_has_error(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 1, i32* %2
br label %82
18: ; preds = %1
%19 = load i32*, i32** %5
%20 = call i32 @xcb_get_setup(i32* %19)
%21 = call %struct.TYPE_4__* @xcb_setup_roots_iterator(i32 %20)
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 0
store %struct.TYPE_4__* %21, %struct.TYPE_4__** %22
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 0
%24 = load %struct.TYPE_4__*, %struct.TYPE_4__** %23
store %struct.TYPE_4__* %24, %struct.TYPE_4__** %6
%25 = load i32*, i32** %5
%26 = call i32 @xcb_generate_id(i32* %25)
store i32 %26, i32* %7
%27 = load i32*, i32** %5
%28 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%29 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%30 = call i32 @lookup_color(i32* %27, %struct.TYPE_4__* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %29)
%31 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 1
store i64 0, i64* %31
%32 = load i32*, i32** %5
%33 = load i32, i32* %7
%34 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i32, i32* @XCB_GC_FOREGROUND
%38 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%39 = call i32 @xcb_create_gc(i32* %32, i32 %33, i32 %36, i32 %37, i64* %38)
%40 = load i32*, i32** %5
%41 = call i32 @xcb_generate_id(i32* %40)
store i32 %41, i32* %8
%42 = load i32*, i32** %5
%43 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%44 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%45 = call i32 @lookup_color(i32* %42, %struct.TYPE_4__* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %44)
%46 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 1
store i64 0, i64* %46
%47 = load i32*, i32** %5
%48 = load i32, i32* %8
%49 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%50 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = load i32, i32* @XCB_GC_FOREGROUND
%53 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%54 = call i32 @xcb_create_gc(i32* %47, i32 %48, i32 %51, i32 %52, i64* %53)
%55 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%56 = getelementptr inbounds [32 x i32], [32 x i32]* %10, i64 0, i64 0
%57 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %57, i32 0, i32 2
%59 = load i32, i32* %58
%60 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%61 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %60, i32 0, i32 1
%62 = load i32, i32* %61
%63 = call i32 @create_rectangles(i32* %55, i32* %56, i32 %59, i32 %62)
%64 = load i32*, i32** %5
%65 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%66 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = load i32, i32* %7
%69 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%70 = call i32 @xcb_poly_fill_rectangle_checked(i32* %64, i32 %67, i32 %68, i32 32, i32* %69)
%71 = load i32*, i32** %5
%72 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%73 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = load i32, i32* %8
%76 = getelementptr inbounds [32 x i32], [32 x i32]* %10, i64 0, i64 0
%77 = call i32 @xcb_poly_fill_rectangle_checked(i32* %71, i32 %74, i32 %75, i32 32, i32* %76)
%78 = load i32*, i32** %5
%79 = call i32 @xcb_flush(i32* %78)
%80 = load i32*, i32** %5
%81 = call i32 @xcb_disconnect(i32* %80)
store i32 0, i32* %2
br label %82
82: ; preds = %18, %17
%83 = load i32, i32* %2
ret i32 %83
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32 }
@.str = [4 x i8] c"red\00"
@XCB_GC_FOREGROUND = global i32 0
@.str.1 = [6 x i8] c"green\00"
define i32 @xcb_draw_grid(i8* %0) {
%2 = alloca [2 x i64]
%3 = alloca [32 x i32]
%4 = alloca [32 x i32]
%5 = bitcast [2 x i64]* %2 to i8*
%6 = bitcast [32 x i32]* %3 to i8*
%7 = bitcast [32 x i32]* %4 to i8*
%8 = tail call i32* @xcb_connect(i8* %0, i32* null)
%9 = tail call i64 @xcb_connection_has_error(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %40
11: ; preds = %1
%12 = tail call i32 @xcb_get_setup(i32* %8)
%13 = tail call %struct.TYPE_4__* @xcb_setup_roots_iterator(i32 %12)
%14 = tail call i32 @xcb_generate_id(i32* %8)
%15 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 0
%16 = call i32 @lookup_color(i32* %8, %struct.TYPE_4__* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %15)
%17 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 1
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i64 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* @XCB_GC_FOREGROUND
%21 = call i32 @xcb_create_gc(i32* %8, i32 %14, i32 %19, i32 %20, i64* %15)
%22 = call i32 @xcb_generate_id(i32* %8)
%23 = call i32 @lookup_color(i32* %8, %struct.TYPE_4__* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %15)
store i64 0, i64* %17
%24 = load i32, i32* %18
%25 = load i32, i32* @XCB_GC_FOREGROUND
%26 = call i32 @xcb_create_gc(i32* %8, i32 %22, i32 %24, i32 %25, i64* %15)
%27 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%28 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 0
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i64 0, i32 2
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i64 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 @create_rectangles(i32* %27, i32* %28, i32 %30, i32 %32)
%34 = load i32, i32* %18
%35 = call i32 @xcb_poly_fill_rectangle_checked(i32* %8, i32 %34, i32 %14, i32 32, i32* %27)
%36 = load i32, i32* %18
%37 = call i32 @xcb_poly_fill_rectangle_checked(i32* %8, i32 %36, i32 %22, i32 32, i32* %28)
%38 = call i32 @xcb_flush(i32* %8)
%39 = call i32 @xcb_disconnect(i32* %8)
br label %40
40: ; preds = %1, %11
%41 = phi i32 [ 0, %11 ], [ 1, %1 ]
ret i32 %41
}