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

/* Variables and functions */
scalar_t__ check_tga(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
void *load_tga(int /*<<< orphan*/ *, unsigned int *, unsigned int *);
int /*<<< orphan*/ stderr;
void *load_image(const char *fname, unsigned int *xsz, unsigned int *ysz) {
  FILE *file;
  if (!(file = fopen(fname, "rb"))) {
    fprintf(stderr, "Image loading error: could not open file %s\n", fname);
    return 0;
  }
  if (check_tga(file)) {
    return load_tga(file, xsz, ysz);
  }
  return 0;
}


x86 assembly (clang, -O0):
<load_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1198 <load_image+0x58>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cd <load_image+0x8d>
mov    -0x28(%rbp),%rdi
call   1060 <check_tga@plt>
cmp    $0x0,%rax
je     11c5 <load_image+0x85>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <load_tga@plt>
mov    %rax,-0x8(%rbp)
jmp    11cd <load_image+0x8d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_image>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118b <load_image+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <check_tga@plt>
test   %rax,%rax
je     11a3 <load_image+0x63>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <load_tga@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    %r12,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [45 x i8] c"Image loading error: could not open file %s\0A\00"
define i8* @load_image(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i8* null, i8** %4
br label %26
16: ; preds = %3
%17 = load i32*, i32** %8
%18 = call i64 @check_tga(i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32*, i32** %8
%22 = load i32*, i32** %6
%23 = load i32*, i32** %7
%24 = call i8* @load_tga(i32* %21, i32* %22, i32* %23)
store i8* %24, i8** %4
br label %26
25: ; preds = %16
store i8* null, i8** %4
br label %26
26: ; preds = %25, %20, %12
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [45 x i8] c"Image loading error: could not open file %s\0A\00"
define i8* @load_image(i8* %0, i32* %1, i32* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %14
9: ; preds = %3
%10 = tail call i64 @check_tga(i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i8* @load_tga(i32* %4, i32* %1, i32* %2)
br label %14
14: ; preds = %9, %12, %6
%15 = phi i8* [ %13, %12 ], [ null, %6 ], [ null, %9 ]
ret i8* %15
}