#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 tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void logfile(char *str) {
  FILE *fp = fopen("TSSplitter.log", "a+");
  if (fp != NULL) {
    time_t ct;
    struct tm *ltm;
    time(&ct);
    ltm = localtime(&ct);
    fprintf(fp, "%02d/%02d %02d:%02d:%02d ", ltm->tm_mon + 1, ltm->tm_mday,
            ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
    fprintf(fp, "%s", str);
    fflush(fp);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<logfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1208 <logfile+0xa8>
lea    -0x14(%rbp),%rdi
call   1060 <time@plt>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
lea    0xe3c(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xe7d(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11ee <logfile+0x7e>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1070 <time@plt>
mov    %r15,%rdi
call   1030 <localtime@plt>
mov    (%rax),%edx
mov    0x4(%rax),%ecx
add    $0x1,%edx
mov    0x8(%rax),%r8d
mov    0xc(%rax),%r9d
mov    0x10(%rax),%eax
mov    %eax,(%rsp)
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"TSSplitter.log\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [26 x i8] c"%02d/%02d %02d:%02d:%02d \00"
@.str.3 = [3 x i8] c"%s\00"
define void @logfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.tm*
store i8* %0, i8** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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 %9, label %37
9: ; preds = %1
%10 = call i32 @time(i32* %4)
%11 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %11, %struct.tm** %5
%12 = load i32*, i32** %3
%13 = load %struct.tm*, %struct.tm** %5
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = load %struct.tm*, %struct.tm** %5
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load %struct.tm*, %struct.tm** %5
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = load %struct.tm*, %struct.tm** %5
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 3
%25 = load i32, i32* %24
%26 = load %struct.tm*, %struct.tm** %5
%27 = getelementptr inbounds %struct.tm, %struct.tm* %26, i32 0, i32 4
%28 = load i32, i32* %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %19, i32 %22, i32 %25, i32 %28)
%30 = load i32*, i32** %3
%31 = load i8*, i8** %2
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %3
%34 = call i32 @fflush(i32* %33)
%35 = load i32*, i32** %3
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %9, %1
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"TSSplitter.log\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [26 x i8] c"%02d/%02d %02d:%02d:%02d \00"
define void @logfile(i8* nocapture %0) {
%2 = alloca i32
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
%7 = call i32 @time(i32* %2)
%8 = call %struct.tm* @localtime(i32* %2)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
%12 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 4
%19 = load i32, i32* %18
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %13, i32 %15, i32 %17, i32 %19)
%21 = call i32 @fputs(i8* %0, i32* %3)
%22 = call i32 @fflush(i32* %3)
%23 = call i32 @fclose(i32* %3)
br label %24
24: ; preds = %5, %1
ret void
}