#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_chunk(int /*<<< orphan*/ *, int, char *);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fstat(int /*<<< orphan*/, struct stat *);
void load_extra(char *filename) {
  FILE *f;
  struct stat sb;
  int filesize;
  f = fopen(filename, "rb");
  if (!f)
    err(1, "fopen: %s", filename);
  if (fstat(fileno(f), &sb))
    err(1, "fstat: %s", filename);
  filesize = (int)sb.st_size;
  add_chunk(f, filesize, filename);
  fclose(f);
}


x86 assembly (clang, -O0):
<load_extra>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <load_extra+0x40>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe68(%rip),%rsi
call   1060 <err@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
je     11d3 <load_extra+0x73>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe3f(%rip),%rsi
call   1060 <err@plt>
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1040 <add_chunk@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_extra>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118f <load_extra+0x2f>
lea    0xe81(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1060 <err@plt>
mov    %rbx,%rdi
call   1050 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1080 <fstat@plt>
test   %rax,%rax
je     11ba <load_extra+0x5a>
lea    0xe60(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1060 <err@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <add_chunk@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [10 x i8] c"fopen: %s\00"
@.str.2 = [10 x i8] c"fstat: %s\00"
define void @load_extra(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %1
%14 = load i32*, i32** %3
%15 = call i32 @fileno(i32* %14)
%16 = call i64 @fstat(i32 %15, %struct.stat* %4)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %13
%22 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
store i32 %24, i32* %5
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = load i8*, i8** %2
%28 = call i32 @add_chunk(i32* %25, i32 %26, i8* %27)
%29 = load i32*, i32** %3
%30 = call i32 @fclose(i32* %29)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [10 x i8] c"fopen: %s\00"
@.str.2 = [10 x i8] c"fstat: %s\00"
define void @load_extra(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%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 %8
6: ; preds = %1
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %1
%9 = tail call i32 @fileno(i32* %4)
%10 = call i64 @fstat(i32 %9, %struct.stat* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %8
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = tail call i32 @add_chunk(i32* %4, i32 %17, i8* %0)
%19 = tail call i32 @fclose(i32* %4)
ret void
}