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

/* Variables and functions */
int /*<<< orphan*/ CompileShaderText(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int const);
GLuint CompileShaderFile(GLenum shaderType, const char *filename) {
  const int max = 100 * 1000;
  int n;
  char *buffer = (char *)malloc(max);
  GLuint shader;
  FILE *f = fopen(filename, "r");
  if (!f) {
    return 0;
  }
  n = fread(buffer, 1, max, f);
  if (n > 0) {
    buffer[n] = 0;
    shader = CompileShaderText(shaderType, buffer);
  } else {
    return 0;
  }
  fclose(f);
  free(buffer);
  return shader;
}


x86 assembly (clang, -O0):
<CompileShaderFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x186a0,-0x14(%rbp)
mov    $0x186a0,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11af <CompileShaderFile+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1217 <CompileShaderFile+0xb7>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x186a0,%edx
call   1050 <fread@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11f3 <CompileShaderFile+0x93>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <CompileShaderText@plt>
mov    %eax,-0x24(%rbp)
jmp    11ff <CompileShaderFile+0x9f>
movl   $0x0,-0x4(%rbp)
jmp    1217 <CompileShaderFile+0xb7>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompileShaderFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %edi,%r14d
mov    $0x186a0,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d0 <CompileShaderFile+0x70>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x186a0,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    11d0 <CompileShaderFile+0x70>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <CompileShaderText@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14d,%eax
jmp    11d2 <CompileShaderFile+0x72>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @CompileShaderFile(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 100000, i32* %6
%11 = call i64 @malloc(i32 100000)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %10
%15 = load i32*, i32** %10
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %2
store i32 0, i32* %3
br label %39
18: ; preds = %2
%19 = load i8*, i8** %8
%20 = load i32*, i32** %10
%21 = call i32 @fread(i8* %19, i32 1, i32 100000, i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %18
%25 = load i8*, i8** %8
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %4
%30 = load i8*, i8** %8
%31 = call i32 @CompileShaderText(i32 %29, i8* %30)
store i32 %31, i32* %9
br label %33
32: ; preds = %18
store i32 0, i32* %3
br label %39
33: ; preds = %24
%34 = load i32*, i32** %10
%35 = call i32 @fclose(i32* %34)
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %9
store i32 %38, i32* %3
br label %39
39: ; preds = %33, %32, %17
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @CompileShaderFile(i32 %0, i8* nocapture %1) {
%3 = tail call i64 @malloc(i32 100000)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = tail call i32 @fread(i8* %4, i32 1, i32 100000, i32* %5)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = zext i32 %8 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 0, i8* %12
%13 = tail call i32 @CompileShaderText(i32 %0, i8* %4)
%14 = tail call i32 @fclose(i32* %5)
%15 = tail call i32 @free(i8* %4)
br label %16
16: ; preds = %7, %2, %10
%17 = phi i32 [ %13, %10 ], [ 0, %2 ], [ 0, %7 ]
ret i32 %17
}