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

/* Variables and functions */
char *calloc(size_t, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, char const *,
                            char const *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void log_print(const char *tag, const char *message, va_list args) {
  time_t current_time;
  time(&current_time);
  struct tm current_time_buf;
  gmtime_r(&current_time, &current_time_buf);
  char current_time_str[256];
  strftime(current_time_str, 256, "%F %T", &current_time_buf);
  size_t message_meta_len = strlen(message) + 256 + strlen(tag) + 16;
  char *message_meta = calloc(message_meta_len, sizeof(char));
  snprintf(message_meta, message_meta_len, "[%s] [%s] %s\n", current_time_str,
           tag, message);
  vfprintf(stdout, message_meta, args);
  free(message_meta);
}


x86 assembly (clang, -O0):
<log_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
call   1080 <time@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <gmtime_r@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
lea    0xe41(%rip),%rdx
lea    -0x20(%rbp),%rcx
call   1090 <strftime@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x100,%eax
mov    %eax,-0x134(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x134(%rbp),%eax
add    %ecx,%eax
add    $0x10,%eax
cltq
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rdi
mov    -0x128(%rbp),%rsi
lea    -0x120(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    -0x10(%rbp),%r9
lea    0xdcf(%rip),%rdx
call   1050 <snprintf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x130(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10a0 <vfprintf@plt>
mov    -0x130(%rbp),%rdi
call   1030 <free@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %edx,0x4(%rsp)
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <time@plt>
lea    0x8(%rsp),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <gmtime_r@plt>
lea    0xe41(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r13,%rcx
call   1090 <strftime@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0x110,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbp
lea    0xdff(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
mov    %r14,%r8
mov    %r12,%r9
call   1050 <snprintf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    0x4(%rsp),%edx
call   10a0 <vfprintf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [14 x i8] c"[%s] [%s] %s\0A\00"
@stdout = global i32 0
define void @log_print(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.tm
%9 = alloca [256 x i8]
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = call i32 @time(i32* %7)
%13 = call i32 @gmtime_r(i32* %7, %struct.tm* %8)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%15 = call i32 @strftime(i8* %14, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 256
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 16
%23 = sext i32 %22 to i64
store i64 %23, i64* %10
%24 = load i64, i64* %10
%25 = call i8* @calloc(i64 %24, i32 1)
store i8* %25, i8** %11
%26 = load i8*, i8** %11
%27 = load i64, i64* %10
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i32 @snprintf(i8* %26, i64 %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29, i8* %30)
%32 = load i32, i32* @stdout
%33 = load i8*, i8** %11
%34 = load i32, i32* %6
%35 = call i32 @vfprintf(i32 %32, i8* %33, i32 %34)
%36 = load i8*, i8** %11
%37 = call i32 @free(i8* %36)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [14 x i8] c"[%s] [%s] %s\0A\00"
@stdout = global i32 0
define void @log_print(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
%6 = alloca [256 x i8]
%7 = bitcast i32* %4 to i8*
%8 = call i32 @time(i32* %4)
%9 = bitcast %struct.tm* %5 to i8*
%10 = call i32 @gmtime_r(i32* %4, %struct.tm* %5)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i32 @strftime(i8* %11, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %5)
%13 = call i32 @strlen(i8* %1)
%14 = call i32 @strlen(i8* %0)
%15 = add i32 %13, 272
%16 = add i32 %15, %14
%17 = sext i32 %16 to i64
%18 = call i8* @calloc(i64 %17, i32 1)
%19 = call i32 @snprintf(i8* %18, i64 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %0, i8* %1)
%20 = load i32, i32* @stdout
%21 = call i32 @vfprintf(i32 %20, i8* %18, i32 %2)
%22 = call i32 @free(i8* %18)
ret void
}