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

/* Variables and functions */
int /*<<< orphan*/ LLVMFuzzerTestOneInput(int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *f;
  char *buf = NULL;
  long siz_buf;
  if (argc < 2) {
    fprintf(stderr, "no input file\n");
    goto err;
  }
  f = fopen(argv[1], "rb");
  if (f == NULL) {
    fprintf(stderr, "error opening input file %s\n", argv[1]);
    goto err;
  }
  fseek(f, 0, SEEK_END);
  siz_buf = ftell(f);
  rewind(f);
  if (siz_buf < 1)
    goto err;
  buf = (char *)malloc((size_t)siz_buf);
  if (buf == NULL) {
    fprintf(stderr, "malloc() failed\n");
    goto err;
  }
  if (fread(buf, (size_t)siz_buf, 1, f) != 1) {
    fprintf(stderr, "fread() failed\n");
    goto err;
  }
  (void)LLVMFuzzerTestOneInput((uint8_t *)buf, (size_t)siz_buf);
err:
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d4 <main+0x44>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12d1 <main+0x141>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121b <main+0x8b>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12d1 <main+0x141>
mov    -0x18(%rbp),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
cmpq   $0x1,-0x28(%rbp)
jge    1255 <main+0xc5>
jmp    12d1 <main+0x141>
mov    -0x28(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1289 <main+0xf9>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12d1 <main+0x141>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     12c4 <main+0x134>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12d1 <main+0x141>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <LLVMFuzzerTestOneInput@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11bc <main+0x2c>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1258 <main+0xc8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe45(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     123a <main+0xaa>
mov    %rax,%r12
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r12,%rdi
call   1080 <ftell@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <rewind@plt>
test   %r15,%r15
jle    1258 <main+0xc8>
mov    %r15,%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     126e <main+0xde>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1283 <main+0xf3>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <LLVMFuzzerTestOneInput@plt>
jmp    1258 <main+0xc8>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdc4(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
jmp    11ad <main+0x1d>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
jmp    11b0 <main+0x20>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"no input file\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"error opening input file %s\0A\00"
@SEEK_END = global i32 0
@.str.3 = [17 x i8] c"malloc() failed\0A\00"
@.str.4 = [16 x i8] c"fread() failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %61
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %61
27: ; preds = %14
%28 = load i32*, i32** %6
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i32*, i32** %6
%32 = call i64 @ftell(i32* %31)
store i64 %32, i64* %8
%33 = load i32*, i32** %6
%34 = call i32 @rewind(i32* %33)
%35 = load i64, i64* %8
%36 = icmp slt i64 %35, 1
br i1 %36, label %37, label %38
37: ; preds = %27
br label %61
38: ; preds = %27
%39 = load i64, i64* %8
%40 = call i64 @malloc(i64 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %61
47: ; preds = %38
%48 = load i8*, i8** %7
%49 = load i64, i64* %8
%50 = load i32*, i32** %6
%51 = call i32 @fread(i8* %48, i64 %49, i32 1, i32* %50)
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %61
56: ; preds = %47
%57 = load i8*, i8** %7
%58 = bitcast i8* %57 to i32*
%59 = load i64, i64* %8
%60 = call i32 @LLVMFuzzerTestOneInput(i32* %58, i64 %59)
br label %61
61: ; preds = %56, %53, %44, %37, %21, %11
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"no input file\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"error opening input file %s\0A\00"
@SEEK_END = global i32 0
@.str.3 = [17 x i8] c"malloc() failed\0A\00"
@.str.4 = [16 x i8] c"fread() failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %38
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %8
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %38
16: ; preds = %7
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %10, i32 0, i32 %17)
%19 = tail call i64 @ftell(i32* %10)
%20 = tail call i32 @rewind(i32* %10)
%21 = icmp slt i64 %19, 1
br i1 %21, label %38, label %22
22: ; preds = %16
%23 = tail call i64 @malloc(i64 %19)
%24 = inttoptr i64 %23 to i8*
%25 = icmp eq i64 %23, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %38
29: ; preds = %22
%30 = tail call i32 @fread(i8* %24, i64 %19, i32 1, i32* %10)
%31 = icmp eq i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %38
35: ; preds = %29
%36 = inttoptr i64 %23 to i32*
%37 = tail call i32 @LLVMFuzzerTestOneInput(i32* %36, i64 %19)
br label %38
38: ; preds = %16, %35, %32, %26, %12, %4
%39 = phi i8* [ null, %4 ], [ null, %12 ], [ null, %16 ], [ null, %26 ], [ %24, %32 ], [ %24, %35 ]
%40 = tail call i32 @free(i8* %39)
ret i32 0
}