#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 *);
int /*<<< orphan*/ printf(char *, char *);
char *printLog(char *val) {
  FILE *myfile;
  char *fname = "/fb_freedom.log";
  myfile = fopen(fname, "a");
  if (!myfile) {
    printf("File %s not open\n", fname);
    val = "Erro";
  } else {
    fprintf(myfile, "\n");
    fprintf(myfile, val);
    fclose(myfile);
  }
  return (char *)val;
}


x86 assembly (clang, -O0):
<printLog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1196 <printLog+0x56>
mov    -0x18(%rbp),%rsi
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
lea    0xe97(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <printLog+0x7c>
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printLog>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1194 <printLog+0x44>
mov    %rax,%rbx
mov    $0xa,%edi
mov    %rax,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11ae <printLog+0x5e>
lea    0xe77(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <printf@plt>
lea    0xe76(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/fb_freedom.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [18 x i8] c"File %s not open\0A\00"
@.str.3 = [5 x i8] c"Erro\00"
@.str.4 = [2 x i8] c"\0A\00"
define i8* @printLog(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = load i8*, i8** %4
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %10)
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %20
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32*, i32** %3
%16 = load i8*, i8** %2
%17 = call i32 @fprintf(i32* %15, i8* %16)
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %12, %9
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@.str = [16 x i8] c"/fb_freedom.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [18 x i8] c"File %s not open\0A\00"
@.str.3 = [5 x i8] c"Erro\00"
define i8* @printLog(i8* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 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 %6
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
6: ; preds = %1
%7 = tail call i32 @fputc(i32 10, i32* %2)
%8 = tail call i32 @fprintf(i32* %2, i8* %0)
%9 = tail call i32 @fclose(i32* %2)
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ %0, %6 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %4 ]
ret i8* %11
}