#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 (*PFNGLXGETSWAPINTERVALMESAPROC)();
typedef int /*<<< orphan*/ GLubyte;
typedef int /*<<< orphan*/ GLXDrawable;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ glXGetProcAddressARB(int /*<<< orphan*/ const *);
scalar_t__ is_glx_extension_supported(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, ...);
int stub1();
void query_vsync(Display *dpy, GLXDrawable drawable) {
  int interval = 0;
  if (is_glx_extension_supported(dpy, "GLX_MESA_swap_control")) {
    PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA =
        (PFNGLXGETSWAPINTERVALMESAPROC)glXGetProcAddressARB(
            (const GLubyte *)"glXGetSwapIntervalMESA");
    interval = (*pglXGetSwapIntervalMESA)();
  } else if (is_glx_extension_supported(dpy, "GLX_SGI_swap_control")) {
    interval = 1;
  }
  if (interval > 0) {
    printf("Running synchronized to the vertical refresh.  The framerate "
           "should be\n");
    if (interval == 1) {
      printf("approximately the same as the monitor refresh rate.\n");
    } else if (interval > 1) {
      printf("approximately 1/%d the monitor refresh rate.\n", interval);
    }
  }
}


x86 assembly (clang, -O0):
<query_vsync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <is_glx_extension_supported@plt>
cmp    $0x0,%rax
je     117f <query_vsync+0x4f>
lea    0xeaf(%rip),%rdi
call   1050 <glXGetProcAddressARB@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   *-0x18(%rbp)
mov    %eax,-0x10(%rbp)
jmp    11a5 <query_vsync+0x75>
mov    -0x8(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1040 <is_glx_extension_supported@plt>
cmp    $0x0,%rax
je     11a0 <query_vsync+0x70>
movl   $0x1,-0x10(%rbp)
jmp    11a5 <query_vsync+0x75>
cmpl   $0x0,-0x10(%rbp)
jle    11ff <query_vsync+0xcf>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x10(%rbp)
jne    11da <query_vsync+0xaa>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fa <query_vsync+0xca>
cmpl   $0x1,-0x10(%rbp)
jle    11f5 <query_vsync+0xc5>
mov    -0x10(%rbp),%esi
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fa <query_vsync+0xca>
jmp    11ff <query_vsync+0xcf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_vsync>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
call   1050 <is_glx_extension_supported@plt>
test   %rax,%rax
je     1190 <query_vsync+0x50>
lea    0xeba(%rip),%rdi
call   1060 <glXGetProcAddressARB@plt>
movslq %eax,%rcx
xor    %eax,%eax
call   *%rcx
test   %eax,%eax
jle    11bd <query_vsync+0x7d>
mov    %eax,%ebx
lea    0xefb(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebx
je     11b0 <query_vsync+0x70>
lea    0xebc(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
call   1050 <is_glx_extension_supported@plt>
test   %rax,%rax
je     11bd <query_vsync+0x7d>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
lea    0xf00(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"GLX_MESA_swap_control\00"
@.str.1 = [23 x i8] c"glXGetSwapIntervalMESA\00"
@.str.2 = [21 x i8] c"GLX_SGI_swap_control\00"
@.str.3 = [72 x i8] c"Running synchronized to the vertical refresh. The framerate should be\0A\00"
@.str.4 = [53 x i8] c"approximately the same as the monitor refresh rate.\0A\00"
@.str.5 = [46 x i8] c"approximately 1/%d the monitor refresh rate.\0A\00"
define void @query_vsync(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32 (...)*
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32*, i32** %3
%8 = call i64 @is_glx_extension_supported(i32* %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = call i32 @glXGetProcAddressARB(i32* bitcast ([23 x i8]* @.str.1 to i32*))
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32 (...)*
store i32 (...)* %13, i32 (...)** %6
%14 = load i32 (...)*, i32 (...)** %6
%15 = call i32 (...) %14()
store i32 %15, i32* %5
br label %22
16: ; preds = %2
%17 = load i32*, i32** %3
%18 = call i64 @is_glx_extension_supported(i32* %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 1, i32* %5
br label %21
21: ; preds = %20, %16
br label %22
22: ; preds = %21, %10
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
br label %38
31: ; preds = %25
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %29
br label %39
39: ; preds = %38, %22
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"GLX_MESA_swap_control\00"
@.str.1 = [23 x i8] c"glXGetSwapIntervalMESA\00"
@.str.2 = [21 x i8] c"GLX_SGI_swap_control\00"
@.str.5 = [46 x i8] c"approximately 1/%d the monitor refresh rate.\0A\00"
@str = [71 x i8] c"Running synchronized to the vertical refresh. The framerate should be\00"
@str.6 = [52 x i8] c"approximately the same as the monitor refresh rate.\00"
define void @query_vsync(i32* %0, i32 %1) {
%3 = tail call i64 @is_glx_extension_supported(i32* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = tail call i64 @is_glx_extension_supported(i32* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str, i64 0, i64 0))
br label %19
10: ; preds = %2
%11 = tail call i32 @glXGetProcAddressARB(i32* bitcast ([23 x i8]* @.str.1 to i32*))
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32 (...)*
%14 = tail call i32 (...) %13()
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str, i64 0, i64 0))
%18 = icmp eq i32 %14, 1
br i1 %18, label %19, label %21
19: ; preds = %8, %16
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.6, i64 0, i64 0))
br label %23
21: ; preds = %16
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %14)
br label %23
23: ; preds = %5, %19, %21, %10
ret void
}