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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ pgr_abort(int);
int strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int vasprintf(char **, char const *, int /*<<< orphan*/);
void _vlogf(FILE *io, const char *fmt, va_list ap) {
  char *msg, tstamp[128];
  int n;
  struct tm t;
  time_t now = time(NULL);
  if (gmtime_r(&now, &t) == NULL) {
    pgr_abort(1);
  }
  n = strftime(tstamp, sizeof(tstamp), "%c", &t);
  if (n < 0) {
    pgr_abort(1);
  }
  n = vasprintf(&msg, fmt, ap);
  if (n < 0) {
    pgr_abort(2);
  }
  fprintf(io, "[%s] %s\n", tstamp, msg);
  free(msg);
}


x86 assembly (clang, -O0):
<_vlogf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0xac(%rbp)
lea    -0xac(%rbp),%rdi
lea    -0xa8(%rbp),%rsi
call   1060 <gmtime_r@plt>
cmp    $0x0,%rax
jne    11bc <_vlogf+0x4c>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x80,%esi
lea    0xe31(%rip),%rdx
lea    -0xa8(%rbp),%rcx
call   1090 <strftime@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jge    11f8 <_vlogf+0x88>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1050 <vasprintf@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jge    1225 <_vlogf+0xb5>
mov    $0x2,%edi
call   1040 <pgr_abort@plt>
mov    -0x8(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdc8(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_vlogf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1060 <gmtime_r@plt>
test   %rax,%rax
jne    11aa <_vlogf+0x3a>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
lea    0xe4f(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x80,%esi
call   1090 <strftime@plt>
test   %eax,%eax
jns    11d1 <_vlogf+0x61>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <vasprintf@plt>
test   %eax,%eax
jns    11ee <_vlogf+0x7e>
mov    $0x2,%edi
call   1040 <pgr_abort@plt>
mov    0x8(%rsp),%rcx
lea    0xe09(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1070 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%c\00"
@.str.1 = [9 x i8] c"[%s] %s\0A\00"
define void @_vlogf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca %struct.tm
%11 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = call i32 @time(i32* null)
store i32 %12, i32* %11
%13 = call i32* @gmtime_r(i32* %11, %struct.tm* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @pgr_abort(i32 1)
br label %17
17: ; preds = %15, %3
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%19 = call i32 @strftime(i8* %18, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @pgr_abort(i32 1)
br label %24
24: ; preds = %22, %17
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = call i32 @vasprintf(i8** %7, i8* %25, i32 %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @pgr_abort(i32 2)
br label %32
32: ; preds = %30, %24
%33 = load i32*, i32** %4
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%35 = load i8*, i8** %7
%36 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %35)
%37 = load i8*, i8** %7
%38 = call i32 @free(i8* %37)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%c\00"
@.str.1 = [9 x i8] c"[%s] %s\0A\00"
define void @_vlogf(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca %struct.tm
%7 = alloca i32
%8 = bitcast i8** %4 to i8*
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%10 = bitcast %struct.tm* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = tail call i32 @time(i32* null)
store i32 %12, i32* %7
%13 = call i32* @gmtime_r(i32* %7, %struct.tm* %6)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @pgr_abort(i32 1)
br label %17
17: ; preds = %15, %3
%18 = call i32 @strftime(i8* %9, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @pgr_abort(i32 1)
br label %22
22: ; preds = %20, %17
%23 = call i32 @vasprintf(i8** %4, i8* %1, i32 %2)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @pgr_abort(i32 2)
br label %27
27: ; preds = %25, %22
%28 = load i8*, i8** %4
%29 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %28)
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
ret void
}