#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;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int, int, int, int, int,
                            int);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vsnprintf(char *, size_t, char const *, int /*<<< orphan*/);
void ant_log_core(char *str, size_t n, const char *fmt, va_list ap) {
  time_t t;
  struct tm tmval;
  int len;
  t = time(NULL);
  tmval = *localtime(&t);
  snprintf(str, n, "%d-%02d-%02d %02d:%02d:%02d ", 1900 + tmval.tm_year,
           tmval.tm_mon + 1, tmval.tm_mday, tmval.tm_hour, tmval.tm_min,
           tmval.tm_sec);
  len = strlen(str);
  vsnprintf(str + len, n - len, fmt, ap);
}


x86 assembly (clang, -O0):
<ant_log_core>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x38(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x30(%rbp)
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x34(%rbp),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%r9d
mov    -0x2c(%rbp),%r11d
mov    -0x28(%rbp),%r10d
mov    -0x24(%rbp),%eax
lea    0xe3e(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x3c(%rbp),%rax
sub    %rax,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <vsnprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ant_log_core>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%r11d
mov    0x14(%rax),%r12d
mov    $0x76c,%ecx
add    (%rax),%ecx
add    $0x1,%r8d
sub    $0x8,%rsp
lea    0xe59(%rip),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
push   %r12
push   %r11
push   %r10
call   1060 <snprintf@plt>
add    $0x20,%rsp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
sub    %rax,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <vsnprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [29 x i8] c"%d-%02d-%02d %02d:%02d:%02d \00"
define void @ant_log_core(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.tm
%11 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = call i32 @time(i32* null)
store i32 %12, i32* %9
%13 = call %struct.tm* @localtime(i32* %9)
%14 = bitcast %struct.tm* %10 to i8*
%15 = bitcast %struct.tm* %13 to i8*
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%19 = load i32, i32* %18
%20 = add nsw i32 1900, %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 1
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
%24 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 2
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 4
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 5
%31 = load i32, i32* %30
%32 = call i32 @snprintf(i8* %16, i64 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31)
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %11
%35 = load i8*, i8** %5
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i64, i64* %6
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = sub i64 %39, %41
%43 = load i8*, i8** %7
%44 = load i32, i32* %8
%45 = call i32 @vsnprintf(i8* %38, i64 %42, i8* %43, i32 %44)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [29 x i8] c"%d-%02d-%02d %02d:%02d:%02d \00"
define void @ant_log_core(i8* %0, i64 %1, i8* nocapture %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 @time(i32* null)
store i32 %7, i32* %5
%8 = call %struct.tm* @localtime(i32* %5)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 3
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 4
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 5
%20 = load i32, i32* %19
%21 = add nsw i32 %10, 1900
%22 = add nsw i32 %12, 1
%23 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22, i32 %14, i32 %16, i32 %18, i32 %20)
%24 = call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = sub i64 %1, %25
%28 = call i32 @vsnprintf(i8* %26, i64 %27, i8* %2, i32 %3)
ret void
}