#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ GL_LINEAR_MIPMAP_LINEAR;
int /*<<< orphan*/ GL_MODULATE;
int /*<<< orphan*/ GL_REPEAT;
int /*<<< orphan*/ GL_RGB;
int /*<<< orphan*/ GL_RGBA;
int /*<<< orphan*/ GL_TEXTURE_2D;
int /*<<< orphan*/ GL_TEXTURE_ENV;
int /*<<< orphan*/ GL_TEXTURE_ENV_MODE;
int /*<<< orphan*/ GL_TEXTURE_MAG_FILTER;
int /*<<< orphan*/ GL_TEXTURE_MIN_FILTER;
int /*<<< orphan*/ GL_TEXTURE_WRAP_S;
int /*<<< orphan*/ GL_TEXTURE_WRAP_T;
int /*<<< orphan*/ GL_UNSIGNED_BYTE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ glBindTexture(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ glGenTextures(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ glTexEnvf(int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/);
int /*<<< orphan*/ glTexParameterf(int /*<<< orphan*/, int /*<<< orphan*/,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ gluBuild2DMipmaps(int /*<<< orphan*/, int /*<<< orphan*/,
                                     int, int, int /*<<< orphan*/,
                                     int /*<<< orphan*/, unsigned char *);
scalar_t__ malloc(int);
GLuint LoadTexture(const char *filename, int width, int height) {
  GLuint texture;
  unsigned char *data;
  FILE *file;
  file = fopen(filename, "rb");
  if (file == NULL)
    return 0;
  data = (unsigned char *)malloc(width * height * 3);
  fread(data, width * height * 3, 1, file);
  fclose(file);
  glGenTextures(1, &texture);
  glBindTexture(GL_TEXTURE_2D, texture);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                  GL_LINEAR_MIPMAP_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                  GL_LINEAR_MIPMAP_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGB,
                    GL_UNSIGNED_BYTE, data);
  free(data);
  return texture;
}


x86 assembly (clang, -O0):
<LoadTexture>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11dd <LoadTexture+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    131c <LoadTexture+0x17c>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   $0x3,%eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   $0x3,%eax,%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
lea    -0x1c(%rbp),%rsi
call   1090 <glGenTextures@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   10b0 <glBindTexture@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
call   1060 <glTexEnvf@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
mov    0x2d33(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
mov    0x2d13(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
mov    0x2ceb(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
mov    0x2cb4(%rip),%rax
mov    (%rax),%esi
mov    0x2ccb(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    0x2cf5(%rip),%rax
mov    (%rax),%r8d
mov    0x2c93(%rip),%rax
mov    (%rax),%r9d
mov    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   10c0 <gluBuild2DMipmaps@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadTexture>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
lea    0xe47(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12cf <LoadTexture+0x12f>
mov    %rax,%rbp
mov    %r15d,%eax
imul   %r14d,%eax
lea    (%rax,%rax,2),%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xc(%rsp),%rsi
mov    $0x1,%edi
call   1090 <glGenTextures@plt>
mov    0x2d9a(%rip),%rbx
mov    (%rbx),%edi
mov    0xc(%rsp),%esi
call   10b0 <glBindTexture@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
call   1060 <glTexEnvf@plt>
mov    (%rbx),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
mov    0x2d55(%rip),%rbp
mov    0x0(%rbp),%edx
call   1080 <glTexParameterf@plt>
mov    (%rbx),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
mov    0x0(%rbp),%edx
call   1080 <glTexParameterf@plt>
mov    (%rbx),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
mov    0x2d20(%rip),%rbp
mov    0x0(%rbp),%edx
call   1080 <glTexParameterf@plt>
mov    (%rbx),%edi
mov    0x2cef(%rip),%rax
mov    (%rax),%esi
mov    0x0(%rbp),%edx
call   1080 <glTexParameterf@plt>
mov    (%rbx),%edi
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
mov    0x2d43(%rip),%rax
mov    (%rax),%r8d
mov    0x2ce1(%rip),%rax
mov    (%rax),%r9d
mov    %r12,(%rsp)
mov    %r15d,%edx
mov    %r14d,%ecx
call   10c0 <gluBuild2DMipmaps@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%eax
jmp    12d1 <LoadTexture+0x131>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@GL_TEXTURE_2D = global i32 0
@GL_TEXTURE_ENV = global i32 0
@GL_TEXTURE_ENV_MODE = global i32 0
@GL_MODULATE = global i32 0
@GL_TEXTURE_MIN_FILTER = global i32 0
@GL_LINEAR_MIPMAP_LINEAR = global i32 0
@GL_TEXTURE_MAG_FILTER = global i32 0
@GL_TEXTURE_WRAP_S = global i32 0
@GL_REPEAT = global i32 0
@GL_TEXTURE_WRAP_T = global i32 0
@GL_RGBA = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
define i32 @LoadTexture(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %67
16: ; preds = %3
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = mul nsw i32 %17, %18
%20 = mul nsw i32 %19, 3
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = mul nsw i32 %24, %25
%27 = mul nsw i32 %26, 3
%28 = load i32*, i32** %10
%29 = call i32 @fread(i8* %23, i32 %27, i32 1, i32* %28)
%30 = load i32*, i32** %10
%31 = call i32 @fclose(i32* %30)
%32 = call i32 @glGenTextures(i32 1, i32* %8)
%33 = load i32, i32* @GL_TEXTURE_2D
%34 = load i32, i32* %8
%35 = call i32 @glBindTexture(i32 %33, i32 %34)
%36 = load i32, i32* @GL_TEXTURE_ENV
%37 = load i32, i32* @GL_TEXTURE_ENV_MODE
%38 = load i32, i32* @GL_MODULATE
%39 = call i32 @glTexEnvf(i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* @GL_TEXTURE_2D
%41 = load i32, i32* @GL_TEXTURE_MIN_FILTER
%42 = load i32, i32* @GL_LINEAR_MIPMAP_LINEAR
%43 = call i32 @glTexParameterf(i32 %40, i32 %41, i32 %42)
%44 = load i32, i32* @GL_TEXTURE_2D
%45 = load i32, i32* @GL_TEXTURE_MAG_FILTER
%46 = load i32, i32* @GL_LINEAR_MIPMAP_LINEAR
%47 = call i32 @glTexParameterf(i32 %44, i32 %45, i32 %46)
%48 = load i32, i32* @GL_TEXTURE_2D
%49 = load i32, i32* @GL_TEXTURE_WRAP_S
%50 = load i32, i32* @GL_REPEAT
%51 = call i32 @glTexParameterf(i32 %48, i32 %49, i32 %50)
%52 = load i32, i32* @GL_TEXTURE_2D
%53 = load i32, i32* @GL_TEXTURE_WRAP_T
%54 = load i32, i32* @GL_REPEAT
%55 = call i32 @glTexParameterf(i32 %52, i32 %53, i32 %54)
%56 = load i32, i32* @GL_TEXTURE_2D
%57 = load i32, i32* @GL_RGBA
%58 = load i32, i32* %6
%59 = load i32, i32* %7
%60 = load i32, i32* @GL_RGB
%61 = load i32, i32* @GL_UNSIGNED_BYTE
%62 = load i8*, i8** %9
%63 = call i32 @gluBuild2DMipmaps(i32 %56, i32 %57, i32 %58, i32 %59, i32 %60, i32 %61, i8* %62)
%64 = load i8*, i8** %9
%65 = call i32 @free(i8* %64)
%66 = load i32, i32* %8
store i32 %66, i32* %4
br label %67
67: ; preds = %16, %15
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@GL_TEXTURE_2D = global i32 0
@GL_TEXTURE_ENV = global i32 0
@GL_TEXTURE_ENV_MODE = global i32 0
@GL_MODULATE = global i32 0
@GL_TEXTURE_MIN_FILTER = global i32 0
@GL_LINEAR_MIPMAP_LINEAR = global i32 0
@GL_TEXTURE_MAG_FILTER = global i32 0
@GL_TEXTURE_WRAP_S = global i32 0
@GL_REPEAT = global i32 0
@GL_TEXTURE_WRAP_T = global i32 0
@GL_RGBA = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
define i32 @LoadTexture(i8* nocapture %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %46, label %8
8: ; preds = %3
%9 = mul i32 %1, 3
%10 = mul i32 %9, %2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @fread(i8* %12, i32 %10, i32 1, i32* %6)
%14 = tail call i32 @fclose(i32* %6)
%15 = call i32 @glGenTextures(i32 1, i32* %4)
%16 = load i32, i32* @GL_TEXTURE_2D
%17 = load i32, i32* %4
%18 = call i32 @glBindTexture(i32 %16, i32 %17)
%19 = load i32, i32* @GL_TEXTURE_ENV
%20 = load i32, i32* @GL_TEXTURE_ENV_MODE
%21 = load i32, i32* @GL_MODULATE
%22 = call i32 @glTexEnvf(i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* @GL_TEXTURE_2D
%24 = load i32, i32* @GL_TEXTURE_MIN_FILTER
%25 = load i32, i32* @GL_LINEAR_MIPMAP_LINEAR
%26 = call i32 @glTexParameterf(i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* @GL_TEXTURE_2D
%28 = load i32, i32* @GL_TEXTURE_MAG_FILTER
%29 = load i32, i32* @GL_LINEAR_MIPMAP_LINEAR
%30 = call i32 @glTexParameterf(i32 %27, i32 %28, i32 %29)
%31 = load i32, i32* @GL_TEXTURE_2D
%32 = load i32, i32* @GL_TEXTURE_WRAP_S
%33 = load i32, i32* @GL_REPEAT
%34 = call i32 @glTexParameterf(i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* @GL_TEXTURE_2D
%36 = load i32, i32* @GL_TEXTURE_WRAP_T
%37 = load i32, i32* @GL_REPEAT
%38 = call i32 @glTexParameterf(i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* @GL_TEXTURE_2D
%40 = load i32, i32* @GL_RGBA
%41 = load i32, i32* @GL_RGB
%42 = load i32, i32* @GL_UNSIGNED_BYTE
%43 = call i32 @gluBuild2DMipmaps(i32 %39, i32 %40, i32 %1, i32 %2, i32 %41, i32 %42, i8* %12)
%44 = call i32 @free(i8* %12)
%45 = load i32, i32* %4
br label %46
46: ; preds = %3, %8
%47 = phi i32 [ %45, %8 ], [ 0, %3 ]
ret i32 %47
}