#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 const *,
                           int, char const *, 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 _vdlogf(FILE *io, const char *file, int line, const char *fn,
             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] DEBUG %s:%d %s() - %s\n", tstamp, file, line, fn, msg);
  free(msg);
}


x86 assembly (clang, -O0):
<_vdlogf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0xcc(%rbp)
lea    -0xcc(%rbp),%rdi
lea    -0xc8(%rbp),%rsi
call   1060 <gmtime_r@plt>
cmp    $0x0,%rax
jne    11c8 <_vdlogf+0x58>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x80,%esi
lea    0xe25(%rip),%rdx
lea    -0xc8(%rbp),%rcx
call   1090 <strftime@plt>
mov    %eax,-0xc4(%rbp)
cmpl   $0x0,-0xc4(%rbp)
jge    1204 <_vdlogf+0x94>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0x38(%rbp),%rdi
call   1050 <vasprintf@plt>
mov    %eax,-0xc4(%rbp)
cmpl   $0x0,-0xc4(%rbp)
jge    1231 <_vdlogf+0xc1>
mov    $0x2,%edi
call   1040 <pgr_abort@plt>
mov    -0x8(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    0xdb0(%rip),%rsi
mov    %rax,(%rsp)
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_vdlogf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9d,%ebx
mov    %r8,%rbp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r13
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0x14(%rsp)
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <gmtime_r@plt>
test   %rax,%rax
jne    11bc <_vdlogf+0x4c>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
lea    0xe3d(%rip),%rdx
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x80,%esi
call   1090 <strftime@plt>
test   %eax,%eax
jns    11e5 <_vdlogf+0x75>
mov    $0x1,%edi
call   1040 <pgr_abort@plt>
lea    0x18(%rsp),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <vasprintf@plt>
test   %eax,%eax
jns    1202 <_vdlogf+0x92>
mov    $0x2,%edi
call   1040 <pgr_abort@plt>
mov    0x18(%rsp),%rax
mov    %rax,(%rsp)
lea    0xdf1(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %r13,%rdi
mov    %r12,%rcx
mov    %r15d,%r8d
mov    %r14,%r9
call   1070 <fprintf@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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