#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 timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int LOG_WARNING;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/ *, char const *,
                            int /*<<< orphan*/);
void mbox_log_console(int p, const char *fmt, va_list args) {
  struct timespec time;
  FILE *s = (p < LOG_WARNING) ? stdout : stderr;
  clock_gettime(CLOCK_REALTIME, &time);
  fprintf(s, "[%s %ld.%.9ld] ", "", time.tv_sec, time.tv_nsec);
  vfprintf(s, fmt, args);
}


x86 assembly (clang, -O0):
<mbox_log_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e9c(%rip),%rcx
cmp    (%rcx),%eax
jge    1167 <mbox_log_console+0x37>
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1175 <mbox_log_console+0x45>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe5f(%rip),%rsi
lea    0xe67(%rip),%rdx
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <vfprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbox_log_console>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    0x2ea3(%rip),%rax
cmp    %edi,(%rax)
jle    1152 <mbox_log_console+0x22>
mov    0x2e80(%rip),%rax
jmp    1159 <mbox_log_console+0x29>
mov    0x2e7f(%rip),%rax
mov    (%rax),%rbp
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%ecx
lea    0xe81(%rip),%rsi
lea    0xe89(%rip),%rdx
mov    %rbp,%rdi
call   1040 <fprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <vfprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@LOG_WARNING = global i32 0
@stdout = global i32* null
@stderr = global i32* null
@CLOCK_REALTIME = global i32 0
@.str = [16 x i8] c"[%s %ld.%.9ld] \00"
@.str.1 = [1 x i8] zeroinitializer
define void @mbox_log_console(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.timespec
%8 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = load i32, i32* @LOG_WARNING
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32*, i32** @stdout
br label %16
14: ; preds = %3
%15 = load i32*, i32** @stderr
br label %16
16: ; preds = %14, %12
%17 = phi i32* [ %13, %12 ], [ %15, %14 ]
store i32* %17, i32** %8
%18 = load i32, i32* @CLOCK_REALTIME
%19 = call i32 @clock_gettime(i32 %18, %struct.timespec* %7)
%20 = load i32*, i32** %8
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %24)
%26 = load i32*, i32** %8
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = call i32 @vfprintf(i32* %26, i8* %27, i32 %28)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@LOG_WARNING = global i32 0
@stdout = global i32* null
@stderr = global i32* null
@CLOCK_REALTIME = global i32 0
@.str = [16 x i8] c"[%s %ld.%.9ld] \00"
@.str.1 = [1 x i8] zeroinitializer
define void @mbox_log_console(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = load i32, i32* @LOG_WARNING
%7 = icmp sgt i32 %6, %0
%8 = load i32*, i32** @stdout
%9 = load i32*, i32** @stderr
%10 = select i1 %7, i32* %8, i32* %9
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %4)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %16)
%18 = call i32 @vfprintf(i32* %10, i8* %1, i32 %2)
ret void
}