#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*/ timestring;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void *logaroo(char *stringy) {
  FILE *fp;
  char timestring[256];
  time_t now;
  struct tm *timeinfo;
  time(&now);
  timeinfo = localtime(&now);
  strftime(timestring, sizeof(timestring), "%a %b %d %H:%M:%S", timeinfo);
  fp = fopen("logs/program_log", "a");
  if (fp == NULL) {
    perror("logs/program_log");
    fp = stderr;
  }
  if (fp)
    fprintf(fp, "%s: %s\n", timestring, stringy);
  if (0 || 0)
    fprintf(stderr, "LOG: %s\n", stringy);
  fclose(fp);
}


x86 assembly (clang, -O0):
<logaroo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x124(%rbp),%rdi
call   1060 <time@plt>
lea    -0x124(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x130(%rbp),%rcx
mov    $0x100,%esi
lea    0xe48(%rip),%rdx
call   1070 <strftime@plt>
lea    0xe4e(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f9 <logaroo+0x89>
lea    0xe2c(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1221 <logaroo+0xb1>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logaroo>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
lea    0xe67(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
lea    0xe60(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11f2 <logaroo+0x82>
lea    0xe58(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe19(%rip),%rdi
call   1090 <perror@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11c6 <logaroo+0x56>
xor    %ebx,%ebx
jmp    11df <logaroo+0x6f>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%a %b %d %H:%M:%S\00"
@.str.1 = [17 x i8] c"logs/program_log\00"
@.str.2 = [2 x i8] c"a\00"
@stderr = global i32* null
@.str.3 = [8 x i8] c"%s: %s\0A\00"
define i8* @logaroo(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca %struct.tm*
store i8* %0, i8** %3
%8 = call i32 @time(i32* %6)
%9 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %9, %struct.tm** %7
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = load %struct.tm*, %struct.tm** %7
%12 = call i32 @strftime(i8* %10, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %11)
%13 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32*, i32** @stderr
store i32* %18, i32** %4
br label %19
19: ; preds = %16, %1
%20 = load i32*, i32** %4
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32*, i32** %4
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* %25)
br label %27
27: ; preds = %22, %19
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%a %b %d %H:%M:%S\00"
@.str.1 = [17 x i8] c"logs/program_log\00"
@.str.2 = [2 x i8] c"a\00"
@stderr = global i32* null
@.str.3 = [8 x i8] c"%s: %s\0A\00"
define noalias i8* @logaroo(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i32 @time(i32* %3)
%7 = call %struct.tm* @localtime(i32* %3)
%8 = call i32 @strftime(i8* %4, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%9 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32*, i32** @stderr
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %1, %11
%16 = phi i32* [ %13, %11 ], [ %9, %1 ]
%17 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %0)
br label %18
18: ; preds = %15, %11
%19 = phi i32* [ %16, %15 ], [ null, %11 ]
%20 = call i32 @fclose(i32* %19)
ret i8* undef
}