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

/* Variables and functions */
int /*<<< orphan*/ GL_COMPILE_STATUS;
scalar_t__ GL_FALSE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(int /*<<< orphan*/ const *);
int /*<<< orphan*/ glCompileShader(int /*<<< orphan*/);
int /*<<< orphan*/ glCreateShader(int /*<<< orphan*/);
int /*<<< orphan*/ glDeleteShader(int /*<<< orphan*/);
int /*<<< orphan*/ glGetShaderiv(int /*<<< orphan*/, int /*<<< orphan*/,
                                 scalar_t__ *);
int /*<<< orphan*/ glShaderSource(int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ const **,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ printlog(int /*<<< orphan*/);
int /*<<< orphan*/ const *readfile(char const *);
int /*<<< orphan*/ stderr;
GLuint createShader(const char *filename, GLenum type) {
  GLchar *source = readfile(filename);
  if (source == NULL) {
    fprintf(stderr, "error opening %s", filename);
    return 0;
  }
  GLuint res = glCreateShader(type);
  const GLchar *sources[] = {source};
  glShaderSource(res, 1, sources, NULL);
  free(source);
  glCompileShader(res);
  GLint compile_ok = GL_FALSE;
  glGetShaderiv(res, GL_COMPILE_STATUS, &compile_ok);
  if (compile_ok == GL_FALSE) {
    fprintf(stderr, "%s: ", filename);
    printlog(res);
    glDeleteShader(res);
    return 0;
  }
  return res;
}


x86 assembly (clang, -O0):
<createShader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <readfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11dc <createShader+0x4c>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <createShader+0xf7>
mov    -0x14(%rbp),%edi
call   1090 <glCreateShader@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x30(%rbp),%rdx
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <glShaderSource@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%edi
call   1080 <glCompileShader@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <glGetShaderiv@plt>
mov    -0x38(%rbp),%rax
mov    0x2da5(%rip),%rcx
cmp    (%rcx),%rax
jne    1281 <createShader+0xf1>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdb1(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   10a0 <printlog@plt>
mov    -0x24(%rbp),%edi
call   1060 <glDeleteShader@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <createShader+0xf7>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createShader>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r15
call   10b0 <readfile@plt>
test   %rax,%rax
je     1239 <createShader+0xa9>
mov    %rax,%rbx
mov    %ebp,%edi
call   1090 <glCreateShader@plt>
mov    %eax,%ebp
mov    %rbx,0x10(%rsp)
xor    %r14d,%r14d
lea    0x10(%rsp),%rdx
mov    %eax,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
call   1050 <glShaderSource@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <glCompileShader@plt>
mov    0x2dfe(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x8(%rsp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <glGetShaderiv@plt>
mov    0x8(%rsp),%rax
cmp    (%rbx),%rax
jne    1256 <createShader+0xc6>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
mov    %ebp,%edi
call   10a0 <printlog@plt>
mov    %ebp,%edi
call   1060 <glDeleteShader@plt>
jmp    1259 <createShader+0xc9>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
xor    %r14d,%r14d
jmp    1259 <createShader+0xc9>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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