#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 int GLint;
typedef int /*<<< orphan*/ GLenum;

/* Variables and functions */
int /*<<< orphan*/ GL_COMPILE_STATUS;
int /*<<< orphan*/ GL_INFO_LOG_LENGTH;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ glCompileShader(int /*<<< orphan*/);
int /*<<< orphan*/ glCreateShader(int /*<<< orphan*/);
int /*<<< orphan*/ glGetShaderInfoLog(int /*<<< orphan*/, int,
                                      int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ glGetShaderiv(int /*<<< orphan*/, int /*<<< orphan*/, int *);
int /*<<< orphan*/ glShaderSource(int /*<<< orphan*/, int, char const **,
                                  int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int glfxCompileShader(GLuint *shader, GLenum type, const char *shaderStr) {
  GLint shaderCompiled;
  *shader = glCreateShader(type);
  glShaderSource(*shader, 1, &shaderStr, NULL);
  glCompileShader(*shader);
  glGetShaderiv(*shader, GL_COMPILE_STATUS, &shaderCompiled);
  if (!shaderCompiled) {
    GLint infoLen = 0;
    glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &infoLen);
    if (infoLen > 1) {
      char *infoLog = malloc(infoLen);
      glGetShaderInfoLog(*shader, infoLen, NULL, infoLog);
      fprintf(stderr, "Error compiling shader.\n%s", infoLog);
      free(infoLog);
    }
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<glfxCompileShader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <glCreateShader@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <glShaderSource@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <glCompileShader@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1040 <glGetShaderiv@plt>
cmpl   $0x0,-0x24(%rbp)
jne    1261 <glfxCompileShader+0xe1>
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <glGetShaderiv@plt>
cmpl   $0x1,-0x28(%rbp)
jle    1255 <glfxCompileShader+0xd5>
mov    -0x28(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%esi
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <glGetShaderInfoLog@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdb9(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <glfxCompileShader+0xe8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glfxCompileShader>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdx,0x8(%rsp)
mov    %esi,%edi
call   1090 <glCreateShader@plt>
mov    %eax,(%rbx)
xor    %r14d,%r14d
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
call   1050 <glShaderSource@plt>
mov    (%rbx),%edi
call   1070 <glCompileShader@plt>
mov    (%rbx),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1040 <glGetShaderiv@plt>
cmpl   $0x0,0x4(%rsp)
jne    1232 <glfxCompileShader+0xb2>
movl   $0x0,(%rsp)
mov    (%rbx),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1040 <glGetShaderiv@plt>
mov    (%rsp),%ebp
cmp    $0x2,%ebp
jl     122c <glfxCompileShader+0xac>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%edi
mov    %ebp,%esi
xor    %edx,%edx
mov    %rax,%rcx
call   10a0 <glGetShaderInfoLog@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@GL_COMPILE_STATUS = global i32 0
@GL_INFO_LOG_LENGTH = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Error compiling shader.\0A%s\00"
define i32 @glfxCompileShader(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = load i32, i32* %6
%12 = call i32 @glCreateShader(i32 %11)
%13 = load i32*, i32** %5
store i32 %12, i32* %13
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = call i32 @glShaderSource(i32 %15, i32 1, i8** %7, i32* null)
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = call i32 @glCompileShader(i32 %18)
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = load i32, i32* @GL_COMPILE_STATUS
%23 = call i32 @glGetShaderiv(i32 %21, i32 %22, i32* %8)
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %47, label %26
26: ; preds = %3
store i32 0, i32* %9
%27 = load i32*, i32** %5
%28 = load i32, i32* %27
%29 = load i32, i32* @GL_INFO_LOG_LENGTH
%30 = call i32 @glGetShaderiv(i32 %28, i32 %29, i32* %9)
%31 = load i32, i32* %9
%32 = icmp sgt i32 %31, 1
br i1 %32, label %33, label %46
33: ; preds = %26
%34 = load i32, i32* %9
%35 = call i8* @malloc(i32 %34)
store i8* %35, i8** %10
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = load i32, i32* %9
%39 = load i8*, i8** %10
%40 = call i32 @glGetShaderInfoLog(i32 %37, i32 %38, i32* null, i8* %39)
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %10
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %10
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %33, %26
store i32 1, i32* %4
br label %48
47: ; preds = %3
store i32 0, i32* %4
br label %48
48: ; preds = %47, %46
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@GL_COMPILE_STATUS = global i32 0
@GL_INFO_LOG_LENGTH = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Error compiling shader.\0A%s\00"
define i32 @glfxCompileShader(i32* nocapture %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %2, i8** %4
%7 = bitcast i32* %5 to i8*
%8 = tail call i32 @glCreateShader(i32 %1)
store i32 %8, i32* %0
%9 = call i32 @glShaderSource(i32 %8, i32 1, i8** %4, i32* null)
%10 = load i32, i32* %0
%11 = call i32 @glCompileShader(i32 %10)
%12 = load i32, i32* %0
%13 = load i32, i32* @GL_COMPILE_STATUS
%14 = call i32 @glGetShaderiv(i32 %12, i32 %13, i32* %5)
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %3
%18 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%19 = load i32, i32* %0
%20 = load i32, i32* @GL_INFO_LOG_LENGTH
%21 = call i32 @glGetShaderiv(i32 %19, i32 %20, i32* %6)
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %31
24: ; preds = %17
%25 = call i8* @malloc(i32 %22)
%26 = load i32, i32* %0
%27 = call i32 @glGetShaderInfoLog(i32 %26, i32 %22, i32* null, i8* %25)
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %25)
%30 = call i32 @free(i8* %25)
br label %31
31: ; preds = %24, %17
br label %32
32: ; preds = %3, %31
%33 = phi i32 [ 1, %31 ], [ 0, %3 ]
ret i32 %33
}