#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 scalar_t__ GLint;

/* Variables and functions */
int /*<<< orphan*/ GL_RGB;
int /*<<< orphan*/ GL_RGBA;
int /*<<< orphan*/ GL_TEXTURE_2D;
int /*<<< orphan*/ GL_UNPACK_ALIGNMENT;
int /*<<< orphan*/ GL_UNSIGNED_BYTE;
int /*<<< orphan*/ glPixelStorei(int /*<<< orphan*/, int);
int /*<<< orphan*/ glTexImage2D(int /*<<< orphan*/, scalar_t__, scalar_t__, int,
                                int, scalar_t__, int /*<<< orphan*/,
                                int /*<<< orphan*/, unsigned char *);
int /*<<< orphan*/ gluBuild2DMipmaps(int /*<<< orphan*/, scalar_t__, int, int,
                                     int /*<<< orphan*/, int /*<<< orphan*/,
                                     unsigned char *);
int /*<<< orphan*/ stbi_failure_reason();
int /*<<< orphan*/ stbi_image_free(unsigned char *);
unsigned char *stbi_load(char const *, int *, int *, int *, int);
int /*<<< orphan*/ verbose(char *, char const *, scalar_t__, int, int);
int /*<<< orphan*/ warn(char *, char const *, int /*<<< orphan*/);
int texture_load(const char *filename, GLint level, GLint internalFormat,
                 int *width, int *height, GLint border, bool use_alpha) {
  int w, h, comps;
  unsigned char *data = stbi_load(filename, &w, &h, &comps, use_alpha ? 4 : 3);
  if (!data) {
    warn("%s:error loading:%s\n", filename, stbi_failure_reason());
    return -1;
  }
  verbose("%s:%d:loaded %dx%d\n", filename, level, w, h);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  if (level >= 0) {
    glTexImage2D(GL_TEXTURE_2D, level, internalFormat, w, h, border,
                 use_alpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, data);
  } else {
    gluBuild2DMipmaps(GL_TEXTURE_2D, internalFormat, w, h,
                      use_alpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, data);
  }
  stbi_image_free(data);
  if (width)
    *width = w;
  if (height)
    *height = h;
  return 0;
}


x86 assembly (clang, -O0):
<texture_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x10(%rbp),%ecx
mov    $0x3,%r8d
mov    $0x4,%eax
cmp    $0x0,%ecx
cmovne %eax,%r8d
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x44(%rbp),%rcx
call   1070 <stbi_load@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    120c <texture_load+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1060 <stbi_failure_reason@plt>
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
lea    0xe05(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a4 <texture_load+0x224>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
lea    0xdf3(%rip),%rdi
call   1090 <verbose@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <glPixelStorei@plt>
cmpq   $0x0,-0x18(%rbp)
jl     12dc <texture_load+0x15c>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
cmpl   $0x0,0x10(%rbp)
je     1290 <texture_load+0x110>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
jmp    129c <texture_load+0x11c>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    -0x60(%rbp),%r9
mov    -0x64(%rbp),%r8d
mov    -0x68(%rbp),%ecx
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rsi
mov    -0x7c(%rbp),%edi
mov    -0x80(%rbp),%r11d
mov    0x2d03(%rip),%rax
mov    (%rax),%r10d
mov    -0x50(%rbp),%rax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <glTexImage2D@plt>
jmp    136c <texture_load+0x1ec>
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x84(%rbp)
cmpl   $0x0,0x10(%rbp)
je     1326 <texture_load+0x1a6>
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
jmp    1335 <texture_load+0x1b5>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    -0x84(%rbp),%ecx
mov    -0x88(%rbp),%edx
mov    -0x90(%rbp),%rsi
mov    -0x94(%rbp),%edi
mov    -0x98(%rbp),%r8d
mov    0x2c64(%rip),%rax
mov    (%rax),%r9d
mov    -0x50(%rbp),%rax
mov    %rax,(%rsp)
call   10a0 <gluBuild2DMipmaps@plt>
mov    -0x50(%rbp),%rdi
call   1080 <stbi_image_free@plt>
cmpq   $0x0,-0x28(%rbp)
je     1389 <texture_load+0x209>
mov    -0x3c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     139d <texture_load+0x21d>
mov    -0x40(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<texture_load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,%r15
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r12
cmpl   $0x1,0x50(%rsp)
mov    $0x4,%r8d
sbb    $0x0,%r8d
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
lea    0x14(%rsp),%rcx
call   1070 <stbi_load@plt>
test   %rax,%rax
je     1208 <texture_load+0x88>
mov    %rax,%rbx
mov    0x4(%rsp),%ecx
mov    (%rsp),%r8d
lea    0xe3b(%rip),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1090 <verbose@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <glPixelStorei@plt>
cmpl   $0x0,0x50(%rsp)
jne    122a <texture_load+0xaa>
mov    0x2de2(%rip),%rax
jmp    1231 <texture_load+0xb1>
xor    %eax,%eax
call   1060 <stbi_failure_reason@plt>
lea    0xdea(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <warn@plt>
mov    $0xffffffff,%eax
jmp    12ab <texture_load+0x12b>
mov    0x2dbf(%rip),%rax
mov    0x2d90(%rip),%rcx
mov    (%rcx),%edi
mov    0x4(%rsp),%ecx
mov    (%rsp),%r8d
mov    (%rax),%r10d
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
test   %rbp,%rbp
js     1271 <texture_load+0xf1>
mov    %rbp,%rsi
mov    %r14,%rdx
mov    0x10(%rsp),%r9
push   %rbx
push   %rax
push   %r10
call   1040 <glTexImage2D@plt>
add    $0x20,%rsp
jmp    1289 <texture_load+0x109>
mov    %r14,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r10d,%r8d
mov    %eax,%r9d
push   %rbx
call   10a0 <gluBuild2DMipmaps@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1080 <stbi_image_free@plt>
test   %r13,%r13
je     129e <texture_load+0x11e>
mov    0x4(%rsp),%eax
mov    %eax,0x0(%r13)
xor    %eax,%eax
test   %r15,%r15
je     12ab <texture_load+0x12b>
mov    (%rsp),%ecx
mov    %ecx,(%r15)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%s:error loading:%s\0A\00"
@.str.1 = [20 x i8] c"%s:%d:loaded %dx%d\0A\00"
@GL_UNPACK_ALIGNMENT = global i32 0
@GL_TEXTURE_2D = global i32 0
@GL_RGBA = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
define i32 @texture_load(i8* %0, i64 %1, i64 %2, i32* %3, i32* %4, i64 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8*
store i8* %0, i8** %9
store i64 %1, i64* %10
store i64 %2, i64* %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i64 %5, i64* %14
store i32 %6, i32* %15
%20 = load i8*, i8** %9
%21 = load i32, i32* %15
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 4, i32 3
%25 = call i8* @stbi_load(i8* %20, i32* %16, i32* %17, i32* %18, i32 %24)
store i8* %25, i8** %19
%26 = load i8*, i8** %19
%27 = icmp ne i8* %26, null
br i1 %27, label %32, label %28
28: ; preds = %7
%29 = load i8*, i8** %9
%30 = call i32 (...) @stbi_failure_reason()
%31 = call i32 @warn(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30)
store i32 -1, i32* %8
br label %91
32: ; preds = %7
%33 = load i8*, i8** %9
%34 = load i64, i64* %10
%35 = load i32, i32* %16
%36 = load i32, i32* %17
%37 = call i32 @verbose(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %33, i64 %34, i32 %35, i32 %36)
%38 = load i32, i32* @GL_UNPACK_ALIGNMENT
%39 = call i32 @glPixelStorei(i32 %38, i32 1)
%40 = load i64, i64* %10
%41 = icmp sge i64 %40, 0
br i1 %41, label %42, label %60
42: ; preds = %32
%43 = load i32, i32* @GL_TEXTURE_2D
%44 = load i64, i64* %10
%45 = load i64, i64* %11
%46 = load i32, i32* %16
%47 = load i32, i32* %17
%48 = load i64, i64* %14
%49 = load i32, i32* %15
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = load i32, i32* @GL_RGBA
br label %55
53: ; preds = %42
%54 = load i32, i32* @GL_RGB
br label %55
55: ; preds = %53, %51
%56 = phi i32 [ %52, %51 ], [ %54, %53 ]
%57 = load i32, i32* @GL_UNSIGNED_BYTE
%58 = load i8*, i8** %19
%59 = call i32 @glTexImage2D(i32 %43, i64 %44, i64 %45, i32 %46, i32 %47, i64 %48, i32 %56, i32 %57, i8* %58)
br label %76
60: ; preds = %32
%61 = load i32, i32* @GL_TEXTURE_2D
%62 = load i64, i64* %11
%63 = load i32, i32* %16
%64 = load i32, i32* %17
%65 = load i32, i32* %15
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %60
%68 = load i32, i32* @GL_RGBA
br label %71
69: ; preds = %60
%70 = load i32, i32* @GL_RGB
br label %71
71: ; preds = %69, %67
%72 = phi i32 [ %68, %67 ], [ %70, %69 ]
%73 = load i32, i32* @GL_UNSIGNED_BYTE
%74 = load i8*, i8** %19
%75 = call i32 @gluBuild2DMipmaps(i32 %61, i64 %62, i32 %63, i32 %64, i32 %72, i32 %73, i8* %74)
br label %76
76: ; preds = %71, %55
%77 = load i8*, i8** %19
%78 = call i32 @stbi_image_free(i8* %77)
%79 = load i32*, i32** %12
%80 = icmp ne i32* %79, null
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = load i32, i32* %16
%83 = load i32*, i32** %12
store i32 %82, i32* %83
br label %84
84: ; preds = %81, %76
%85 = load i32*, i32** %13
%86 = icmp ne i32* %85, null
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i32, i32* %17
%89 = load i32*, i32** %13
store i32 %88, i32* %89
br label %90
90: ; preds = %87, %84
store i32 0, i32* %8
br label %91
91: ; preds = %90, %28
%92 = load i32, i32* %8
ret i32 %92
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s:error loading:%s\0A\00"
@.str.1 = [20 x i8] c"%s:%d:loaded %dx%d\0A\00"
@GL_UNPACK_ALIGNMENT = global i32 0
@GL_TEXTURE_2D = global i32 0
@GL_RGBA = global i32 0
@GL_RGB = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
define i32 @texture_load(i8* %0, i64 %1, i64 %2, i32* writeonly %3, i32* writeonly %4, i64 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = bitcast i32* %8 to i8*
%12 = bitcast i32* %9 to i8*
%13 = bitcast i32* %10 to i8*
%14 = icmp eq i32 %6, 0
%15 = select i1 %14, i32 3, i32 4
%16 = call i8* @stbi_load(i8* %0, i32* %8, i32* %9, i32* %10, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %7
%19 = call i32 (...) @stbi_failure_reason()
%20 = call i32 @warn(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %19)
br label %48
21: ; preds = %7
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = call i32 @verbose(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %1, i32 %22, i32 %23)
%25 = load i32, i32* @GL_UNPACK_ALIGNMENT
%26 = call i32 @glPixelStorei(i32 %25, i32 1)
%27 = icmp sgt i64 %1, -1
%28 = load i32, i32* @GL_TEXTURE_2D
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = load i32, i32* @GL_RGBA
%32 = load i32, i32* @GL_RGB
%33 = select i1 %14, i32 %32, i32 %31
%34 = load i32, i32* @GL_UNSIGNED_BYTE
br i1 %27, label %35, label %37
35: ; preds = %21
%36 = call i32 @glTexImage2D(i32 %28, i64 %1, i64 %2, i32 %29, i32 %30, i64 %5, i32 %33, i32 %34, i8* %16)
br label %39
37: ; preds = %21
%38 = call i32 @gluBuild2DMipmaps(i32 %28, i64 %2, i32 %29, i32 %30, i32 %33, i32 %34, i8* %16)
br label %39
39: ; preds = %37, %35
%40 = call i32 @stbi_image_free(i8* %16)
%41 = icmp eq i32* %3, null
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = load i32, i32* %8
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %39
%45 = icmp eq i32* %4, null
br i1 %45, label %48, label %46
46: ; preds = %44
%47 = load i32, i32* %9
store i32 %47, i32* %4
br label %48
48: ; preds = %44, %46, %18
%49 = phi i32 [ -1, %18 ], [ 0, %46 ], [ 0, %44 ]
ret i32 %49
}