#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*/ err_sys(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vprintf(char const *, int /*<<< orphan*/);
void vn_log_format(char *tag, const char *fmt, va_list ap) {
  time_t now;
  char *date;
  time(&now);
  if ((date = ctime(&now)) == NULL) {
    err_sys("[vn_log_format] ctime error");
  }
  date[strlen(date) - 1] = '\0';
  printf("%s [%s] ", date, tag);
  vprintf(fmt, ap);
  printf("\n");
}


x86 assembly (clang, -O0):
<vn_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   1070 <time@plt>
lea    -0x18(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119f <vn_log_format+0x3f>
lea    0xe66(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <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    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <vprintf@plt>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vn_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   1080 <time@plt>
mov    %rbx,%rdi
call   1050 <ctime@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a9 <vn_log_format+0x39>
lea    0xe5c(%rip),%rdi
call   1040 <err_sys@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1090 <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 = [28 x i8] c"[vn_log_format] ctime error\00"
@.str.1 = [9 x i8] c"%s [%s] \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @vn_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 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
%15 = load i8*, i8** %8
%16 = load i8*, i8** %8
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
store i8 0, i8* %20
%21 = load i8*, i8** %8
%22 = load i8*, i8** %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = call i32 @vprintf(i8* %24, i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"[vn_log_format] ctime error\00"
@.str.1 = [9 x i8] c"%s [%s] \00"
define void @vn_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 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = call i32 @strlen(i8* %7)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 0, i8* %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %0)
%17 = call i32 @vprintf(i8* %1, i32 %2)
%18 = call i32 @putchar(i32 10)
ret void
}