#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;
typedef int mask;
typedef int /*<<< orphan*/ date;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char const *,
                           ...);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ *log_fp(int);
char *log_priorityname(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void log_default_vprintf_with_timestamp(int mask, const char *fmt,
                                        va_list args) {
  char buf[640];
  int level = ((mask)&0xFF);
  char date[32];
  const char *extra_msg;
  time_t now;
  FILE *pf = log_fp(mask);
  memset(buf, 0, sizeof(buf));
  vsnprintf(buf, sizeof(buf) - 1, fmt, args);
  now = time(NULL);
  strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now));
  extra_msg = log_priorityname(level);
  if (extra_msg && strlen(extra_msg)) {
    fprintf(pf, "%s [%s] %s", date, extra_msg, buf);
  } else {
    fprintf(pf, "%s %s", date, buf);
  }
  fflush(pf);
}


x86 assembly (clang, -O0):
<log_default_vprintf_with_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x2a4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <log_fp@plt>
mov    %rax,-0x2e8(%rbp)
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x280,%edx
call   1070 <memset@plt>
lea    -0x2a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x27f,%esi
call   1040 <vsnprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x2dc(%rbp)
lea    -0x2d0(%rbp),%rax
mov    %rax,-0x2f0(%rbp)
lea    -0x2dc(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x2f0(%rbp),%rdi
mov    %eax,%ecx
mov    $0x20,%esi
lea    0xdc5(%rip),%rdx
call   10b0 <strftime@plt>
mov    -0x2a4(%rbp),%edi
call   10c0 <log_priorityname@plt>
mov    %rax,-0x2d8(%rbp)
cmpq   $0x0,-0x2d8(%rbp)
je     12a5 <log_default_vprintf_with_timestamp+0x105>
mov    -0x2d8(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
je     12a5 <log_default_vprintf_with_timestamp+0x105>
mov    -0x2e8(%rbp),%rdi
lea    -0x2d0(%rbp),%rdx
mov    -0x2d8(%rbp),%rcx
lea    -0x2a0(%rbp),%r8
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    12c8 <log_default_vprintf_with_timestamp+0x128>
mov    -0x2e8(%rbp),%rdi
lea    -0x2d0(%rbp),%rdx
lea    -0x2a0(%rbp),%rcx
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x2e8(%rbp),%rdi
call   10a0 <fflush@plt>
add    $0x2f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_default_vprintf_with_timestamp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2b0,%rsp
mov    %edx,%r12d
mov    %rsi,%rbp
movzbl %dil,%r15d
call   1050 <log_fp@plt>
mov    %rax,%r14
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x280,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x27f,%esi
mov    %rbp,%rdx
mov    %r12d,%ecx
call   1040 <vsnprintf@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe0c(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    %eax,%ecx
call   10a0 <strftime@plt>
mov    %r15d,%edi
call   10b0 <log_priorityname@plt>
test   %rax,%rax
je     1237 <log_default_vprintf_with_timestamp+0xa7>
cmpb   $0x0,(%rax)
je     1237 <log_default_vprintf_with_timestamp+0xa7>
lea    0xdf4(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x30(%rsp),%r8
mov    %r14,%rdi
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1252 <log_default_vprintf_with_timestamp+0xc2>
lea    0xddf(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x30(%rsp),%rcx
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1090 <fflush@plt>
add    $0x2b0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [11 x i8] c"%s [%s] %s\00"
@.str.2 = [6 x i8] c"%s %s\00"
define void @log_default_vprintf_with_timestamp(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [640 x i8]
%8 = alloca i32
%9 = alloca [32 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%13 = load i32, i32* %4
%14 = and i32 %13, 255
store i32 %14, i32* %8
%15 = load i32, i32* %4
%16 = call i32* @log_fp(i32 %15)
store i32* %16, i32** %12
%17 = getelementptr inbounds [640 x i8], [640 x i8]* %7, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 640)
%19 = getelementptr inbounds [640 x i8], [640 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = call i32 @vsnprintf(i8* %19, i32 639, i8* %20, i32 %21)
%23 = call i32 @time(i32* null)
store i32 %23, i32* %11
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%25 = call i32 @localtime(i32* %11)
%26 = call i32 @strftime(i8* %24, i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %8
%28 = call i8* @log_priorityname(i32 %27)
store i8* %28, i8** %10
%29 = load i8*, i8** %10
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %41
31: ; preds = %3
%32 = load i8*, i8** %10
%33 = call i64 @strlen(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = load i32*, i32** %12
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%38 = load i8*, i8** %10
%39 = getelementptr inbounds [640 x i8], [640 x i8]* %7, i64 0, i64 0
%40 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %38, i8* %39)
br label %46
41: ; preds = %31, %3
%42 = load i32*, i32** %12
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%44 = getelementptr inbounds [640 x i8], [640 x i8]* %7, i64 0, i64 0
%45 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %43, i8* %44)
br label %46
46: ; preds = %41, %35
%47 = load i32*, i32** %12
%48 = call i32 @fflush(i32* %47)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [11 x i8] c"%s [%s] %s\00"
@.str.2 = [6 x i8] c"%s %s\00"
define void @log_default_vprintf_with_timestamp(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca [640 x i8]
%5 = alloca [32 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [640 x i8], [640 x i8]* %4, i64 0, i64 0
%8 = and i32 %0, 255
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = tail call i32* @log_fp(i32 %0)
%12 = call i32 @memset(i8* %7, i32 0, i32 640)
%13 = call i32 @vsnprintf(i8* %7, i32 639, i8* %1, i32 %2)
%14 = call i32 @time(i32* null)
store i32 %14, i32* %6
%15 = call i32 @localtime(i32* %6)
%16 = call i32 @strftime(i8* %9, i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i8* @log_priorityname(i32 %8)
%18 = icmp eq i8* %17, null
br i1 %18, label %24, label %19
19: ; preds = %3
%20 = load i8, i8* %17
%21 = icmp eq i8 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %17, i8* %7)
br label %26
24: ; preds = %19, %3
%25 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %7)
br label %26
26: ; preds = %24, %22
%27 = call i32 @fflush(i32* %11)
ret void
}