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

/* Variables and functions */
int /*<<< orphan*/ *XOpenDisplay(char *);
int /*<<< orphan*/ XQueryExtension(int /*<<< orphan*/ *, char *, int *, int *,
                                   int *);
int /*<<< orphan*/ exit(int);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int main(int argc, char *argv[]) {
  const char *msg1 = "X display";
  char *dpyname = getenv("DISPLAY");
  if (!dpyname)
    ({
      printf("fatal: %s:\t"
             "DISPLAY not set"
             "\n",
             msg1);
      exit(1);
    });
  printf("info:  %s:\t"
         "%s"
         "\n",
         msg1, dpyname);
  Display *dpy = XOpenDisplay(dpyname);
  if (!dpy)
    ({
      printf("fatal: %s:\t"
             "failed to open connection"
             "\n",
             msg1);
      exit(1);
    });
  msg1 = "X Ext. \"GLX\"";
  int dummy;
  if (!XQueryExtension(dpy, "GLX", &dummy, &dummy, &dummy))
    ({
      printf("fatal: %s:\t"
             "not present; see the Xorg log for details"
             "\n",
             msg1);
      exit(1);
    });
  printf("info:  %s:\t"
         "present"
         "\n",
         msg1);
  msg1 = "X Ext. \"NV-GLX\"";
  if (!XQueryExtension(dpy, "NV-GLX", &dummy, &dummy, &dummy))
    printf("info:  %s:\t"
           "not present; OK for non-nVidia drivers"
           "\n",
           msg1);
  else
    printf("info:  %s:\t"
           "present"
           "\n",
           msg1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <main+0x58>
mov    -0x18(%rbp),%rsi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f2 <main+0xa2>
mov    -0x18(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe6a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xec5(%rip),%rsi
lea    -0x38(%rbp),%r8
mov    %r8,%rdx
mov    %r8,%rcx
call   1060 <XQueryExtension@plt>
cmp    $0x0,%eax
jne    123c <main+0xec>
mov    -0x18(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe65(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe66(%rip),%rsi
lea    -0x38(%rbp),%r8
mov    %r8,%rdx
mov    %r8,%rcx
call   1060 <XQueryExtension@plt>
cmp    $0x0,%eax
jne    1293 <main+0x143>
mov    -0x18(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a5 <main+0x155>
mov    -0x18(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeaf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     120d <main+0xbd>
mov    %rax,%rbx
lea    0xebb(%rip),%rdi
lea    0xe86(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <XOpenDisplay@plt>
test   %rax,%rax
je     1216 <main+0xc6>
mov    %rax,%rbx
lea    0xf2e(%rip),%rsi
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
mov    %rcx,%rdx
mov    %rcx,%r8
call   1060 <XQueryExtension@plt>
test   %eax,%eax
je     1226 <main+0xd6>
lea    0xee9(%rip),%r14
lea    0xe9f(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef5(%rip),%rsi
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
mov    %rcx,%rdx
mov    %rcx,%r8
call   1060 <XQueryExtension@plt>
test   %eax,%eax
lea    0xee0(%rip),%rdi
cmovne %r14,%rdi
lea    0xebe(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdfe(%rip),%rdi
jmp    121d <main+0xcd>
lea    0xe20(%rip),%rdi
lea    0xddc(%rip),%rsi
jmp    1234 <main+0xe4>
lea    0xe43(%rip),%rdi
lea    0xe2f(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"X display\00"
@.str.1 = [8 x i8] c"DISPLAY\00"
@.str.2 = [28 x i8] c"fatal: %s:\09DISPLAY not set\0A\00"
@.str.3 = [15 x i8] c"info: %s:\09%s\0A\00"
@.str.4 = [38 x i8] c"fatal: %s:\09failed to open connection\0A\00"
@.str.5 = [13 x i8] c"X Ext. \22GLX\22\00"
@.str.6 = [4 x i8] c"GLX\00"
@.str.7 = [54 x i8] c"fatal: %s:\09not present; see the Xorg log for details\0A\00"
@.str.8 = [20 x i8] c"info: %s:\09present\0A\00"
@.str.9 = [16 x i8] c"X Ext. \22NV-GLX\22\00"
@.str.10 = [7 x i8] c"NV-GLX\00"
@.str.11 = [51 x i8] c"info: %s:\09not present; OK for non-nVidia drivers\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
%13 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %7
%25 = call i32* @XOpenDisplay(i8* %24)
store i32* %25, i32** %9
%26 = load i32*, i32** %9
%27 = icmp ne i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %20
%29 = load i8*, i8** %6
%30 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %20
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %6
%33 = load i32*, i32** %9
%34 = call i32 @XQueryExtension(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %11, i32* %11, i32* %11)
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %32
%41 = load i8*, i8** %6
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %41)
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8** %6
%43 = load i32*, i32** %9
%44 = call i32 @XQueryExtension(i32* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32* %11, i32* %11, i32* %11)
%45 = icmp ne i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = load i8*, i8** %6
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.11, i64 0, i64 0), i8* %47)
br label %52
49: ; preds = %40
%50 = load i8*, i8** %6
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %46
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"X display\00"
@.str.1 = [8 x i8] c"DISPLAY\00"
@.str.2 = [28 x i8] c"fatal: %s:\09DISPLAY not set\0A\00"
@.str.3 = [15 x i8] c"info: %s:\09%s\0A\00"
@.str.4 = [38 x i8] c"fatal: %s:\09failed to open connection\0A\00"
@.str.5 = [13 x i8] c"X Ext. \22GLX\22\00"
@.str.6 = [4 x i8] c"GLX\00"
@.str.7 = [54 x i8] c"fatal: %s:\09not present; see the Xorg log for details\0A\00"
@.str.8 = [20 x i8] c"info: %s:\09present\0A\00"
@.str.9 = [16 x i8] c"X Ext. \22NV-GLX\22\00"
@.str.10 = [7 x i8] c"NV-GLX\00"
@.str.11 = [51 x i8] c"info: %s:\09not present; OK for non-nVidia drivers\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %4)
%11 = tail call i32* @XOpenDisplay(i8* %4)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = bitcast i32* %3 to i8*
%18 = call i32 @XQueryExtension(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %3, i32* %3, i32* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 @XQueryExtension(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32* %3, i32* %3, i32* %3)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0)
%28 = call i32 (i8*, i8*, ...) @printf(i8* %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}