#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 EIO;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
int print_f(char *buf) {
  FILE *fp;
  fp = fopen("/tmp/wifilog", "r");
  if (fp == NULL) {
    return -EIO;
  }
  fclose(fp);
  fp = fopen("/tmp/wifilog", "a+");
  if (fp == NULL) {
    return -EIO;
  }
  fwrite(buf, 1, strlen(buf), fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<print_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1181 <print_f+0x41>
xor    %eax,%eax
mov    0x2e69(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <print_f+0xb4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe6f(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <print_f+0x7f>
xor    %eax,%eax
mov    0x2e2b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <print_f+0xb4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_f>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a8 <print_f+0x68>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xe92(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a8 <print_f+0x68>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11b3 <print_f+0x73>
mov    0x2e31(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/wifilog\00"
@.str.1 = [2 x i8] c"r\00"
@EIO = global i32 0
@.str.2 = [3 x i8] c"a+\00"
define i32 @print_f(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @EIO
%10 = sub nsw i32 0, %9
store i32 %10, i32* %2
br label %28
11: ; preds = %1
%12 = load i32*, i32** %4
%13 = call i32 @fclose(i32* %12)
%14 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %4
%15 = load i32*, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* @EIO
%19 = sub nsw i32 0, %18
store i32 %19, i32* %2
br label %28
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = load i8*, i8** %3
%23 = call i32 @strlen(i8* %22)
%24 = load i32*, i32** %4
%25 = call i32 @fwrite(i8* %21, i32 1, i32 %23, i32* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
store i32 0, i32* %2
br label %28
28: ; preds = %20, %17, %8
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/wifilog\00"
@.str.1 = [2 x i8] c"r\00"
@EIO = global i32 0
@.str.2 = [3 x i8] c"a+\00"
define i32 @print_f(i8* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @EIO
%6 = sub nsw i32 0, %5
br label %18
7: ; preds = %1
%8 = tail call i32 @fclose(i32* %2)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @EIO
%13 = sub nsw i32 0, %12
br label %18
14: ; preds = %7
%15 = tail call i32 @strlen(i8* %0)
%16 = tail call i32 @fwrite(i8* %0, i32 1, i32 %15, i32* %9)
%17 = tail call i32 @fclose(i32* %9)
br label %18
18: ; preds = %14, %11, %4
%19 = phi i32 [ %6, %4 ], [ %13, %11 ], [ 0, %14 ]
ret i32 %19
}