#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 dummy;
};

/* Variables and functions */
int getpid();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vprintf(char const *, int /*<<< orphan*/);
void do_log(const char *level, const char *msgfmt, va_list ap) {
  char buf[1024];
  time_t t = time(NULL);
  struct tm *p = localtime(&t);
  strftime(buf, 1024, "%B %d %Y %H:%M:%S", p);
  printf("[%s][PID %d][%s] ", level, getpid(), buf);
  vprintf(msgfmt, ap);
  printf("\n");
}


x86 assembly (clang, -O0):
<do_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x424(%rbp)
lea    -0x424(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x430(%rbp),%rcx
mov    $0x400,%esi
lea    0xe4e(%rip),%rdx
call   1080 <strftime@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
lea    -0x420(%rbp),%rcx
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <vprintf@plt>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_log>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0xe5e(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
call   1090 <strftime@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe4d(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1080 <vprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%B %d %Y %H:%M:%S\00"
@.str.1 = [18 x i8] c"[%s][PID %d][%s] \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @do_log(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca %struct.tm*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = call i32 @time(i32* null)
store i32 %10, i32* %8
%11 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %11, %struct.tm** %9
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = load %struct.tm*, %struct.tm** %9
%14 = call i32 @strftime(i8* %12, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %13)
%15 = load i8*, i8** %4
%16 = call i32 (...) @getpid()
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %16, i8* %17)
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i32 @vprintf(i8* %19, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%B %d %Y %H:%M:%S\00"
@.str.1 = [18 x i8] c"[%s][PID %d][%s] \00"
define void @do_log(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = tail call i32 @time(i32* null)
store i32 %8, i32* %5
%9 = call %struct.tm* @localtime(i32* %5)
%10 = call i32 @strftime(i8* %6, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %9)
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %11, i8* %6)
%13 = call i32 @vprintf(i8* %1, i32 %2)
%14 = call i32 @putchar(i32 10)
ret void
}