#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 *, char *);
unsigned char *stbi_png_load_from_file(int /*<<< orphan*/ *, int *, int *,
                                       int *, int);
unsigned char *stbi_png_load(char *filename, int *x, int *y, int *comp,
                             int req_comp) {
  unsigned char *data;
  FILE *f = fopen(filename, "rb");
  if (!f)
    return NULL;
  data = stbi_png_load_from_file(f, x, y, comp, req_comp);
  fclose(f);
  return data;
}


x86 assembly (clang, -O0):
<stbi_png_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    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1178 <stbi_png_load+0x48>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <stbi_png_load+0x76>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1040 <stbi_png_load_from_file@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stbi_png_load>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbp
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117c <stbi_png_load+0x4c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1040 <stbi_png_load_from_file@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rbp,%rax
jmp    117e <stbi_png_load+0x4e>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i8* @stbi_png_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 i8*
%13 = alloca i32*
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** %13
%16 = load i32*, i32** %13
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %5
store i8* null, i8** %6
br label %29
19: ; preds = %5
%20 = load i32*, i32** %13
%21 = load i32*, i32** %8
%22 = load i32*, i32** %9
%23 = load i32*, i32** %10
%24 = load i32, i32* %11
%25 = call i8* @stbi_png_load_from_file(i32* %20, i32* %21, i32* %22, i32* %23, i32 %24)
store i8* %25, i8** %12
%26 = load i32*, i32** %13
%27 = call i32 @fclose(i32* %26)
%28 = load i8*, i8** %12
store i8* %28, i8** %6
br label %29
29: ; preds = %19, %18
%30 = load i8*, i8** %6
ret i8* %30
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i8* @stbi_png_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 %11, label %8
8: ; preds = %5
%9 = tail call i8* @stbi_png_load_from_file(i32* %6, i32* %1, i32* %2, i32* %3, i32 %4)
%10 = tail call i32 @fclose(i32* %6)
br label %11
11: ; preds = %5, %8
%12 = phi i8* [ %9, %8 ], [ null, %5 ]
ret i8* %12
}