#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *logging_get_timestamp(char *);
char *str_alloc_printf(char *, char *, char *, char const *);
char *logging_timestamp_formatter(int level, const char *message) {
  char *timestamp = logging_get_timestamp("%x %X");
  if (!timestamp)
    return NULL;
  char *log_level = NULL;
  switch (level) {
  case 1:
    log_level = "DEBUGM";
    break;
  case 2:
    log_level = "DEBUG";
    break;
  case 3:
    log_level = "INFO";
    break;
  case 4:
    log_level = "WARNING";
    break;
  case 5:
    log_level = "ERROR";
    break;
  default:
    log_level = "UNKNOWN";
    break;
  }
  char *buffer = str_alloc_printf("[%s] %s: %s", timestamp, log_level, message);
  free(timestamp);
  return buffer;
}


x86 assembly (clang, -O0):
<logging_timestamp_formatter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xece(%rip),%rdi
call   1050 <logging_get_timestamp@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1167 <logging_timestamp_formatter+0x37>
movq   $0x0,-0x8(%rbp)
jmp    1220 <logging_timestamp_formatter+0xf0>
movq   $0x0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x4,%eax
ja     11e8 <logging_timestamp_formatter+0xb8>
mov    -0x38(%rbp),%rax
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe7b(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11f3 <logging_timestamp_formatter+0xc3>
lea    0xe72(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11f3 <logging_timestamp_formatter+0xc3>
lea    0xe68(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11f3 <logging_timestamp_formatter+0xc3>
lea    0xe5d(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11f3 <logging_timestamp_formatter+0xc3>
lea    0xe55(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11f3 <logging_timestamp_formatter+0xc3>
lea    0xe4b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe3c(%rip),%rdi
call   1040 <str_alloc_printf@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logging_timestamp_formatter>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xec0(%rip),%rdi
call   1050 <logging_get_timestamp@plt>
test   %rax,%rax
je     1168 <logging_timestamp_formatter+0x38>
mov    %rax,%rbx
add    $0xffffffff,%ebp
cmp    $0x4,%ebp
ja     116c <logging_timestamp_formatter+0x3c>
movslq %ebp,%rax
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
jmp    1173 <logging_timestamp_formatter+0x43>
xor    %eax,%eax
jmp    1193 <logging_timestamp_formatter+0x63>
lea    0xeb3(%rip),%rdx
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rcx
call   1040 <str_alloc_printf@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%x %X\00"
@.str.1 = [7 x i8] c"DEBUGM\00"
@.str.2 = [6 x i8] c"DEBUG\00"
@.str.3 = [5 x i8] c"INFO\00"
@.str.4 = [8 x i8] c"WARNING\00"
@.str.5 = [6 x i8] c"ERROR\00"
@.str.6 = [8 x i8] c"UNKNOWN\00"
@.str.7 = [12 x i8] c"[%s] %s: %s\00"
define i8* @logging_timestamp_formatter(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = call i8* @logging_get_timestamp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i8* null, i8** %3
br label %29
13: ; preds = %2
store i8* null, i8** %7
%14 = load i32, i32* %4
switch i32 %14, label %20 [
i32 1, label %15
i32 2, label %16
i32 3, label %17
i32 4, label %18
i32 5, label %19
]
15: ; preds = %13
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %21
16: ; preds = %13
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %21
17: ; preds = %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %21
18: ; preds = %13
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %21
19: ; preds = %13
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %21
20: ; preds = %13
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %21
21: ; preds = %20, %19, %18, %17, %16, %15
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = call i8* @str_alloc_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %22, i8* %23, i8* %24)
store i8* %25, i8** %8
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %8
store i8* %28, i8** %3
br label %29
29: ; preds = %21, %12
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
@.str = [6 x i8] c"%x %X\00"
@.str.1 = [7 x i8] c"DEBUGM\00"
@.str.2 = [6 x i8] c"DEBUG\00"
@.str.3 = [5 x i8] c"INFO\00"
@.str.4 = [8 x i8] c"WARNING\00"
@.str.5 = [6 x i8] c"ERROR\00"
@.str.6 = [8 x i8] c"UNKNOWN\00"
@.str.7 = [12 x i8] c"[%s] %s: %s\00"
@reltable.logging_timestamp_formatter = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_timestamp_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_timestamp_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_timestamp_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_timestamp_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.5 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_timestamp_formatter to i64)) to i32)]
define i8* @logging_timestamp_formatter(i32 %0, i8* %1) {
%3 = tail call i8* @logging_get_timestamp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = add i32 %0, -1
%7 = icmp ult i32 %6, 5
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = sext i32 %6 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.logging_timestamp_formatter to i8*), i64 %10)
br label %12
12: ; preds = %5, %8
%13 = phi i8* [ %11, %8 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %5 ]
%14 = tail call i8* @str_alloc_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %3, i8* %13, i8* %1)
%15 = tail call i32 @free(i8* %3)
br label %16
16: ; preds = %2, %12
%17 = phi i8* [ %14, %12 ], [ null, %2 ]
ret i8* %17
}