#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ const *, size_t, int,
                          int /*<<< orphan*/ *);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ zlog_fini();
int zlog_init(char *);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  char filename[256];
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
  FILE *fp = fopen(filename, "wb");
  if (!fp)
    return 0;
  fwrite(data, size, 1, fp);
  fclose(fp);
  int rc = zlog_init(filename);
  if (rc == 0) {
    zlog_fini();
  }
  unlink(filename);
  return 0;
}


x86 assembly (clang, -O0):
<LLVMFuzzerTestOneInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%edx
lea    0xe48(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11f1 <LLVMFuzzerTestOneInput+0x71>
movl   $0x0,-0x4(%rbp)
jmp    124f <LLVMFuzzerTestOneInput+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x128(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    -0x128(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x120(%rbp),%rdi
call   1030 <zlog_init@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jne    123c <LLVMFuzzerTestOneInput+0xbc>
mov    $0x0,%al
call   1070 <zlog_fini@plt>
lea    -0x120(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LLVMFuzzerTestOneInput>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe60(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fa <LLVMFuzzerTestOneInput+0x7a>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %rsp,%rdi
call   1030 <zlog_init@plt>
test   %eax,%eax
jne    11f2 <LLVMFuzzerTestOneInput+0x72>
xor    %eax,%eax
call   1070 <zlog_fini@plt>
mov    %rsp,%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/tmp/libfuzzer.%d\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @LLVMFuzzerTestOneInput(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca [256 x i8]
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%10 = call i32 (...) @getpid()
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i32 0, i32* %3
br label %33
17: ; preds = %2
%18 = load i32*, i32** %4
%19 = load i64, i64* %5
%20 = load i32*, i32** %7
%21 = call i32 @fwrite(i32* %18, i64 %19, i32 1, i32* %20)
%22 = load i32*, i32** %7
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = call i32 @zlog_init(i8* %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = call i32 (...) @zlog_fini()
br label %30
30: ; preds = %28, %17
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%32 = call i32 @unlink(i8* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %16
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [18 x i8] c"/tmp/libfuzzer.%d\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @LLVMFuzzerTestOneInput(i32* nocapture %0, i64 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @getpid()
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = tail call i32 @fwrite(i32* %0, i64 %1, i32 1, i32* %7)
%11 = tail call i32 @fclose(i32* %7)
%12 = call i32 @zlog_init(i8* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 (...) @zlog_fini()
br label %16
16: ; preds = %14, %9
%17 = call i32 @unlink(i8* %4)
br label %18
18: ; preds = %2, %16
ret i32 0
}