#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 uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
size_t init_load(const char *source_fname) {
  uint64_t end_address;
  FILE *fd;
  fd = fopen(source_fname, "rb");
  if (fd == NULL) {
    perror("unable to open input file");
    exit(1);
  }
  fseek(fd, 4 * 8, SEEK_SET);
  if (fread(&end_address, 8, 1, fd) != 1) {
    perror("unable to read input file header");
    exit(1);
  }
  if (end_address > 0x1000000) {
    fputs("end_address invalid", stderr);
    exit(1);
  }
  fclose(fd);
  return (size_t)end_address;
}


x86 assembly (clang, -O0):
<init_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b1 <init_load+0x41>
lea    0xe61(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11fe <init_load+0x8e>
lea    0xe2e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x1000000,-0xc(%rbp)
jle    122a <init_load+0xba>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movslq -0xc(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_load>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11db <init_load+0x6b>
mov    %rax,%r14
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x20,%esi
call   1060 <fseek@plt>
lea    0x4(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11e4 <init_load+0x74>
movslq 0x4(%rsp),%rbx
cmp    $0x1000001,%rbx
jge    11fa <init_load+0x8a>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe21(%rip),%rdi
jmp    11eb <init_load+0x7b>
lea    0xe32(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"unable to open input file\00"
@SEEK_SET = global i32 0
@.str.2 = [33 x i8] c"unable to read input file header\00"
@.str.3 = [20 x i8] c"end_address invalid\00"
@stderr = global i32 0
define i64 @init_load(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseek(i32* %13, i32 32, i32 %14)
%16 = load i32*, i32** %4
%17 = call i32 @fread(i32* %3, i32 8, i32 1, i32* %16)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %12
%23 = load i32, i32* %3
%24 = icmp sgt i32 %23, 16777216
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
ret i64 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"unable to open input file\00"
@SEEK_SET = global i32 0
@.str.2 = [33 x i8] c"unable to read input file header\00"
@.str.3 = [20 x i8] c"end_address invalid\00"
@stderr = global i32 0
define i64 @init_load(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %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 %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %4, i32 32, i32 %10)
%12 = call i32 @fread(i32* %2, i32 8, i32 1, i32* %4)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = load i32, i32* %2
%19 = icmp sgt i32 %18, 16777216
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = tail call i32 @fclose(i32* %4)
%26 = sext i32 %18 to i64
ret i64 %26
}