#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*/ date;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/);
void log_to_file(char *line, FILE *logfile) {
  char date[50];
  struct tm *current_time;
  time_t now = time(0);
  current_time = gmtime(&now);
  strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", current_time);
  fprintf(logfile, "[%s] %s\n", date, line);
  fflush(logfile);
}


x86 assembly (clang, -O0):
<log_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,-0x5c(%rbp)
lea    -0x5c(%rbp),%rdi
call   1070 <gmtime@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rcx
mov    $0x32,%esi
lea    0xe75(%rip),%rdx
call   1060 <strftime@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe6f(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fflush@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_to_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1070 <gmtime@plt>
lea    0xe85(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x32,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fflush@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [9 x i8] c"[%s] %s\0A\00"
define void @log_to_file(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [50 x i8]
%6 = alloca %struct.tm*
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = call i32 @time(i32 0)
store i32 %8, i32* %7
%9 = call %struct.tm* @gmtime(i32* %7)
store %struct.tm* %9, %struct.tm** %6
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%11 = load %struct.tm*, %struct.tm** %6
%12 = call i32 @strftime(i8* %10, i32 50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %11)
%13 = load i32*, i32** %4
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15)
%17 = load i32*, i32** %4
%18 = call i32 @fflush(i32* %17)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [9 x i8] c"[%s] %s\0A\00"
define void @log_to_file(i8* %0, i32* nocapture %1) {
%3 = alloca [50 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @time(i32 0)
store i32 %7, i32* %4
%8 = call %struct.tm* @gmtime(i32* %4)
%9 = call i32 @strftime(i8* %5, i32 50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%10 = call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %0)
%11 = call i32 @fflush(i32* %1)
ret void
}