#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ stbi_error(char *);
unsigned char *stbi_load_from_file(int /*<<< orphan*/ *, int *, int *, int *,
                                   int);
unsigned char *stbi_load(char const *filename, int *x, int *y, int *comp,
                         int req_comp) {
  FILE *f = fopen(filename, "rb");
  unsigned char *result;
  if (!f)
    return ((unsigned char *)(stbi_error("Unable to open file") ? NULL : NULL));
  result = stbi_load_from_file(f, x, y, comp, req_comp);
  fclose(f);
  return result;
}


x86 assembly (clang, -O0):
<stbi_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119d <stbi_load+0x5d>
lea    0xe81(%rip),%rdi
call   1060 <stbi_error@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
cmovne %rax,%rax
mov    %rax,-0x8(%rbp)
jmp    11cb <stbi_load+0x8b>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1040 <stbi_load_from_file@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stbi_load>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118c <stbi_load+0x4c>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1040 <stbi_load_from_file@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
jmp    119a <stbi_load+0x5a>
lea    0xe70(%rip),%rdi
call   1060 <stbi_error@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [20 x i8] c"Unable to open file\00"
define i8* @stbi_load(i8* %0, i32* %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i8*
store i8* %0, i8** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%14 = load i8*, i8** %7
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %12
%16 = load i32*, i32** %12
%17 = icmp ne i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %5
%19 = call i64 @stbi_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* null, i8* null
store i8* %22, i8** %6
br label %33
23: ; preds = %5
%24 = load i32*, i32** %12
%25 = load i32*, i32** %8
%26 = load i32*, i32** %9
%27 = load i32*, i32** %10
%28 = load i32, i32* %11
%29 = call i8* @stbi_load_from_file(i32* %24, i32* %25, i32* %26, i32* %27, i32 %28)
store i8* %29, i8** %13
%30 = load i32*, i32** %12
%31 = call i32 @fclose(i32* %30)
%32 = load i8*, i8** %13
store i8* %32, i8** %6
br label %33
33: ; preds = %23, %18
%34 = load i8*, i8** %6
ret i8* %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [20 x i8] c"Unable to open file\00"
define i8* @stbi_load(i8* nocapture %0, i32* %1, i32* %2, i32* %3, i32 %4) {
%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 %8, label %10
8: ; preds = %5
%9 = tail call i64 @stbi_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %5
%11 = tail call i8* @stbi_load_from_file(i32* %6, i32* %1, i32* %2, i32* %3, i32 %4)
%12 = tail call i32 @fclose(i32* %6)
br label %13
13: ; preds = %10, %8
%14 = phi i8* [ %11, %10 ], [ null, %8 ]
ret i8* %14
}