#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*/ buffer;

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ log_write(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void log_event(const char *msg) {
  time_t current_time = time(NULL);
  struct tm *ltime = localtime(&current_time);
  char timestamp[20];
  strftime(timestamp, 20, "[%m-%d-%y %H:%M:%S]", ltime);
  char buffer[128];
  snprintf(buffer, sizeof(buffer), "%s %s", timestamp, msg);
  log_write(buffer);
}


x86 assembly (clang, -O0):
<log_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x14,%esi
lea    0xe74(%rip),%rdx
call   1060 <strftime@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    $0x80,%esi
lea    0xe68(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xb0(%rbp),%rdi
call   1070 <log_write@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_event>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
mov    %rdi,%r14
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe85(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x14,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
lea    0xe7d(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <log_write@plt>
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [20 x i8] c"[%m-%d-%y %H:%M:%S]\00"
@.str.1 = [6 x i8] c"%s %s\00"
define void @log_event(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca [20 x i8]
%6 = alloca [128 x i8]
store i8* %0, i8** %2
%7 = call i32 @time(i32* null)
store i32 %7, i32* %3
%8 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %8, %struct.tm** %4
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%10 = load %struct.tm*, %struct.tm** %4
%11 = call i32 @strftime(i8* %9, i32 20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %2
%15 = call i32 @snprintf(i8* %12, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %14)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%17 = call i32 @log_write(i8* %16)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [20 x i8] c"[%m-%d-%y %H:%M:%S]\00"
@.str.1 = [6 x i8] c"%s %s\00"
define void @log_event(i8* %0) {
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = alloca [128 x i8]
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %2
%7 = call %struct.tm* @localtime(i32* %2)
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%9 = call i32 @strftime(i8* %8, i32 20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %0)
%12 = call i32 @log_write(i8* %10)
ret void
}