#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 fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int log_file(char *log_string) {
  FILE *fp;
  if (NULL == (fp = fopen("/home/pi/Web_Log_Files/pid3.txt", "a"))) {
    printf("Error printing to text log file\n");
    return 1;
  }
  char print_log_str[1024];
  sprintf(print_log_str, "%s", log_string);
  fprintf(fp, print_log_str);
  if (!0 == fclose(fp)) {
    printf("Error closing text log file\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<log_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    119c <log_file+0x4c>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fa <log_file+0xaa>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe95(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    11f3 <log_file+0xa3>
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fa <log_file+0xaa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
lea    0xe9a(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ad <log_file+0x5d>
mov    %rax,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    11be <log_file+0x6e>
lea    0xe77(%rip),%rdi
jmp    11b4 <log_file+0x64>
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"/home/pi/Web_Log_Files/pid3.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [33 x i8] c"Error printing to text log file\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [29 x i8] c"Error closing text log file\0A\00"
define i32 @log_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
store i8* %0, i8** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp eq i32* null, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %23
10: ; preds = %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %4
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = call i32 @fprintf(i32* %14, i8* %15)
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
%19 = icmp eq i32 1, %18
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %23
22: ; preds = %10
store i32 0, i32* %2
br label %23
23: ; preds = %22, %20, %8
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [32 x i8] c"/home/pi/Web_Log_Files/pid3.txt\00"
@.str.1 = [2 x i8] c"a\00"
@str = [28 x i8] c"Error closing text log file\00"
@str.5 = [32 x i8] c"Error printing to text log file\00"
define i32 @log_file(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, 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 ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
br label %17
7: ; preds = %1
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = call i8* @strcpy(i8* %8, i8* dereferenceable(1) %0)
%10 = call i32 @fprintf(i32* %3, i8* %8)
%11 = call i32 @fclose(i32* %3)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %7, %13
%16 = phi i32 [ 1, %13 ], [ 0, %7 ]
br label %17
17: ; preds = %15, %5
%18 = phi i32 [ 1, %5 ], [ %16, %15 ]
ret i32 %18
}