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

/* Variables and functions */
#define GL_INVALID_ENUM 134
#define GL_INVALID_FRAMEBUFFER_OPERATION 133
#define GL_INVALID_OPERATION 132
#define GL_INVALID_VALUE 131
int /*<<< orphan*/ GL_NO_ERROR;
#define GL_OUT_OF_MEMORY 130
#define GL_STACK_OVERFLOW 129
#define GL_STACK_UNDERFLOW 128
int /*<<< orphan*/ glGetError();
int /*<<< orphan*/ platform_log(char *, char *, int /*<<< orphan*/);
void opengl_check_error() {
  GLenum error;
  while ((error = glGetError()) != GL_NO_ERROR) {
    char *error_name = "";
    switch (error) {
    case GL_INVALID_ENUM:
      error_name = "GL_INVALID_ENUM";
      break;
    case GL_INVALID_VALUE:
      error_name = "GL_INVALID_VALUE";
      break;
    case GL_INVALID_OPERATION:
      error_name = "GL_INVALID_OPERATION";
      break;
    case GL_INVALID_FRAMEBUFFER_OPERATION:
      error_name = "GL_INVALID_FRAMEBUFFER_OPERATION";
      break;
    case GL_OUT_OF_MEMORY:
      error_name = "GL_OUT_OF_MEMORY";
      break;
    case GL_STACK_UNDERFLOW:
      error_name = "GL_STACK_UNDERFLOW";
      break;
    case GL_STACK_OVERFLOW:
      error_name = "GL_STACK_OVERFLOW";
      break;
    }
    platform_log("OpenGL Error: %s (%d)\n", error_name, error);
  }
}


x86 assembly (clang, -O0):
<opengl_check_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <glGetError@plt>
mov    %eax,-0x4(%rbp)
mov    0x2eaf(%rip),%rcx
cmp    (%rcx),%eax
je     11f8 <opengl_check_error+0xd8>
lea    0xf77(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     11e0 <opengl_check_error+0xc0>
mov    -0x18(%rbp),%rax
lea    0xe94(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea0(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <opengl_check_error+0xc0>
lea    0xea0(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <opengl_check_error+0xc0>
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <opengl_check_error+0xc0>
lea    0xea6(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <opengl_check_error+0xc0>
lea    0xeb7(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <opengl_check_error+0xc0>
lea    0xeb8(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <opengl_check_error+0xc0>
lea    0xebb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xebb(%rip),%rdi
call   1040 <platform_log@plt>
jmp    1128 <opengl_check_error+0x8>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opengl_check_error>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <glGetError@plt>
mov    0x2eb2(%rip),%r14
cmp    (%r14),%eax
jne    1147 <opengl_check_error+0x27>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xf55(%rip),%r15
lea    0xf4f(%rip),%r12
lea    0xf31(%rip),%rbx
jmp    1176 <opengl_check_error+0x56>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <platform_log@plt>
xor    %eax,%eax
call   1030 <glGetError@plt>
cmp    (%r14),%eax
je     113b <opengl_check_error+0x1b>
lea    -0x80(%rax),%ecx
mov    %r15,%rsi
cmp    $0x6,%ecx
ja     1160 <opengl_check_error+0x40>
movslq %ecx,%rcx
movslq (%r12,%rcx,4),%rsi
add    %r12,%rsi
jmp    1160 <opengl_check_error+0x40>

LLVM IR (-O0):
@GL_NO_ERROR = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [16 x i8] c"GL_INVALID_ENUM\00"
@.str.2 = [17 x i8] c"GL_INVALID_VALUE\00"
@.str.3 = [21 x i8] c"GL_INVALID_OPERATION\00"
@.str.4 = [33 x i8] c"GL_INVALID_FRAMEBUFFER_OPERATION\00"
@.str.5 = [17 x i8] c"GL_OUT_OF_MEMORY\00"
@.str.6 = [19 x i8] c"GL_STACK_UNDERFLOW\00"
@.str.7 = [18 x i8] c"GL_STACK_OVERFLOW\00"
@.str.8 = [23 x i8] c"OpenGL Error: %s (%d)\0A\00"
define void @opengl_check_error() {
%1 = alloca i32
%2 = alloca i8*
br label %3
3: ; preds = %16, %0
%4 = call i32 (...) @glGetError()
store i32 %4, i32* %1
%5 = load i32, i32* @GL_NO_ERROR
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %20
7: ; preds = %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = load i32, i32* %1
switch i32 %8, label %16 [
i32 134, label %9
i32 131, label %10
i32 132, label %11
i32 133, label %12
i32 130, label %13
i32 128, label %14
i32 129, label %15
]
9: ; preds = %7
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %16
10: ; preds = %7
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %16
11: ; preds = %7
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %16
12: ; preds = %7
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %16
13: ; preds = %7
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %16
14: ; preds = %7
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %16
15: ; preds = %7
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %16
16: ; preds = %7, %15, %14, %13, %12, %11, %10, %9
%17 = load i8*, i8** %2
%18 = load i32, i32* %1
%19 = call i32 @platform_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %17, i32 %18)
br label %3
20: ; preds = %3
ret void
}

LLVM IR (-O2):
@GL_NO_ERROR = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [16 x i8] c"GL_INVALID_ENUM\00"
@.str.2 = [17 x i8] c"GL_INVALID_VALUE\00"
@.str.3 = [21 x i8] c"GL_INVALID_OPERATION\00"
@.str.4 = [33 x i8] c"GL_INVALID_FRAMEBUFFER_OPERATION\00"
@.str.5 = [17 x i8] c"GL_OUT_OF_MEMORY\00"
@.str.6 = [19 x i8] c"GL_STACK_UNDERFLOW\00"
@.str.7 = [18 x i8] c"GL_STACK_OVERFLOW\00"
@.str.8 = [23 x i8] c"OpenGL Error: %s (%d)\0A\00"
@reltable.opengl_check_error = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.opengl_check_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.7 to i64), i64 ptrtoint ([7 x i32]* @reltable.opengl_check_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.opengl_check_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.opengl_check_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.opengl_check_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([33 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.opengl_check_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.opengl_check_error to i64)) to i32)]
define void @opengl_check_error() {
%1 = tail call i32 (...) @glGetError()
%2 = load i32, i32* @GL_NO_ERROR
%3 = icmp eq i32 %1, %2
br i1 %3, label %18, label %4
4: ; preds = %0, %12
%5 = phi i32 [ %15, %12 ], [ %1, %0 ]
%6 = add i32 %5, -128
%7 = icmp ult i32 %6, 7
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = sext i32 %6 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.opengl_check_error to i8*), i64 %10)
br label %12
12: ; preds = %8, %4
%13 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %4 ], [ %11, %8 ]
%14 = tail call i32 @platform_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %13, i32 %5)
%15 = tail call i32 (...) @glGetError()
%16 = load i32, i32* @GL_NO_ERROR
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %4
18: ; preds = %12, %0
ret void
}