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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char const *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void WriteToLog(const char *msg) {
  time_t t;
  static struct tm *tm;
  static char s[100];
  time(&t);
  tm = localtime(&t);
  strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", tm);
  FILE *fp = fopen("/var/log/pitabd.log", "a");
  if (fp != NULL) {
    fprintf(fp, "%s %s\n", s, msg);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<WriteToLog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <time@plt>
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,0x2edb(%rip)
mov    0x2ed4(%rip),%rcx
lea    0x2edd(%rip),%rdi
mov    $0x64,%esi
lea    0xe61(%rip),%rdx
call   1070 <strftime@plt>
lea    0xe67(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ea <WriteToLog+0x8a>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    0xe53(%rip),%rsi
lea    0x2e94(%rip),%rdx
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteToLog>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,0x2edd(%rip)
lea    0x2ee6(%rip),%rdi
lea    0xe6f(%rip),%rdx
mov    $0x64,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
lea    0xe6d(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11da <WriteToLog+0x7a>
mov    %rax,%rbx
lea    0xe68(%rip),%rsi
lea    0x2ea9(%rip),%rdx
mov    %rax,%rdi
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@WriteToLog.tm = internal global %struct.tm* null
@WriteToLog.s = internal global [100 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [20 x i8] c"/var/log/pitabd.log\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [7 x i8] c"%s %s\0A\00"
define void @WriteToLog(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = call i32 @time(i32* %3)
%6 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %6, %struct.tm** @WriteToLog.tm
%7 = load %struct.tm*, %struct.tm** @WriteToLog.tm
%8 = call i32 @strftime(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @WriteToLog.s, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%9 = 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* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = load i8*, i8** %2
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @WriteToLog.s, i64 0, i64 0), i8* %14)
%16 = load i32*, i32** %4
%17 = call i32 @fclose(i32* %16)
br label %18
18: ; preds = %12, %1
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@WriteToLog.tm = internal unnamed_addr global %struct.tm* null
@WriteToLog.s = internal global [100 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [20 x i8] c"/var/log/pitabd.log\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [7 x i8] c"%s %s\0A\00"
define void @WriteToLog(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @time(i32* %2)
%5 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %5, %struct.tm** @WriteToLog.tm
%6 = call i32 @strftime(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @WriteToLog.s, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %5)
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @WriteToLog.s, i64 0, i64 0), i8* %0)
%11 = call i32 @fclose(i32* %7)
br label %12
12: ; preds = %9, %1
ret void
}