#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*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ c_time_string;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, size_t);
struct tm *gmtime(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char const *);
scalar_t__ strftime(char *, int, char *, struct tm *);
int strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *logger_format(int level, const char *format) {
  time_t t = time(NULL);
  struct tm *current_time = gmtime(&t);
  char c_time_string[19];
  bzero(c_time_string, 19);
  if (current_time != NULL) {
    if (strftime(c_time_string, sizeof(c_time_string), "%F %T", current_time)) {
    }
  }
  char *str_level;
  switch (level) {
  case 1:
    str_level = "TARCE";
    break;
  case 2:
    str_level = "DEBUG";
    break;
  case 3:
    str_level = "INFO ";
    break;
  case 4:
    str_level = "WARN ";
    break;
  case 5:
    str_level = "ERROR";
    break;
  case 6:
    str_level = "FATAL";
    break;
  defualt:
    str_level = "WARN ";
    break;
  }
  size_t new_len = strlen(c_time_string) + 1 + strlen(str_level) + 1 +
                   strlen(format) + 1 + 1 + 1 + 1;
  char *new_format = malloc(sizeof(char) * new_len);
  bzero(new_format, new_len);
  sprintf(new_format, "%s %s %s\n", c_time_string, str_level, format);
  return new_format;
}


x86 assembly (clang, -O0):
<logger_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1080 <gmtime@plt>
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x13,%esi
call   1070 <bzero@plt>
cmpq   $0x0,-0x20(%rbp)
je     11de <logger_format+0x6e>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x13,%esi
lea    0xe53(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%rax
je     11d9 <logger_format+0x69>
jmp    11d9 <logger_format+0x69>
jmp    11de <logger_format+0x6e>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x60(%rbp)
sub    $0x5,%eax
ja     1262 <logger_format+0xf2>
mov    -0x60(%rbp),%rax
lea    0xe02(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe10(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1262 <logger_format+0xf2>
lea    0xe06(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1262 <logger_format+0xf2>
lea    0xdfc(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1262 <logger_format+0xf2>
lea    0xdf2(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1262 <logger_format+0xf2>
lea    0xde8(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1262 <logger_format+0xf2>
lea    0xdde(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
add    $0x1,%eax
add    $0x1,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1070 <bzero@plt>
mov    -0x58(%rbp),%rdi
lea    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xd62(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x58(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logger_format>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1080 <gmtime@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x13,%esi
call   1070 <bzero@plt>
test   %r15,%r15
je     11c8 <logger_format+0x58>
lea    0xe4a(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x13,%esi
mov    %r15,%rcx
call   1060 <strftime@plt>
add    $0xfffffffe,%ebx
cmp    $0x4,%ebx
ja     11e3 <logger_format+0x73>
movslq %ebx,%rax
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%r13
add    %rcx,%r13
jmp    11ea <logger_format+0x7a>
lea    0xe1c(%rip),%r13
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %r12d,%ebp
add    %ebp,%eax
add    $0x6,%eax
movslq %eax,%rbp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1070 <bzero@plt>
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %r14,%r8
call   1090 <sprintf@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [6 x i8] c"TARCE\00"
@.str.2 = [6 x i8] c"DEBUG\00"
@.str.3 = [6 x i8] c"INFO \00"
@.str.4 = [6 x i8] c"WARN \00"
@.str.5 = [6 x i8] c"ERROR\00"
@.str.6 = [6 x i8] c"FATAL\00"
@.str.7 = [10 x i8] c"%s %s %s\0A\00"
define i8* @logger_format(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.tm*
%7 = alloca [19 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%11 = call i32 @time(i32* null)
store i32 %11, i32* %5
%12 = call %struct.tm* @gmtime(i32* %5)
store %struct.tm* %12, %struct.tm** %6
%13 = getelementptr inbounds [19 x i8], [19 x i8]* %7, i64 0, i64 0
%14 = call i32 @bzero(i8* %13, i64 19)
%15 = load %struct.tm*, %struct.tm** %6
%16 = icmp ne %struct.tm* %15, null
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = getelementptr inbounds [19 x i8], [19 x i8]* %7, i64 0, i64 0
%19 = load %struct.tm*, %struct.tm** %6
%20 = call i64 @strftime(i8* %18, i32 19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %23
23: ; preds = %22, %17
br label %24
24: ; preds = %23, %2
%25 = load i32, i32* %3
switch i32 %25, label %33 [
i32 1, label %26
i32 2, label %27
i32 3, label %28
i32 4, label %29
i32 5, label %30
i32 6, label %31
]
26: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %33
27: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %33
28: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %33
29: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %8
br label %33
30: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %8
br label %33
31: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8** %8
br label %33
32: ; No predecessors!
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %8
br label %33
33: ; preds = %24, %32, %31, %30, %29, %28, %27, %26
%34 = getelementptr inbounds [19 x i8], [19 x i8]* %7, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %35, 1
%37 = load i8*, i8** %8
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %36, %38
%40 = add nsw i32 %39, 1
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
%43 = add nsw i32 %40, %42
%44 = add nsw i32 %43, 1
%45 = add nsw i32 %44, 1
%46 = add nsw i32 %45, 1
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
store i64 %48, i64* %9
%49 = load i64, i64* %9
%50 = mul i64 1, %49
%51 = trunc i64 %50 to i32
%52 = call i8* @malloc(i32 %51)
store i8* %52, i8** %10
%53 = load i8*, i8** %10
%54 = load i64, i64* %9
%55 = call i32 @bzero(i8* %53, i64 %54)
%56 = load i8*, i8** %10
%57 = getelementptr inbounds [19 x i8], [19 x i8]* %7, i64 0, i64 0
%58 = load i8*, i8** %8
%59 = load i8*, i8** %4
%60 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %57, i8* %58, i8* %59)
%61 = load i8*, i8** %10
ret i8* %61
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [6 x i8] c"TARCE\00"
@.str.2 = [6 x i8] c"DEBUG\00"
@.str.3 = [6 x i8] c"INFO \00"
@.str.4 = [6 x i8] c"WARN \00"
@.str.5 = [6 x i8] c"ERROR\00"
@.str.6 = [6 x i8] c"FATAL\00"
@.str.7 = [10 x i8] c"%s %s %s\0A\00"
@reltable.logger_format = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.logger_format to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.logger_format to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.logger_format to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.5 to i64), i64 ptrtoint ([5 x i32]* @reltable.logger_format to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.6 to i64), i64 ptrtoint ([5 x i32]* @reltable.logger_format to i64)) to i32)]
define noalias i8* @logger_format(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca [19 x i8]
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = call %struct.tm* @gmtime(i32* %3)
%8 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
%9 = call i32 @bzero(i8* %8, i64 19)
%10 = icmp eq %struct.tm* %7, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i64 @strftime(i8* %8, i32 19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
br label %13
13: ; preds = %11, %2
%14 = add i32 %0, -2
%15 = icmp ult i32 %14, 5
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = sext i32 %14 to i64
%18 = shl i64 %17, 2
%19 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.logger_format to i8*), i64 %18)
br label %20
20: ; preds = %16, %13
%21 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %13 ], [ %19, %16 ]
%22 = call i32 @strlen(i8* %8)
%23 = call i32 @strlen(i8* %21)
%24 = call i32 @strlen(i8* %1)
%25 = add i32 %22, 6
%26 = add i32 %25, %23
%27 = add i32 %26, %24
%28 = sext i32 %27 to i64
%29 = call i8* @malloc(i32 %27)
%30 = call i32 @bzero(i8* %29, i64 %28)
%31 = call i32 @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %8, i8* %21, i8* %1)
ret i8* %29
}