#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ printf(char *, ...);
void logToFile(const char *str) {
  printf("%s\n", str);
  FILE *fp;
  fp = fopen("/www/stats/wifi.txt", "a");
  if (fp == NULL) {
    printf("I couldn't open logfile for writing.\n");
    return;
  }
  fprintf(fp, "%s \n", str);
  fclose(fp);
}


x86 assembly (clang, -O0):
<logToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <logToFile+0x53>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b0 <logToFile+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe9e(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logToFile>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <puts@plt>
lea    0xead(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1188 <logToFile+0x48>
mov    %rax,%rbx
lea    0xea8(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>
lea    0xe8c(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [20 x i8] c"/www/stats/wifi.txt\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [38 x i8] c"I couldn't open logfile for writing.\0A\00"
@.str.4 = [5 x i8] c"%s \0A\00"
define void @logToFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %17
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = load i8*, i8** %2
%14 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %3
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %11, %9
ret void
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"/www/stats/wifi.txt\00"
@.str.2 = [2 x i8] c"a\00"
@.str.4 = [5 x i8] c"%s \0A\00"
@str = [37 x i8] c"I couldn't open logfile for writing.\00"
define void @logToFile(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) %0)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %10
7: ; preds = %1
%8 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %7, %5
ret void
}