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

/* Variables and functions */
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
double get_time();
char **malloc(int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strdup(char *);
int /*<<< orphan*/ useXCBPoorly(char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ useXCBProperly(char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ useXlib(char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ useXlibProperly(char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ *xcb_connect(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_disconnect(int /*<<< orphan*/ *);
int main() {
  char(**names) = malloc(500 * sizeof(*names));
  for (int i = 0; i < 500; i++) {
    char buf[100];
    sprintf(buf, "NAME%d", i);
    names[i] = strdup(buf);
  }
  double start, XlibTime, XlibGoodTime, XCBBadTime, XCBGoodTime;
  Display *display = XOpenDisplay(NULL);
  start = get_time();
  useXlib(names, display);
  XlibTime = get_time() - start;
  start = get_time();
  useXlibProperly(names, display);
  XlibGoodTime = get_time() - start;
  XCloseDisplay(display);
  xcb_connection_t *connection = xcb_connect(NULL, NULL);
  start = get_time();
  useXCBPoorly(names, connection);
  XCBBadTime = get_time() - start;
  start = get_time();
  useXCBProperly(names, connection);
  XCBGoodTime = get_time() - start;
  xcb_disconnect(connection);
  printf("Bad Xlib time: %f\n", XlibTime);
  printf("Good Xlib time: %f\n", XlibGoodTime);
  printf("Bad xcb time: %f\n", XCBBadTime);
  printf("Good xcb time: %f\n", XCBGoodTime);
  printf("ratio of good xcb time to bad xcb time: %f\n",
         XCBGoodTime / XCBBadTime);
  printf("ratio of Xlib time to good xcb time: %f\n", XlibTime / XCBGoodTime);
  printf("ratio of good time to bad Xlib time: %f\n", XlibGoodTime / XlibTime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xfa0,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1f4,-0x14(%rbp)
jge    123d <main+0x6d>
lea    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdee(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   10d0 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f7 <main+0x27>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <XOpenDisplay@plt>
mov    %rax,-0xb0(%rbp)
mov    $0x0,%al
call   1070 <get_time@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x10(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
call   10a0 <useXlib@plt>
mov    $0x0,%al
call   1070 <get_time@plt>
subsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x90(%rbp)
ff
mov    $0x0,%al
call   1070 <get_time@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x10(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
call   1050 <useXlibProperly@plt>
mov    $0x0,%al
call   1070 <get_time@plt>
subsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0xb0(%rbp),%rdi
call   10e0 <XCloseDisplay@plt>
xor    %eax,%eax
mov    %eax,%esi
mov    %rsi,%rdi
call   1030 <xcb_connect@plt>
mov    %rax,-0xb8(%rbp)
mov    $0x0,%al
call   1070 <get_time@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x10(%rbp),%rdi
mov    -0xb8(%rbp),%rsi
call   10f0 <useXCBPoorly@plt>
mov    $0x0,%al
call   1070 <get_time@plt>
subsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0xa0(%rbp)
ff
mov    $0x0,%al
call   1070 <get_time@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x10(%rbp),%rdi
mov    -0xb8(%rbp),%rsi
call   1060 <useXCBProperly@plt>
mov    $0x0,%al
call   1070 <get_time@plt>
subsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0xa8(%rbp)
ff
mov    -0xb8(%rbp),%rdi
call   10b0 <xcb_disconnect@plt>
movsd  -0x90(%rbp),%xmm0
ff
lea    0xca8(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x98(%rbp),%xmm0
ff
lea    0xca7(%rip),%rdi
call   1040 <printf@plt>
movsd  -0xa0(%rbp),%xmm0
ff
lea    0xca7(%rip),%rdi
call   1040 <printf@plt>
movsd  -0xa8(%rbp),%xmm0
ff
lea    0xca5(%rip),%rdi
call   1040 <printf@plt>
movsd  -0xa8(%rbp),%xmm0
ff
divsd  -0xa0(%rbp),%xmm0
ff
lea    0xc9c(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x90(%rbp),%xmm0
ff
divsd  -0xa8(%rbp),%xmm0
ff
lea    0xcac(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x98(%rbp),%xmm0
ff
divsd  -0x90(%rbp),%xmm0
ff
lea    0xcb9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    $0xfa0,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe0c(%rip),%r14
lea    0x20(%rsp),%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   10c0 <sprintf@plt>
mov    %r12,%rdi
call   10d0 <strdup@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    $0x1f4,%rbx
jne    1200 <main+0x30>
xor    %edi,%edi
call   1080 <XOpenDisplay@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <get_time@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <useXlib@plt>
xor    %eax,%eax
call   1070 <get_time@plt>
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <get_time@plt>
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <useXlibProperly@plt>
xor    %eax,%eax
call   1070 <get_time@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %r14,%rdi
call   10e0 <XCloseDisplay@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <xcb_connect@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <get_time@plt>
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   10f0 <useXCBPoorly@plt>
xor    %eax,%eax
call   1070 <get_time@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1070 <get_time@plt>
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <useXCBProperly@plt>
xor    %eax,%eax
call   1070 <get_time@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
call   10b0 <xcb_disconnect@plt>
lea    0xd0f(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xd10(%rip),%rdi
movsd  0x18(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xd12(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xd12(%rip),%rdi
movsd  (%rsp),%xmm0
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
lea    0xd09(%rip),%rdi
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
lea    0xd1e(%rip),%rdi
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
lea    0xd2f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"NAME%d\00"
@.str.1 = [19 x i8] c"Bad Xlib time: %f\0A\00"
@.str.2 = [20 x i8] c"Good Xlib time: %f\0A\00"
@.str.3 = [18 x i8] c"Bad xcb time: %f\0A\00"
@.str.4 = [19 x i8] c"Good xcb time: %f\0A\00"
@.str.5 = [44 x i8] c"ratio of good xcb time to bad xcb time: %f\0A\00"
@.str.6 = [41 x i8] c"ratio of Xlib time to good xcb time: %f\0A\00"
@.str.7 = [41 x i8] c"ratio of good time to bad Xlib time: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %1
%12 = call i8** @malloc(i32 4000)
store i8** %12, i8*** %2
store i32 0, i32* %3
br label %13
13: ; preds = %26, %0
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 500
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* %3
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i8* @strdup(i8* %20)
%22 = load i8**, i8*** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
store i8* %21, i8** %25
br label %26
26: ; preds = %16
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %13
29: ; preds = %13
%30 = call i32* @XOpenDisplay(i32* null)
store i32* %30, i32** %10
%31 = call double (...) @get_time()
store double %31, double* %5
%32 = load i8**, i8*** %2
%33 = load i32*, i32** %10
%34 = call i32 @useXlib(i8** %32, i32* %33)
%35 = call double (...) @get_time()
%36 = load double, double* %5
%37 = fsub double %35, %36
store double %37, double* %6
%38 = call double (...) @get_time()
store double %38, double* %5
%39 = load i8**, i8*** %2
%40 = load i32*, i32** %10
%41 = call i32 @useXlibProperly(i8** %39, i32* %40)
%42 = call double (...) @get_time()
%43 = load double, double* %5
%44 = fsub double %42, %43
store double %44, double* %7
%45 = load i32*, i32** %10
%46 = call i32 @XCloseDisplay(i32* %45)
%47 = call i32* @xcb_connect(i32* null, i32* null)
store i32* %47, i32** %11
%48 = call double (...) @get_time()
store double %48, double* %5
%49 = load i8**, i8*** %2
%50 = load i32*, i32** %11
%51 = call i32 @useXCBPoorly(i8** %49, i32* %50)
%52 = call double (...) @get_time()
%53 = load double, double* %5
%54 = fsub double %52, %53
store double %54, double* %8
%55 = call double (...) @get_time()
store double %55, double* %5
%56 = load i8**, i8*** %2
%57 = load i32*, i32** %11
%58 = call i32 @useXCBProperly(i8** %56, i32* %57)
%59 = call double (...) @get_time()
%60 = load double, double* %5
%61 = fsub double %59, %60
store double %61, double* %9
%62 = load i32*, i32** %11
%63 = call i32 @xcb_disconnect(i32* %62)
%64 = load double, double* %6
%65 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %64)
%66 = load double, double* %7
%67 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %66)
%68 = load double, double* %8
%69 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %68)
%70 = load double, double* %9
%71 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %70)
%72 = load double, double* %9
%73 = load double, double* %8
%74 = fdiv double %72, %73
%75 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), double %74)
%76 = load double, double* %6
%77 = load double, double* %9
%78 = fdiv double %76, %77
%79 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), double %78)
%80 = load double, double* %7
%81 = load double, double* %6
%82 = fdiv double %80, %81
%83 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), double %82)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"NAME%d\00"
@.str.1 = [19 x i8] c"Bad Xlib time: %f\0A\00"
@.str.2 = [20 x i8] c"Good Xlib time: %f\0A\00"
@.str.3 = [18 x i8] c"Bad xcb time: %f\0A\00"
@.str.4 = [19 x i8] c"Good xcb time: %f\0A\00"
@.str.5 = [44 x i8] c"ratio of good xcb time to bad xcb time: %f\0A\00"
@.str.6 = [41 x i8] c"ratio of Xlib time to good xcb time: %f\0A\00"
@.str.7 = [41 x i8] c"ratio of good time to bad Xlib time: %f\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = tail call i8** @malloc(i32 4000)
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
br label %35
4: ; preds = %35
%5 = tail call i32* @XOpenDisplay(i32* null)
%6 = tail call double (...) @get_time()
%7 = tail call i32 @useXlib(i8** %2, i32* %5)
%8 = tail call double (...) @get_time()
%9 = fsub double %8, %6
%10 = tail call double (...) @get_time()
%11 = tail call i32 @useXlibProperly(i8** %2, i32* %5)
%12 = tail call double (...) @get_time()
%13 = fsub double %12, %10
%14 = tail call i32 @XCloseDisplay(i32* %5)
%15 = tail call i32* @xcb_connect(i32* null, i32* null)
%16 = tail call double (...) @get_time()
%17 = tail call i32 @useXCBPoorly(i8** %2, i32* %15)
%18 = tail call double (...) @get_time()
%19 = fsub double %18, %16
%20 = tail call double (...) @get_time()
%21 = tail call i32 @useXCBProperly(i8** %2, i32* %15)
%22 = tail call double (...) @get_time()
%23 = fsub double %22, %20
%24 = tail call i32 @xcb_disconnect(i32* %15)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %9)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %13)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %19)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %23)
%29 = fdiv double %23, %19
%30 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), double %29)
%31 = fdiv double %9, %23
%32 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), double %31)
%33 = fdiv double %13, %9
%34 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), double %33)
ret i32 0
35: ; preds = %0, %35
%36 = phi i64 [ 0, %0 ], [ %41, %35 ]
%37 = trunc i64 %36 to i32
%38 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = call i8* @strdup(i8* %3)
%40 = getelementptr inbounds i8*, i8** %2, i64 %36
store i8* %39, i8** %40
%41 = add nuw nsw i64 %36, 1
%42 = icmp eq i64 %41, 500
br i1 %42, label %4, label %35
}