#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;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int, int,
                           int, int, unsigned int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/ *, char const *,
                            int /*<<< orphan*/);
int vfdebug(FILE *fp, const char *fmt, va_list args) {
  struct timeval rawtime;
  struct tm cooked;
  if (!fp || !fmt)
    return -1;
  gettimeofday(&rawtime, NULL);
  gmtime_r(&rawtime.tv_sec, &cooked);
  fprintf(fp, "[%u:%02u:%02u: %02u:%02u:%02u.%03u]: ", cooked.tm_year + 1900,
          cooked.tm_mon + 1, cooked.tm_mday, cooked.tm_hour, cooked.tm_min,
          cooked.tm_sec, (unsigned int)(rawtime.tv_usec / 1000));
  vfprintf(fp, fmt, args);
  fflush(fp);
  return 0;
}


x86 assembly (clang, -O0):
<vfdebug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1179 <vfdebug+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1185 <vfdebug+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <vfdebug+0xbf>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x28(%rbp),%rdi
add    $0x4,%rdi
lea    -0x40(%rbp),%rsi
call   1030 <gmtime_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x44(%rbp)
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x38(%rbp),%r8d
mov    -0x34(%rbp),%r9d
mov    -0x30(%rbp),%r11d
mov    -0x2c(%rbp),%r10d
mov    -0x28(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    -0x44(%rbp),%edx
lea    0xe23(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <vfprintf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfdebug>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1208 <vfdebug+0xb8>
mov    %rsi,%rbp
test   %rsi,%rsi
je     1208 <vfdebug+0xb8>
mov    %edx,%r15d
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gmtime_r@plt>
mov    $0x76c,%edx
add    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    0x18(%rsp),%r8d
add    $0x1,%ecx
mov    0x1c(%rsp),%r9d
mov    0x20(%rsp),%r10d
mov    0x24(%rsp),%r11d
movslq 0x8(%rsp),%rsi
imul   $0x10624dd3,%rsi,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rax
add    %esi,%eax
sub    $0x8,%rsp
lea    0xe1f(%rip),%rsi
mov    %rbx,%rdi
push   %rax
push   %r11
push   %r10
call   1050 <fprintf@plt>
add    $0x20,%rsp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1070 <vfprintf@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [38 x i8] c"[%u:%02u:%02u: %02u:%02u:%02u.%03u]: \00"
define i32 @vfdebug(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca %struct.tm
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12, %3
store i32 -1, i32* %4
br label %45
16: ; preds = %12
%17 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%19 = call i32 @gmtime_r(i32* %18, %struct.tm* %9)
%20 = load i32*, i32** %5
%21 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1900
%24 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
%27 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 2
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 4
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 5
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%36 = load i32, i32* %35
%37 = sdiv i32 %36, 1000
%38 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %26, i32 %28, i32 %30, i32 %32, i32 %34, i32 %37)
%39 = load i32*, i32** %5
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = call i32 @vfprintf(i32* %39, i8* %40, i32 %41)
%43 = load i32*, i32** %5
%44 = call i32 @fflush(i32* %43)
store i32 0, i32* %4
br label %45
45: ; preds = %16, %15
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [38 x i8] c"[%u:%02u:%02u: %02u:%02u:%02u.%03u]: \00"
define i32 @vfdebug(i32* %0, i8* %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.tm
%6 = bitcast %struct.timeval* %4 to i8*
%7 = bitcast %struct.tm* %5 to i8*
%8 = icmp ne i32* %0, null
%9 = icmp ne i8* %1, null
%10 = and i1 %8, %9
br i1 %10, label %11, label %35
11: ; preds = %3
%12 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%14 = call i32 @gmtime_r(i32* %13, %struct.tm* %5)
%15 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1900
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
%21 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%30 = load i32, i32* %29
%31 = sdiv i32 %30, 1000
%32 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %20, i32 %22, i32 %24, i32 %26, i32 %28, i32 %31)
%33 = call i32 @vfprintf(i32* %0, i8* %1, i32 %2)
%34 = call i32 @fflush(i32* %0)
br label %35
35: ; preds = %3, %11
%36 = phi i32 [ 0, %11 ], [ -1, %3 ]
ret i32 %36
}