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

/* Variables and functions */
int /*<<< orphan*/ FuzzerTestOneInput(unsigned char *, size_t);
int /*<<< orphan*/ OPENSSL_assert(int);
int S_IFREG;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(unsigned char *, int, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stdout;
void testfile(const char *pathname) {
  struct stat st;
  FILE *f;
  unsigned char *buf;
  size_t s;
  if (stat(pathname, &st) < 0 || !((st.st_mode) & S_IFREG))
    return;
  printf("# %s\n", pathname);
  fflush(stdout);
  f = fopen(pathname, "rb");
  if (f == NULL)
    return;
  buf = malloc(st.st_size);
  if (buf != NULL) {
    s = fread(buf, 1, st.st_size, f);
    OPENSSL_assert(s == (size_t)st.st_size);
    FuzzerTestOneInput(buf, s);
    free(buf);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<testfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jl     11d8 <testfile+0x38>
mov    -0x18(%rbp),%eax
mov    0x2e1b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11dd <testfile+0x3d>
jmp    1285 <testfile+0xe5>
mov    -0x8(%rbp),%rsi
lea    0xe18(%rip),%rdi
call   1070 <printf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    -0x8(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121f <testfile+0x7f>
jmp    1285 <testfile+0xe5>
mov    -0x10(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     127c <testfile+0xdc>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <OPENSSL_assert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10c0 <FuzzerTestOneInput@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1080 <stat@plt>
test   %rax,%rax
js     1259 <testfile+0xb9>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rsp)
je     1259 <testfile+0xb9>
lea    0xe2a(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
lea    0xe13(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1259 <testfile+0xb9>
mov    %rax,%r14
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     1251 <testfile+0xb1>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    %rax,%r15
xor    %edi,%edi
cmp    0x8(%rsp),%rax
sete   %dil
call   1040 <OPENSSL_assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <FuzzerTestOneInput@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@S_IFREG = global i32 0
@.str = [6 x i8] c"# %s\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"rb\00"
define void @testfile(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @stat(i8* %7, %struct.stat* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFREG
%14 = and i32 %12, %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %10, %1
br label %53
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @stdout
%21 = call i32 @fflush(i32 %20)
%22 = load i8*, i8** %2
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %4
%24 = load i32*, i32** %4
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %17
br label %53
27: ; preds = %17
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%29 = load i64, i64* %28
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %50
33: ; preds = %27
%34 = load i8*, i8** %5
%35 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%36 = load i64, i64* %35
%37 = load i32*, i32** %4
%38 = call i64 @fread(i8* %34, i32 1, i64 %36, i32* %37)
store i64 %38, i64* %6
%39 = load i64, i64* %6
%40 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%41 = load i64, i64* %40
%42 = icmp eq i64 %39, %41
%43 = zext i1 %42 to i32
%44 = call i32 @OPENSSL_assert(i32 %43)
%45 = load i8*, i8** %5
%46 = load i64, i64* %6
%47 = call i32 @FuzzerTestOneInput(i8* %45, i64 %46)
%48 = load i8*, i8** %5
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %33, %27
%51 = load i32*, i32** %4
%52 = call i32 @fclose(i32* %51)
br label %53
53: ; preds = %50, %26, %16
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@S_IFREG = global i32 0
@.str = [6 x i8] c"# %s\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"rb\00"
define void @testfile(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @S_IFREG
%10 = and i32 %9, %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %33, label %12
12: ; preds = %6
%13 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = load i32, i32* @stdout
%15 = call i32 @fflush(i32 %14)
%16 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %33, label %18
18: ; preds = %12
%19 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%20 = load i64, i64* %19
%21 = call i8* @malloc(i64 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %31, label %23
23: ; preds = %18
%24 = call i64 @fread(i8* %21, i32 1, i64 %20, i32* %16)
%25 = load i64, i64* %19
%26 = icmp eq i64 %24, %25
%27 = zext i1 %26 to i32
%28 = call i32 @OPENSSL_assert(i32 %27)
%29 = call i32 @FuzzerTestOneInput(i8* %21, i64 %24)
%30 = call i32 @free(i8* %21)
br label %31
31: ; preds = %23, %18
%32 = call i32 @fclose(i32* %16)
br label %33
33: ; preds = %12, %1, %6, %31
ret void
}