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

/* Variables and functions */
int /*<<< orphan*/ GL_COMPILE_STATUS;
scalar_t__ GL_FALSE;
int /*<<< orphan*/ GL_INFO_LOG_LENGTH;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ glCompileShader(int /*<<< orphan*/);
int /*<<< orphan*/ glCreateShader(int /*<<< orphan*/);
int /*<<< orphan*/ glDeleteShader(int /*<<< orphan*/);
int /*<<< orphan*/ glGetShaderInfoLog(int /*<<< orphan*/, scalar_t__,
                                      scalar_t__ *, char *);
int /*<<< orphan*/ glGetShaderiv(int /*<<< orphan*/, int /*<<< orphan*/,
                                 scalar_t__ *);
int /*<<< orphan*/ glShaderSource(int /*<<< orphan*/, int, char const **,
                                  scalar_t__ *);
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *, char *);
scalar_t__ strlen(char *);
GLuint compile_shader(GLenum type, char *src) {
  GLuint shader = glCreateShader(type);
  GLint length = strlen(src);
  glShaderSource(shader, 1, (const char **)&src, &length);
  glCompileShader(shader);
  GLint result;
  glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
  if (result == GL_FALSE) {
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
    char *log = malloc(length);
    glGetShaderInfoLog(shader, length, &result, log);
    printf("Compile failed: Unable to compile %s: %s\n", src, log);
    free(log);
    glDeleteShader(shader);
    return 0;
  }
  return shader;
}


x86 assembly (clang, -O0):
<compile_shader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   10b0 <glCreateShader@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
lea    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1070 <glShaderSource@plt>
mov    -0x14(%rbp),%edi
call   1090 <glCompileShader@plt>
mov    -0x14(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <glGetShaderiv@plt>
mov    -0x28(%rbp),%rax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
jne    1274 <compile_shader+0xd4>
mov    -0x14(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <glGetShaderiv@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rcx
lea    -0x28(%rbp),%rdx
call   10c0 <glGetShaderInfoLog@plt>
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdae(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1080 <glDeleteShader@plt>
movl   $0x0,-0x4(%rbp)
jmp    127a <compile_shader+0xda>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compile_shader>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rsi,0x18(%rsp)
call   10b0 <glCreateShader@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,0x8(%rsp)
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x1,%esi
call   1070 <glShaderSource@plt>
mov    %ebp,%edi
call   1090 <glCompileShader@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1050 <glGetShaderiv@plt>
mov    0x10(%rsp),%rax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
jne    1263 <compile_shader+0xc3>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1050 <glGetShaderiv@plt>
mov    0x8(%rsp),%r14
mov    %r14,%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rax,%rcx
call   10c0 <glGetShaderInfoLog@plt>
mov    0x18(%rsp),%rsi
lea    0xdb6(%rip),%rdi
mov    %rbx,%rdx
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <glDeleteShader@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@GL_COMPILE_STATUS = global i32 0
@GL_FALSE = global i64 0
@GL_INFO_LOG_LENGTH = global i32 0
@.str = [42 x i8] c"Compile failed: Unable to compile %s: %s\0A\00"
define i32 @compile_shader(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = load i32, i32* %4
%11 = call i32 @glCreateShader(i32 %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
%14 = load i32, i32* %6
%15 = call i32 @glShaderSource(i32 %14, i32 1, i8** %5, i64* %7)
%16 = load i32, i32* %6
%17 = call i32 @glCompileShader(i32 %16)
%18 = load i32, i32* %6
%19 = load i32, i32* @GL_COMPILE_STATUS
%20 = call i32 @glGetShaderiv(i32 %18, i32 %19, i64* %8)
%21 = load i64, i64* %8
%22 = load i64, i64* @GL_FALSE
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %41
24: ; preds = %2
%25 = load i32, i32* %6
%26 = load i32, i32* @GL_INFO_LOG_LENGTH
%27 = call i32 @glGetShaderiv(i32 %25, i32 %26, i64* %7)
%28 = load i64, i64* %7
%29 = call i8* @malloc(i64 %28)
store i8* %29, i8** %9
%30 = load i32, i32* %6
%31 = load i64, i64* %7
%32 = load i8*, i8** %9
%33 = call i32 @glGetShaderInfoLog(i32 %30, i64 %31, i64* %8, i8* %32)
%34 = load i8*, i8** %5
%35 = load i8*, i8** %9
%36 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35)
%37 = load i8*, i8** %9
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %6
%40 = call i32 @glDeleteShader(i32 %39)
store i32 0, i32* %3
br label %43
41: ; preds = %2
%42 = load i32, i32* %6
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %24
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@GL_COMPILE_STATUS = global i32 0
@GL_FALSE = global i64 0
@GL_INFO_LOG_LENGTH = global i32 0
@.str = [42 x i8] c"Compile failed: Unable to compile %s: %s\0A\00"
define i32 @compile_shader(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %1, i8** %3
%6 = tail call i32 @glCreateShader(i32 %0)
%7 = bitcast i64* %4 to i8*
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
store i64 %8, i64* %4
%9 = call i32 @glShaderSource(i32 %6, i32 1, i8** %3, i64* %4)
%10 = call i32 @glCompileShader(i32 %6)
%11 = bitcast i64* %5 to i8*
%12 = load i32, i32* @GL_COMPILE_STATUS
%13 = call i32 @glGetShaderiv(i32 %6, i32 %12, i64* %5)
%14 = load i64, i64* %5
%15 = load i64, i64* @GL_FALSE
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %2
%18 = load i32, i32* @GL_INFO_LOG_LENGTH
%19 = call i32 @glGetShaderiv(i32 %6, i32 %18, i64* %4)
%20 = load i64, i64* %4
%21 = call i8* @malloc(i64 %20)
%22 = call i32 @glGetShaderInfoLog(i32 %6, i64 %20, i64* %5, i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %21)
%25 = call i32 @free(i8* %21)
%26 = call i32 @glDeleteShader(i32 %6)
br label %27
27: ; preds = %2, %17
%28 = phi i32 [ 0, %17 ], [ %6, %2 ]
ret i32 %28
}