#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*/ GLuint;
typedef scalar_t__ GLint;

/* Variables and functions */
int /*<<< orphan*/ GL_COMPILE_STATUS;
scalar_t__ GL_FALSE;
int /*<<< orphan*/ GL_INFO_LOG_LENGTH;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *, char *);
int /*<<< orphan*/ glGetShaderInfoLog(int /*<<< orphan*/, scalar_t__,
                                      scalar_t__ *, char *);
int /*<<< orphan*/ glGetShaderiv(int /*<<< orphan*/, int /*<<< orphan*/,
                                 scalar_t__ *);
scalar_t__ malloc(scalar_t__);
void __attribute__((unused)) check_shader(GLuint shader) {
  GLint len, res;
  char *log;
  glGetShaderiv(shader, GL_COMPILE_STATUS, &res);
  if (res == GL_FALSE) {
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
    log = (char *)malloc(len);
    if (!log) {
      err(1, "malloc");
    }
    glGetShaderInfoLog(shader, len, &res, log);
    errx(1, "glErr: %s\n", log);
  }
}


x86 assembly (clang, -O0):
<check_shader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <glGetShaderiv@plt>
mov    -0x18(%rbp),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    11eb <check_shader+0x9b>
mov    -0x4(%rbp),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <glGetShaderiv@plt>
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <check_shader+0x72>
mov    $0x1,%edi
lea    0xe43(%rip),%rsi
call   1050 <err@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    -0x18(%rbp),%rdx
call   1070 <glGetShaderInfoLog@plt>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xe21(%rip),%rsi
call   1030 <errx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_shader>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <glGetShaderiv@plt>
mov    0x8(%rsp),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    11dd <check_shader+0x8d>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   1040 <glGetShaderiv@plt>
mov    0x10(%rsp),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11b5 <check_shader+0x65>
lea    0xe55(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    %r14,%rcx
call   1070 <glGetShaderInfoLog@plt>
lea    0xe37(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1030 <errx@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@GL_COMPILE_STATUS = global i32 0
@GL_FALSE = global i64 0
@GL_INFO_LOG_LENGTH = global i32 0
@.str = [7 x i8] c"malloc\00"
@.str.1 = [11 x i8] c"glErr: %s\0A\00"
define void @check_shader(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* @GL_COMPILE_STATUS
%8 = call i32 @glGetShaderiv(i32 %6, i32 %7, i64* %4)
%9 = load i64, i64* %4
%10 = load i64, i64* @GL_FALSE
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %30
12: ; preds = %1
%13 = load i32, i32* %2
%14 = load i32, i32* @GL_INFO_LOG_LENGTH
%15 = call i32 @glGetShaderiv(i32 %13, i32 %14, i64* %3)
%16 = load i64, i64* %3
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %12
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %12
%24 = load i32, i32* %2
%25 = load i64, i64* %3
%26 = load i8*, i8** %5
%27 = call i32 @glGetShaderInfoLog(i32 %24, i64 %25, i64* %4, i8* %26)
%28 = load i8*, i8** %5
%29 = call i32 @errx(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %23, %1
ret void
}

LLVM IR (-O2):
@GL_COMPILE_STATUS = global i32 0
@GL_FALSE = global i64 0
@GL_INFO_LOG_LENGTH = global i32 0
@.str = [7 x i8] c"malloc\00"
@.str.1 = [11 x i8] c"glErr: %s\0A\00"
define void @check_shader(i32 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = load i32, i32* @GL_COMPILE_STATUS
%7 = call i32 @glGetShaderiv(i32 %0, i32 %6, i64* %3)
%8 = load i64, i64* %3
%9 = load i64, i64* @GL_FALSE
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = load i32, i32* @GL_INFO_LOG_LENGTH
%13 = call i32 @glGetShaderiv(i32 %0, i32 %12, i64* %2)
%14 = load i64, i64* %2
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = load i64, i64* %2
%22 = call i32 @glGetShaderInfoLog(i32 %0, i64 %21, i64* %3, i8* %16)
%23 = call i32 @errx(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %24
24: ; preds = %20, %1
ret void
}