#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 /*<<< orphan*/ tm_mday;
  scalar_t__ tm_mon;
  scalar_t__ tm_year;
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_min;
  int /*<<< orphan*/ tm_hour;
};

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, char *, int, char *, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int getpid();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vasprintf(char **, char *, int /*<<< orphan*/);
void x_vaprintf(char *format, va_list ap) {
  int pid;
  time_t timet;
  struct tm *tms;
  char *time_str;
  char *ap_str;
  char *print_str;
  pid = getpid();
  timet = time(NULL);
  tms = localtime(&timet);
  asprintf(&time_str, "%.2i:%.2i:%.2i %.2i%.2i%.2i ", tms->tm_hour, tms->tm_min,
           tms->tm_sec, tms->tm_year - 100, tms->tm_mon + 1, tms->tm_mday);
  vasprintf(&ap_str, format, ap);
  asprintf(&print_str, "%s [%i] - %s", time_str, getpid(), ap_str);
  free(time_str);
  free(ap_str);
  fprintf(stdout, "%s\n", print_str);
  free(print_str);
}


x86 assembly (clang, -O0):
<x_vaprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq 0x20(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x1c(%rax),%ecx
mov    -0x20(%rbp),%rax
movslq 0x18(%rax),%r8
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r9
sub    $0x64,%r9
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r10
add    $0x1,%r10
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rdi
lea    0xe1e(%rip),%rsi
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1090 <asprintf@plt>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x30(%rbp),%rdi
call   1060 <vasprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
mov    -0x30(%rbp),%r8
lea    -0x38(%rbp),%rdi
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1090 <asprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x_vaprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <getpid@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
movslq 0x20(%rax),%rdx
mov    0x1c(%rax),%ecx
movslq 0x18(%rax),%r8
mov    0x10(%rax),%r9
add    $0xffffffffffffff9c,%r9
mov    0x8(%rax),%rbp
add    $0x1,%rbp
mov    (%rax),%ebx
lea    0xe40(%rip),%rsi
lea    0x20(%rsp),%rdi
xor    %eax,%eax
push   %rbx
push   %rbp
call   1090 <asprintf@plt>
add    $0x10,%rsp
lea    0x18(%rsp),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1060 <vasprintf@plt>
mov    0x20(%rsp),%rbx
xor    %eax,%eax
call   1050 <getpid@plt>
mov    0x18(%rsp),%r8
lea    0xe23(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <asprintf@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xdf6(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i64, i64, i32, i32, i32 }
@.str = [29 x i8] c"%.2i:%.2i:%.2i %.2i%.2i%.2i \00"
@.str.1 = [13 x i8] c"%s [%i] - %s\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define void @x_vaprintf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = call i32 (...) @getpid()
store i32 %11, i32* %5
%12 = call i32 @time(i32* null)
store i32 %12, i32* %6
%13 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %13, %struct.tm** %7
%14 = load %struct.tm*, %struct.tm** %7
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 5
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = load %struct.tm*, %struct.tm** %7
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 4
%21 = load i32, i32* %20
%22 = load %struct.tm*, %struct.tm** %7
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 3
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
%27 = load %struct.tm*, %struct.tm** %7
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 2
%29 = load i64, i64* %28
%30 = sub nsw i64 %29, 100
%31 = load %struct.tm*, %struct.tm** %7
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 1
%33 = load i64, i64* %32
%34 = add nsw i64 %33, 1
%35 = load %struct.tm*, %struct.tm** %7
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 (i8**, i8*, i8*, i32, i8*, ...) @asprintf(i8** %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %21, i8* %26, i64 %30, i64 %34, i32 %37)
%39 = load i8*, i8** %3
%40 = load i32, i32* %4
%41 = call i32 @vasprintf(i8** %9, i8* %39, i32 %40)
%42 = load i8*, i8** %8
%43 = call i32 (...) @getpid()
%44 = load i8*, i8** %9
%45 = call i32 (i8**, i8*, i8*, i32, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %42, i32 %43, i8* %44)
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %9
%49 = call i32 @free(i8* %48)
%50 = load i32, i32* @stdout
%51 = load i8*, i8** %10
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %10
%54 = call i32 @free(i8* %53)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i64, i64, i32, i32, i32 }
@.str = [29 x i8] c"%.2i:%.2i:%.2i %.2i%.2i%.2i \00"
@.str.1 = [13 x i8] c"%s [%i] - %s\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define void @x_vaprintf(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = bitcast i8** %6 to i8*
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 @time(i32* null)
store i32 %12, i32* %3
%13 = call %struct.tm* @localtime(i32* %3)
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 5
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 3
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 2
%25 = load i64, i64* %24
%26 = add nsw i64 %25, -100
%27 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 1
%28 = load i64, i64* %27
%29 = add nsw i64 %28, 1
%30 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 (i8**, i8*, i8*, i32, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %19, i8* %23, i64 %26, i64 %29, i32 %31)
%33 = call i32 @vasprintf(i8** %5, i8* %0, i32 %1)
%34 = load i8*, i8** %4
%35 = call i32 (...) @getpid()
%36 = load i8*, i8** %5
%37 = call i32 (i8**, i8*, i8*, i32, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %34, i32 %35, i8* %36)
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* @stdout
%43 = load i8*, i8** %6
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = load i8*, i8** %6
%46 = call i32 @free(i8* %45)
ret void
}