#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_CLAMP;
int /*<<< orphan*/ GL_LINEAR;
int /*<<< orphan*/ GL_LINEAR_MIPMAP_NEAREST;
int /*<<< orphan*/ GL_MODULATE;
int /*<<< orphan*/ GL_REPEAT;
int /*<<< orphan*/ GL_RGB;
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, int, int,
                                     int /*<<< orphan*/, int /*<<< orphan*/,
                                     unsigned char *);
unsigned char *malloc(int);
GLuint LoadTextureRAW(const char *filename, int wrap) {
  GLuint texture;
  int width, height;
  unsigned char *data;
  FILE *file;
  file = fopen(filename, "rb");
  if (file == NULL)
    return 0;
  width = 256;
  height = 256;
  data = 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_NEAREST);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                  wrap ? GL_REPEAT : GL_CLAMP);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                  wrap ? GL_REPEAT : GL_CLAMP);
  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE,
                    data);
  free(data);
  return texture;
}


x86 assembly (clang, -O0):
<LoadTextureRAW>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11da <LoadTextureRAW+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    137d <LoadTextureRAW+0x1dd>
movl   $0x100,-0x1c(%rbp)
movl   $0x100,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
imul   $0x3,%eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
imul   -0x20(%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    -0x18(%rbp),%rsi
call   1090 <glGenTextures@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
call   10b0 <glBindTexture@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
call   1060 <glTexEnvf@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
mov    0x2cf8(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12d2 <LoadTextureRAW+0x132>
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    12de <LoadTextureRAW+0x13e>
mov    0x2d1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%edx
call   1080 <glTexParameterf@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     131f <LoadTextureRAW+0x17f>
mov    0x2c83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
jmp    132b <LoadTextureRAW+0x18b>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%esi
mov    -0x44(%rbp),%edi
mov    -0x48(%rbp),%edx
call   1080 <glTexParameterf@plt>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    0x2c99(%rip),%rax
mov    (%rax),%r8d
mov    0x2c37(%rip),%rax
mov    (%rax),%r9d
mov    -0x28(%rbp),%rax
mov    $0x3,%esi
mov    %rax,(%rsp)
call   10c0 <gluBuild2DMipmaps@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadTextureRAW>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127f <LoadTextureRAW+0xdf>
mov    %rax,%rbp
mov    $0x30000,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x30000,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0x14(%rsp),%rsi
mov    $0x1,%edi
call   1090 <glGenTextures@plt>
mov    0x2d9b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x14(%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    0x0(%rbp),%edi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x0(%rbp),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
mov    0x2d72(%rip),%rax
mov    (%rax),%edx
call   1080 <glTexParameterf@plt>
mov    0x0(%rbp),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
test   %r14d,%r14d
jne    1283 <LoadTextureRAW+0xe3>
mov    0x2d7b(%rip),%rbx
jmp    128a <LoadTextureRAW+0xea>
xor    %eax,%eax
jmp    12df <LoadTextureRAW+0x13f>
mov    0x2d0e(%rip),%rbx
mov    (%rbx),%edx
call   1080 <glTexParameterf@plt>
mov    0x0(%rbp),%edi
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
call   1080 <glTexParameterf@plt>
mov    0x0(%rbp),%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%r8d
mov    0x2cd8(%rip),%rax
mov    (%rax),%r9d
mov    %r15,(%rsp)
mov    $0x3,%esi
mov    $0x100,%edx
mov    $0x100,%ecx
call   10c0 <gluBuild2DMipmaps@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x14(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
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_NEAREST = global i32 0
@GL_TEXTURE_MAG_FILTER = global i32 0
@GL_LINEAR = global i32 0
@GL_TEXTURE_WRAP_S = global i32 0
@GL_REPEAT = global i32 0
@GL_CLAMP = global i32 0
@GL_TEXTURE_WRAP_T = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
define i32 @LoadTextureRAW(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i8*, i8** %4
%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 = %2
store i32 0, i32* %3
br label %79
16: ; preds = %2
store i32 256, i32* %7
store i32 256, i32* %8
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
%20 = mul nsw i32 %19, 3
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = mul nsw i32 %23, %24
%26 = mul nsw i32 %25, 3
%27 = load i32*, i32** %10
%28 = call i32 @fread(i8* %22, i32 %26, i32 1, i32* %27)
%29 = load i32*, i32** %10
%30 = call i32 @fclose(i32* %29)
%31 = call i32 @glGenTextures(i32 1, i32* %6)
%32 = load i32, i32* @GL_TEXTURE_2D
%33 = load i32, i32* %6
%34 = call i32 @glBindTexture(i32 %32, i32 %33)
%35 = load i32, i32* @GL_TEXTURE_ENV
%36 = load i32, i32* @GL_TEXTURE_ENV_MODE
%37 = load i32, i32* @GL_MODULATE
%38 = call i32 @glTexEnvf(i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* @GL_TEXTURE_2D
%40 = load i32, i32* @GL_TEXTURE_MIN_FILTER
%41 = load i32, i32* @GL_LINEAR_MIPMAP_NEAREST
%42 = call i32 @glTexParameterf(i32 %39, i32 %40, i32 %41)
%43 = load i32, i32* @GL_TEXTURE_2D
%44 = load i32, i32* @GL_TEXTURE_MAG_FILTER
%45 = load i32, i32* @GL_LINEAR
%46 = call i32 @glTexParameterf(i32 %43, i32 %44, i32 %45)
%47 = load i32, i32* @GL_TEXTURE_2D
%48 = load i32, i32* @GL_TEXTURE_WRAP_S
%49 = load i32, i32* %5
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %16
%52 = load i32, i32* @GL_REPEAT
br label %55
53: ; preds = %16
%54 = load i32, i32* @GL_CLAMP
br label %55
55: ; preds = %53, %51
%56 = phi i32 [ %52, %51 ], [ %54, %53 ]
%57 = call i32 @glTexParameterf(i32 %47, i32 %48, i32 %56)
%58 = load i32, i32* @GL_TEXTURE_2D
%59 = load i32, i32* @GL_TEXTURE_WRAP_T
%60 = load i32, i32* %5
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %55
%63 = load i32, i32* @GL_REPEAT
br label %66
64: ; preds = %55
%65 = load i32, i32* @GL_CLAMP
br label %66
66: ; preds = %64, %62
%67 = phi i32 [ %63, %62 ], [ %65, %64 ]
%68 = call i32 @glTexParameterf(i32 %58, i32 %59, i32 %67)
%69 = load i32, i32* @GL_TEXTURE_2D
%70 = load i32, i32* %7
%71 = load i32, i32* %8
%72 = load i32, i32* @GL_RGB
%73 = load i32, i32* @GL_UNSIGNED_BYTE
%74 = load i8*, i8** %9
%75 = call i32 @gluBuild2DMipmaps(i32 %69, i32 3, i32 %70, i32 %71, i32 %72, i32 %73, i8* %74)
%76 = load i8*, i8** %9
%77 = call i32 @free(i8* %76)
%78 = load i32, i32* %6
store i32 %78, i32* %3
br label %79
79: ; preds = %66, %15
%80 = load i32, i32* %3
ret i32 %80
}

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_NEAREST = global i32 0
@GL_TEXTURE_MAG_FILTER = global i32 0
@GL_LINEAR = global i32 0
@GL_TEXTURE_WRAP_S = global i32 0
@GL_REPEAT = global i32 0
@GL_CLAMP = global i32 0
@GL_TEXTURE_WRAP_T = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
define i32 @LoadTextureRAW(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %46, label %7
7: ; preds = %2
%8 = tail call dereferenceable_or_null(196608) i8* @malloc(i32 196608)
%9 = tail call i32 @fread(i8* %8, i32 196608, i32 1, i32* %5)
%10 = tail call i32 @fclose(i32* %5)
%11 = call i32 @glGenTextures(i32 1, i32* %3)
%12 = load i32, i32* @GL_TEXTURE_2D
%13 = load i32, i32* %3
%14 = call i32 @glBindTexture(i32 %12, i32 %13)
%15 = load i32, i32* @GL_TEXTURE_ENV
%16 = load i32, i32* @GL_TEXTURE_ENV_MODE
%17 = load i32, i32* @GL_MODULATE
%18 = call i32 @glTexEnvf(i32 %15, i32 %16, i32 %17)
%19 = load i32, i32* @GL_TEXTURE_2D
%20 = load i32, i32* @GL_TEXTURE_MIN_FILTER
%21 = load i32, i32* @GL_LINEAR_MIPMAP_NEAREST
%22 = call i32 @glTexParameterf(i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* @GL_TEXTURE_2D
%24 = load i32, i32* @GL_TEXTURE_MAG_FILTER
%25 = load i32, i32* @GL_LINEAR
%26 = call i32 @glTexParameterf(i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* @GL_TEXTURE_2D
%28 = load i32, i32* @GL_TEXTURE_WRAP_S
%29 = icmp eq i32 %1, 0
%30 = load i32, i32* @GL_REPEAT
%31 = load i32, i32* @GL_CLAMP
%32 = select i1 %29, i32 %31, i32 %30
%33 = call i32 @glTexParameterf(i32 %27, i32 %28, i32 %32)
%34 = load i32, i32* @GL_TEXTURE_2D
%35 = load i32, i32* @GL_TEXTURE_WRAP_T
%36 = load i32, i32* @GL_REPEAT
%37 = load i32, i32* @GL_CLAMP
%38 = select i1 %29, i32 %37, i32 %36
%39 = call i32 @glTexParameterf(i32 %34, i32 %35, i32 %38)
%40 = load i32, i32* @GL_TEXTURE_2D
%41 = load i32, i32* @GL_RGB
%42 = load i32, i32* @GL_UNSIGNED_BYTE
%43 = call i32 @gluBuild2DMipmaps(i32 %40, i32 3, i32 256, i32 256, i32 %41, i32 %42, i8* %8)
%44 = call i32 @free(i8* %8)
%45 = load i32, i32* %3
br label %46
46: ; preds = %2, %7
%47 = phi i32 [ %45, %7 ], [ 0, %2 ]
ret i32 %47
}