#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ LLVMFuzzerTestOneInput(unsigned char *, size_t);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Exactly one argument is expected.\n");
    exit(EXIT_FAILURE);
  }
  FILE *f = fopen(argv[1], "r");
  if (!f) {
    fprintf(stderr, "Failed to open input file.");
    exit(EXIT_FAILURE);
  }
  size_t max_len = 1 << 20;
  unsigned char *tmp = (unsigned char *)malloc(max_len);
  size_t len = fread(tmp, 1, max_len, f);
  if (ferror(f)) {
    fclose(f);
    fprintf(stderr, "Failed read input file.");
    exit(EXIT_FAILURE);
  }
  unsigned char *data = (unsigned char *)malloc(len);
  memcpy(data, tmp, len);
  free(tmp);
  LLVMFuzzerTestOneInput(data, len);
  free(data);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e3 <main+0x43>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe31(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1229 <main+0x89>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
movq   $0x100000,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1297 <main+0xf7>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1090 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <LLVMFuzzerTestOneInput@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11d4 <main+0x34>
mov    0x8(%rsi),%rdi
lea    0xe6e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    11e9 <main+0x49>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
jmp    1278 <main+0xd8>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
jmp    1278 <main+0xd8>
mov    %rax,%rbx
mov    $0x100000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    $0x100000,%edx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1260 <main+0xc0>
mov    %r15,%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <LLVMFuzzerTestOneInput@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Exactly one argument is expected.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Failed to open input file.\00"
@.str.3 = [24 x i8] c"Failed read input file.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %30, label %25
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %18
store i64 1048576, i64* %7
%31 = load i64, i64* %7
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = load i64, i64* %7
%36 = load i32*, i32** %6
%37 = call i64 @fread(i8* %34, i32 1, i64 %35, i32* %36)
store i64 %37, i64* %9
%38 = load i32*, i32** %6
%39 = call i64 @ferror(i32* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %30
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %30
%49 = load i64, i64* %9
%50 = call i64 @malloc(i64 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %10
%52 = load i8*, i8** %10
%53 = load i8*, i8** %8
%54 = load i64, i64* %9
%55 = call i32 @memcpy(i8* %52, i8* %53, i64 %54)
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %10
%59 = load i64, i64* %9
%60 = call i32 @LLVMFuzzerTestOneInput(i8* %58, i64 %59)
%61 = load i8*, i8** %10
%62 = call i32 @free(i8* %61)
%63 = load i32, i32* @EXIT_SUCCESS
%64 = call i32 @exit(i32 %63)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Exactly one argument is expected.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Failed to open input file.\00"
@.str.3 = [24 x i8] c"Failed read input file.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %9
%20 = tail call i64 @malloc(i64 1048576)
%21 = inttoptr i64 %20 to i8*
%22 = tail call i64 @fread(i8* %21, i32 1, i64 1048576, i32* %12)
%23 = tail call i64 @ferror(i32* %12)
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = tail call i32 @fclose(i32* %12)
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %19
%32 = tail call i64 @malloc(i64 %22)
%33 = inttoptr i64 %32 to i8*
%34 = tail call i32 @memcpy(i8* %33, i8* %21, i64 %22)
%35 = tail call i32 @free(i8* %21)
%36 = tail call i32 @LLVMFuzzerTestOneInput(i8* %33, i64 %22)
%37 = tail call i32 @free(i8* %33)
%38 = load i32, i32* @EXIT_SUCCESS
%39 = tail call i32 @exit(i32 %38)
unreachable
}