#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 GLenum;

/* Variables and functions */
#define GL_INVALID_ENUM 132
#define GL_INVALID_FRAMEBUFFER_OPERATION 131
#define GL_INVALID_OPERATION 130
#define GL_INVALID_VALUE 129
int GL_NO_ERROR;
#define GL_OUT_OF_MEMORY 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char const *const, int /*<<< orphan*/);
int glGetError();
int /*<<< orphan*/ stderr;
int report_opengl_error(char const *const reason) {
  GLenum e = glGetError();
  if (e == GL_NO_ERROR) {
    return 0;
  }
  (void)fputs(reason, stderr);
  switch (e) {
  case GL_INVALID_ENUM:
    fprintf(stderr, "OpenGL: Invalid enumeration.\n");
    break;
  case GL_INVALID_VALUE:
    fprintf(stderr, "OpenGL: Invalid value.\n");
    break;
  case GL_INVALID_OPERATION:
    fprintf(stderr, "OpenGL: Invalid operation.\n");
    break;
  case GL_INVALID_FRAMEBUFFER_OPERATION:
    fprintf(stderr, "OpenGL: Invalid framebuffer operation.\n");
    break;
  case GL_OUT_OF_MEMORY:
    fprintf(stderr, "OpenGL: Out of memory.\n");
    break;
  default:
    fprintf(stderr, "Unknown OpenGL error: %d.\n", (int)e);
  }
  return 1;
}


x86 assembly (clang, -O0):
<report_opengl_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <glGetError@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%eax
jne    1164 <report_opengl_error+0x34>
movl   $0x0,-0x4(%rbp)
jmp    124c <report_opengl_error+0x11c>
mov    -0x10(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    -0x14(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     122b <report_opengl_error+0xfb>
mov    -0x20(%rbp),%rax
lea    0xe6a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1245 <report_opengl_error+0x115>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1245 <report_opengl_error+0x115>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1245 <report_opengl_error+0x115>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1245 <report_opengl_error+0x115>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1245 <report_opengl_error+0x115>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<report_opengl_error>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <glGetError@plt>
mov    %eax,%ebx
mov    0x2e9f(%rip),%rax
cmp    (%rax),%ebx
je     11d6 <report_opengl_error+0xa6>
mov    0x2e80(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1030 <fputs@plt>
lea    -0x80(%rbx),%eax
cmp    $0x4,%eax
ja     1187 <report_opengl_error+0x57>
lea    0xe8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x0(%rbp),%edi
lea    0xf09(%rip),%rsi
jmp    11ca <report_opengl_error+0x9a>
mov    0x0(%rbp),%edi
lea    0xf15(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d1 <report_opengl_error+0xa1>
mov    0x0(%rbp),%edi
lea    0xe8c(%rip),%rsi
jmp    11ca <report_opengl_error+0x9a>
mov    0x0(%rbp),%edi
lea    0xe98(%rip),%rsi
jmp    11ca <report_opengl_error+0x9a>
mov    0x0(%rbp),%edi
lea    0xea8(%rip),%rsi
jmp    11ca <report_opengl_error+0x9a>
mov    0x0(%rbp),%edi
lea    0xe4a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@GL_NO_ERROR = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"OpenGL: Invalid enumeration.\0A\00"
@.str.1 = [24 x i8] c"OpenGL: Invalid value.\0A\00"
@.str.2 = [28 x i8] c"OpenGL: Invalid operation.\0A\00"
@.str.3 = [40 x i8] c"OpenGL: Invalid framebuffer operation.\0A\00"
@.str.4 = [24 x i8] c"OpenGL: Out of memory.\0A\00"
@.str.5 = [27 x i8] c"Unknown OpenGL error: %d.\0A\00"
define i32 @report_opengl_error(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 (...) @glGetError()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = load i32, i32* @GL_NO_ERROR
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %35
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* %11, i32 %12)
%14 = load i32, i32* %4
switch i32 %14, label %30 [
i32 132, label %15
i32 129, label %18
i32 130, label %21
i32 131, label %24
i32 128, label %27
]
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %34
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %34
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %34
24: ; preds = %10
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %34
27: ; preds = %10
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %34
30: ; preds = %10
%31 = load i32, i32* @stderr
%32 = load i32, i32* %4
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %30, %27, %24, %21, %18, %15
store i32 1, i32* %2
br label %35
35: ; preds = %34, %9
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@GL_NO_ERROR = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"OpenGL: Invalid enumeration.\0A\00"
@.str.1 = [24 x i8] c"OpenGL: Invalid value.\0A\00"
@.str.2 = [28 x i8] c"OpenGL: Invalid operation.\0A\00"
@.str.3 = [40 x i8] c"OpenGL: Invalid framebuffer operation.\0A\00"
@.str.4 = [24 x i8] c"OpenGL: Out of memory.\0A\00"
@.str.5 = [27 x i8] c"Unknown OpenGL error: %d.\0A\00"
define i32 @report_opengl_error(i8* %0) {
%2 = tail call i32 (...) @glGetError()
%3 = load i32, i32* @GL_NO_ERROR
%4 = icmp eq i32 %2, %3
br i1 %4, label %26, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* %0, i32 %6)
switch i32 %2, label %23 [
i32 132, label %8
i32 129, label %11
i32 130, label %14
i32 131, label %17
i32 128, label %20
]
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %26
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %26
14: ; preds = %5
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %26
17: ; preds = %5
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %26
20: ; preds = %5
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %26
23: ; preds = %5
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %2)
br label %26
26: ; preds = %8, %11, %14, %17, %20, %23, %1
%27 = phi i32 [ 0, %1 ], [ 1, %23 ], [ 1, %20 ], [ 1, %17 ], [ 1, %14 ], [ 1, %11 ], [ 1, %8 ]
ret i32 %27
}