#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;
typedef int /*<<< orphan*/ Bool;

/* Variables and functions */
int *GetAllFBConfigs(int /*<<< orphan*/ *, int, int *);
int /*<<< orphan*/ PrintFBConfigInfo(int /*<<< orphan*/ *, int, int,
                                     int /*<<< orphan*/);
int /*<<< orphan*/ XFree(int *);
int /*<<< orphan*/ printf(char *, ...);
void PrintConfigs(Display *dpy, int screen, Bool horizFormat) {
  int *fbConfigs;
  int nConfigs;
  int i;
  fbConfigs = GetAllFBConfigs(dpy, screen, &nConfigs);
  if (!nConfigs || !fbConfigs) {
    printf("Error: glxGetFBConfigs failed\n");
    XFree(fbConfigs);
    return;
  }
  printf("Number of fbconfigs: %d\n", nConfigs);
  if (horizFormat) {
    printf("  ID        VisualType  Depth Lvl RGB CI DB Stereo  R  G  B  A");
    printf("   Z  S  AR AG AB AA  MSbufs MSnum  Pbuffer  Float\n");
  }
  for (i = 0; i < nConfigs; i++) {
    PrintFBConfigInfo(dpy, screen, fbConfigs[i], horizFormat);
  }
  XFree(fbConfigs);
}


x86 assembly (clang, -O0):
<PrintConfigs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1050 <GetAllFBConfigs@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117b <PrintConfigs+0x3b>
cmpq   $0x0,-0x18(%rbp)
jne    1197 <PrintConfigs+0x57>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <XFree@plt>
jmp    1212 <PrintConfigs+0xd2>
mov    -0x1c(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
je     11ce <PrintConfigs+0x8e>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1209 <PrintConfigs+0xc9>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%ecx
call   1060 <PrintFBConfigInfo@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d5 <PrintConfigs+0x95>
mov    -0x18(%rbp),%rdi
call   1040 <XFree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintConfigs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
lea    0xc(%rsp),%rdx
call   1060 <GetAllFBConfigs@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
test   %esi,%esi
je     11e1 <PrintConfigs+0x91>
test   %rbx,%rbx
je     11e1 <PrintConfigs+0x91>
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     11ac <PrintConfigs+0x5c>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ed <PrintConfigs+0x9d>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%rbp,4),%edx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14d,%ecx
call   1070 <PrintFBConfigInfo@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     11c0 <PrintConfigs+0x70>
jmp    11ed <PrintConfigs+0x9d>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <XFree@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Error: glxGetFBConfigs failed\0A\00"
@.str.1 = [25 x i8] c"Number of fbconfigs: %d\0A\00"
@.str.2 = [63 x i8] c" ID VisualType Depth Lvl RGB CI DB Stereo R G B A\00"
@.str.3 = [52 x i8] c" Z S AR AG AB AA MSbufs MSnum Pbuffer Float\0A\00"
define void @PrintConfigs(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32*, i32** %4
%11 = load i32, i32* %5
%12 = call i32* @GetAllFBConfigs(i32* %10, i32 %11, i32* %8)
store i32* %12, i32** %7
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %15, %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%20 = load i32*, i32** %7
%21 = call i32 @XFree(i32* %20)
br label %51
22: ; preds = %15
%23 = load i32, i32* %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %27, %22
store i32 0, i32* %9
br label %31
31: ; preds = %45, %30
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = load i32*, i32** %4
%37 = load i32, i32* %5
%38 = load i32*, i32** %7
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %6
%44 = call i32 @PrintFBConfigInfo(i32* %36, i32 %37, i32 %42, i32 %43)
br label %45
45: ; preds = %35
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %31
48: ; preds = %31
%49 = load i32*, i32** %7
%50 = call i32 @XFree(i32* %49)
br label %51
51: ; preds = %48, %18
ret void
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"Number of fbconfigs: %d\0A\00"
@.str.2 = [63 x i8] c" ID VisualType Depth Lvl RGB CI DB Stereo R G B A\00"
@str = [30 x i8] c"Error: glxGetFBConfigs failed\00"
@str.4 = [51 x i8] c" Z S AR AG AB AA MSbufs MSnum Pbuffer Float\00"
define void @PrintConfigs(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32* @GetAllFBConfigs(i32* %0, i32 %1, i32* %4)
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
%9 = icmp ne i32* %6, null
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%13 = call i32 @XFree(i32* %6)
br label %34
14: ; preds = %3
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%16 = icmp eq i32 %2, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.4, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %20, %23
%24 = phi i64 [ %28, %23 ], [ 0, %20 ]
%25 = getelementptr inbounds i32, i32* %6, i64 %24
%26 = load i32, i32* %25
%27 = call i32 @PrintFBConfigInfo(i32* %0, i32 %1, i32 %26, i32 %2)
%28 = add nuw nsw i64 %24, 1
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %23, label %32
32: ; preds = %23, %20
%33 = call i32 @XFree(i32* %6)
br label %34
34: ; preds = %32, %11
ret void
}