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

/* Variables and functions */
int /*<<< orphan*/ GL_BGRA;
int /*<<< orphan*/ GL_LINEAR;
int /*<<< orphan*/ GL_REPEAT;
int /*<<< orphan*/ GL_TEXTURE_2D;
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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ glBindTexture(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ glGenTextures(int, unsigned int *);
int /*<<< orphan*/ glTexImage2D(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                unsigned int, unsigned int, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                unsigned int *);
int /*<<< orphan*/ glTexParameteri(int /*<<< orphan*/, int /*<<< orphan*/,
                                   int /*<<< orphan*/);
unsigned int *load_image(char const *, unsigned int *, unsigned int *);
int /*<<< orphan*/ stderr;
int load_texture(const char *fname) {
  unsigned int tex_id;
  unsigned int *img, x, y;
  if (!(img = load_image(fname, &x, &y))) {
    fprintf(stderr, "failed loading texture \"%s\"\n", fname);
    return 0;
  }
  glGenTextures(1, &tex_id);
  glBindTexture(GL_TEXTURE_2D, tex_id);
  glTexImage2D(GL_TEXTURE_2D, 0, 4, x, y, 0, GL_BGRA, GL_UNSIGNED_BYTE, img);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  return tex_id;
}


x86 assembly (clang, -O0):
<load_texture>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <load_image@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b0 <load_texture+0x50>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129b <load_texture+0x13b>
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
call   1070 <glGenTextures@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1080 <glBindTexture@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    0x2db2(%rip),%rax
mov    (%rax),%r11d
mov    0x2dc0(%rip),%rax
mov    (%rax),%r10d
mov    -0x20(%rbp),%rax
xor    %r9d,%r9d
mov    $0x4,%edx
mov    %r9d,%esi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <glTexImage2D@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
call   1030 <glTexParameteri@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
call   1030 <glTexParameteri@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
call   1030 <glTexParameteri@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
mov    0x2d2a(%rip),%rax
mov    (%rax),%edx
call   1030 <glTexParameteri@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_texture>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1060 <load_image@plt>
test   %rax,%rax
je     1242 <load_texture+0xe2>
mov    %rax,%r14
lea    0x4(%rsp),%rsi
mov    $0x1,%edi
call   1070 <glGenTextures@plt>
mov    0x2e2b(%rip),%r15
mov    (%r15),%edi
mov    0x4(%rsp),%esi
call   1080 <glBindTexture@plt>
mov    (%r15),%edi
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    0x2deb(%rip),%rdx
mov    (%rdx),%ebx
sub    $0x8,%rsp
xor    %esi,%esi
mov    $0x4,%edx
xor    %r9d,%r9d
push   %r14
push   %rbx
push   %rax
call   1040 <glTexImage2D@plt>
add    $0x20,%rsp
mov    (%r15),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    0x2deb(%rip),%rbx
mov    (%rbx),%edx
call   1030 <glTexParameteri@plt>
mov    (%r15),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
call   1030 <glTexParameteri@plt>
mov    (%r15),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    0x2d96(%rip),%rbx
mov    (%rbx),%edx
call   1030 <glTexParameteri@plt>
mov    (%r15),%edi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
call   1030 <glTexParameteri@plt>
mov    0x4(%rsp),%eax
jmp    125c <load_texture+0xfc>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"failed loading texture \22%s\22\0A\00"
@GL_TEXTURE_2D = global i32 0
@GL_BGRA = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
@GL_TEXTURE_MIN_FILTER = global i32 0
@GL_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
define i32 @load_texture(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @load_image(i8* %8, i32* %6, i32* %7)
store i32* %9, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 0, i32* %2
br label %44
15: ; preds = %1
%16 = call i32 @glGenTextures(i32 1, i32* %4)
%17 = load i32, i32* @GL_TEXTURE_2D
%18 = load i32, i32* %4
%19 = call i32 @glBindTexture(i32 %17, i32 %18)
%20 = load i32, i32* @GL_TEXTURE_2D
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = load i32, i32* @GL_BGRA
%24 = load i32, i32* @GL_UNSIGNED_BYTE
%25 = load i32*, i32** %5
%26 = call i32 @glTexImage2D(i32 %20, i32 0, i32 4, i32 %21, i32 %22, i32 0, i32 %23, i32 %24, i32* %25)
%27 = load i32, i32* @GL_TEXTURE_2D
%28 = load i32, i32* @GL_TEXTURE_MIN_FILTER
%29 = load i32, i32* @GL_LINEAR
%30 = call i32 @glTexParameteri(i32 %27, i32 %28, i32 %29)
%31 = load i32, i32* @GL_TEXTURE_2D
%32 = load i32, i32* @GL_TEXTURE_MAG_FILTER
%33 = load i32, i32* @GL_LINEAR
%34 = call i32 @glTexParameteri(i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* @GL_TEXTURE_2D
%36 = load i32, i32* @GL_TEXTURE_WRAP_S
%37 = load i32, i32* @GL_REPEAT
%38 = call i32 @glTexParameteri(i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* @GL_TEXTURE_2D
%40 = load i32, i32* @GL_TEXTURE_WRAP_T
%41 = load i32, i32* @GL_REPEAT
%42 = call i32 @glTexParameteri(i32 %39, i32 %40, i32 %41)
%43 = load i32, i32* %4
store i32 %43, i32* %2
br label %44
44: ; preds = %15, %11
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"failed loading texture \22%s\22\0A\00"
@GL_TEXTURE_2D = global i32 0
@GL_BGRA = global i32 0
@GL_UNSIGNED_BYTE = global i32 0
@GL_TEXTURE_MIN_FILTER = global i32 0
@GL_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
define i32 @load_texture(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32* @load_image(i8* %0, i32* %3, i32* %4)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %41
13: ; preds = %1
%14 = call i32 @glGenTextures(i32 1, i32* %2)
%15 = load i32, i32* @GL_TEXTURE_2D
%16 = load i32, i32* %2
%17 = call i32 @glBindTexture(i32 %15, i32 %16)
%18 = load i32, i32* @GL_TEXTURE_2D
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = load i32, i32* @GL_BGRA
%22 = load i32, i32* @GL_UNSIGNED_BYTE
%23 = call i32 @glTexImage2D(i32 %18, i32 0, i32 4, i32 %19, i32 %20, i32 0, i32 %21, i32 %22, i32* %8)
%24 = load i32, i32* @GL_TEXTURE_2D
%25 = load i32, i32* @GL_TEXTURE_MIN_FILTER
%26 = load i32, i32* @GL_LINEAR
%27 = call i32 @glTexParameteri(i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* @GL_TEXTURE_2D
%29 = load i32, i32* @GL_TEXTURE_MAG_FILTER
%30 = load i32, i32* @GL_LINEAR
%31 = call i32 @glTexParameteri(i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* @GL_TEXTURE_2D
%33 = load i32, i32* @GL_TEXTURE_WRAP_S
%34 = load i32, i32* @GL_REPEAT
%35 = call i32 @glTexParameteri(i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* @GL_TEXTURE_2D
%37 = load i32, i32* @GL_TEXTURE_WRAP_T
%38 = load i32, i32* @GL_REPEAT
%39 = call i32 @glTexParameteri(i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* %2
br label %41
41: ; preds = %13, %10
%42 = phi i32 [ %40, %13 ], [ 0, %10 ]
ret i32 %42
}