#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*/ timebuf;
typedef int /*<<< orphan*/ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *, char const *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
void PICA_log_entry(int loglevel, const char *fmt, va_list args) {
  static char buf[1024];
  static const char *loglevel_txt[] = {"fatal",  "error",  "warning", "info",
                                       "debug1", "debug2", "debug3"};
  FILE *log_file = stdout;
  time_t log_time;
  static char timebuf[32];
  if (loglevel <= 31339)
    log_file = stderr;
  log_time = time(NULL);
  strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", localtime(&log_time));
  sprintf(buf, "[%.32s] %s: %.1000s\n", timebuf, loglevel_txt[loglevel - 31337],
          fmt);
  vfprintf(log_file, buf, args);
  fflush(log_file);
}


x86 assembly (clang, -O0):
<PICA_log_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x7a6b,-0x4(%rbp)
jg     119b <PICA_log_entry+0x3b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%ecx
lea    0x3307(%rip),%rdi
mov    $0x20,%esi
lea    0xe69(%rip),%rdx
call   1060 <strftime@plt>
mov    -0x4(%rbp),%eax
sub    $0x7a69,%eax
movslq %eax,%rcx
lea    0x2e84(%rip),%rax
mov    (%rax,%rcx,8),%rcx
mov    -0x10(%rbp),%r8
lea    0x2ec5(%rip),%rdi
lea    0xe4e(%rip),%rsi
lea    0x32c7(%rip),%rdx
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0x2ea4(%rip),%rsi
call   1070 <vfprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PICA_log_entry>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebx
cmp    $0x7a6c,%edi
jge    1185 <PICA_log_entry+0x25>
mov    0x2e5d(%rip),%rax
jmp    118c <PICA_log_entry+0x2c>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rbp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0x32c5(%rip),%r12
lea    0xe98(%rip),%rdx
mov    %r12,%rdi
mov    $0x20,%esi
mov    %eax,%ecx
call   1060 <strftime@plt>
movslq %ebx,%rax
lea    0xe35(%rip),%rdx
movslq -0x1e9a4(%rdx,%rax,4),%rcx
ff
add    %rdx,%rcx
lea    0x2e83(%rip),%rbx
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15,%r8
call   1080 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <vfprintf@plt>
mov    %rbp,%rdi
call   1050 <fflush@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PICA_log_entry.buf = internal global [1024 x i8] zeroinitializer
@PICA_log_entry.loglevel_txt = internal global [7 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0)]
@.str = [6 x i8] c"fatal\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [8 x i8] c"warning\00"
@.str.3 = [5 x i8] c"info\00"
@.str.4 = [7 x i8] c"debug1\00"
@.str.5 = [7 x i8] c"debug2\00"
@.str.6 = [7 x i8] c"debug3\00"
@stdout = global i32* null
@PICA_log_entry.timebuf = internal global [32 x i8] zeroinitializer
@stderr = global i32* null
@.str.7 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.8 = [21 x i8] c"[%.32s] %s: %.1000s\0A\00"
define void @PICA_log_entry(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32*, i32** @stdout
store i32* %9, i32** %7
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 31339
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32*, i32** @stderr
store i32* %13, i32** %7
br label %14
14: ; preds = %12, %3
%15 = call i32 @time(i32* null)
store i32 %15, i32* %8
%16 = call i32 @localtime(i32* %8)
%17 = call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @PICA_log_entry.timebuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 31337
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [7 x i8*], [7 x i8*]* @PICA_log_entry.loglevel_txt, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = load i8*, i8** %5
%24 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @PICA_log_entry.buf, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @PICA_log_entry.timebuf, i64 0, i64 0), i8* %22, i8* %23)
%25 = load i32*, i32** %7
%26 = load i32, i32* %6
%27 = call i32 @vfprintf(i32* %25, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @PICA_log_entry.buf, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %7
%29 = call i32 @fflush(i32* %28)
ret void
}

LLVM IR (-O2):
@PICA_log_entry.buf = internal global [1024 x i8] zeroinitializer
@reltable.PICA_log_entry = internal unnamed_addr constant [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.PICA_log_entry to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.PICA_log_entry to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.PICA_log_entry to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.PICA_log_entry to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.PICA_log_entry to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.PICA_log_entry to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.PICA_log_entry to i64)) to i32)]
@.str = [6 x i8] c"fatal\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [8 x i8] c"warning\00"
@.str.3 = [5 x i8] c"info\00"
@.str.4 = [7 x i8] c"debug1\00"
@.str.5 = [7 x i8] c"debug2\00"
@.str.6 = [7 x i8] c"debug3\00"
@stdout = global i32* null
@PICA_log_entry.timebuf = internal global [32 x i8] zeroinitializer
@stderr = global i32* null
@.str.7 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.8 = [21 x i8] c"[%.32s] %s: %.1000s\0A\00"
define void @PICA_log_entry(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = load i32*, i32** @stdout
%6 = bitcast i32* %4 to i8*
%7 = icmp slt i32 %0, 31340
%8 = load i32*, i32** @stderr
%9 = select i1 %7, i32* %8, i32* %5
%10 = tail call i32 @time(i32* null)
store i32 %10, i32* %4
%11 = call i32 @localtime(i32* %4)
%12 = call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @PICA_log_entry.timebuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %11)
%13 = add nsw i32 %0, -31337
%14 = sext i32 %13 to i64
%15 = shl i64 %14, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.PICA_log_entry to i8*), i64 %15)
%17 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @PICA_log_entry.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @PICA_log_entry.timebuf, i64 0, i64 0), i8* %16, i8* %1)
%18 = call i32 @vfprintf(i32* %9, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @PICA_log_entry.buf, i64 0, i64 0), i32 %2)
%19 = call i32 @fflush(i32* %9)
ret void
}