#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;

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vprintf(char const *, int /*<<< orphan*/);
void log_format(const char *tag, const char *message, va_list args) {
  time_t now;
  time(&now);
  char *date = ctime(&now);
  date[strlen(date) - 1] = '\0';
  printf("%s [%s] ", date, tag);
  vprintf(message, args);
  printf("\n");
}


x86 assembly (clang, -O0):
<log_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <time@plt>
lea    -0x18(%rbp),%rdi
call   1030 <ctime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <vprintf@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_format>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <time@plt>
mov    %rbx,%rdi
call   1040 <ctime@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1080 <vprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s [%s] \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @log_format(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = call i32 @time(i32* %7)
%10 = call i8* @ctime(i32* %7)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = load i8*, i8** %8
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
store i8 0, i8* %16
%17 = load i8*, i8** %8
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18)
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = call i32 @vprintf(i8* %20, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s [%s] \00"
define void @log_format(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @time(i32* %4)
%7 = call i8* @ctime(i32* %4)
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 0, i8* %11
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %0)
%13 = call i32 @vprintf(i8* %1, i32 %2)
%14 = call i32 @putchar(i32 10)
ret void
}