#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 */

/* Type definitions */
typedef int /*<<< orphan*/ XVisualInfo;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int DefaultScreen(int /*<<< orphan*/ *);
int GLX_BLUE_SIZE;
int GLX_DOUBLEBUFFER;
int GLX_GREEN_SIZE;
int GLX_RED_SIZE;
int GLX_RGBA;
int None;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *glXChooseVisual(int /*<<< orphan*/ *, int, int *);
int /*<<< orphan*/ printf(char *);
XVisualInfo *ChooseWindowVisual(Display *dpy) {
  int screen = DefaultScreen(dpy);
  XVisualInfo *visinfo;
  int attribs[] = {GLX_RGBA, GLX_RED_SIZE,  1, GLX_GREEN_SIZE,
                   1,        GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER,
                   None};
  visinfo = glXChooseVisual(dpy, screen, attribs);
  if (!visinfo) {
    printf("Unable to find RGB, double-buffered visual\n");
    exit(1);
  }
  return visinfo;
}


x86 assembly (clang, -O0):
<ChooseWindowVisual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <DefaultScreen@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x1,-0x38(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movl   $0x1,-0x30(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x28(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1040 <glXChooseVisual@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ea <ChooseWindowVisual+0xaa>
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ChooseWindowVisual>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
call   1060 <DefaultScreen@plt>
mov    0x2e94(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rsp)
mov    0x2e58(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0xc(%rsp)
movl   $0x1,0x10(%rsp)
mov    0x2e4e(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rsp)
movl   $0x1,0x18(%rsp)
mov    0x2e21(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x1c(%rsp)
mov    0x2e24(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x20(%rsp)
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <glXChooseVisual@plt>
test   %rax,%rax
je     11ca <ChooseWindowVisual+0x8a>
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@GLX_RGBA = global i32 0
@GLX_RED_SIZE = global i32 0
@GLX_GREEN_SIZE = global i32 0
@GLX_BLUE_SIZE = global i32 0
@GLX_DOUBLEBUFFER = global i32 0
@None = global i32 0
@.str = [44 x i8] c"Unable to find RGB, double-buffered visual\0A\00"
define i32* @ChooseWindowVisual(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [9 x i32]
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @DefaultScreen(i32* %6)
store i32 %7, i32* %3
%8 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 0
%9 = load i32, i32* @GLX_RGBA
store i32 %9, i32* %8
%10 = getelementptr inbounds i32, i32* %8, i64 1
%11 = load i32, i32* @GLX_RED_SIZE
store i32 %11, i32* %10
%12 = getelementptr inbounds i32, i32* %10, i64 1
store i32 1, i32* %12
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* @GLX_GREEN_SIZE
store i32 %14, i32* %13
%15 = getelementptr inbounds i32, i32* %13, i64 1
store i32 1, i32* %15
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* @GLX_BLUE_SIZE
store i32 %17, i32* %16
%18 = getelementptr inbounds i32, i32* %16, i64 1
store i32 1, i32* %18
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* @GLX_DOUBLEBUFFER
store i32 %20, i32* %19
%21 = getelementptr inbounds i32, i32* %19, i64 1
%22 = load i32, i32* @None
store i32 %22, i32* %21
%23 = load i32*, i32** %2
%24 = load i32, i32* %3
%25 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 0
%26 = call i32* @glXChooseVisual(i32* %23, i32 %24, i32* %25)
store i32* %26, i32** %4
%27 = load i32*, i32** %4
%28 = icmp ne i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %1
%30 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %1
%33 = load i32*, i32** %4
ret i32* %33
}

LLVM IR (-O2):
@GLX_RGBA = global i32 0
@GLX_RED_SIZE = global i32 0
@GLX_GREEN_SIZE = global i32 0
@GLX_BLUE_SIZE = global i32 0
@GLX_DOUBLEBUFFER = global i32 0
@None = global i32 0
@str = [43 x i8] c"Unable to find RGB, double-buffered visual\00"
define i32* @ChooseWindowVisual(i32* %0) {
%2 = alloca [9 x i32]
%3 = tail call i32 @DefaultScreen(i32* %0)
%4 = bitcast [9 x i32]* %2 to i8*
%5 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%6 = load i32, i32* @GLX_RGBA
store i32 %6, i32* %5
%7 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 1
%8 = load i32, i32* @GLX_RED_SIZE
store i32 %8, i32* %7
%9 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 2
store i32 1, i32* %9
%10 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 3
%11 = load i32, i32* @GLX_GREEN_SIZE
store i32 %11, i32* %10
%12 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 4
store i32 1, i32* %12
%13 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 5
%14 = load i32, i32* @GLX_BLUE_SIZE
store i32 %14, i32* %13
%15 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 6
store i32 1, i32* %15
%16 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 7
%17 = load i32, i32* @GLX_DOUBLEBUFFER
store i32 %17, i32* %16
%18 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 8
%19 = load i32, i32* @None
store i32 %19, i32* %18
%20 = call i32* @glXChooseVisual(i32* %0, i32 %3, i32* %5)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %1
ret i32* %20
}