#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*/ snprintf(char *, int, char *, char *);
void log_lvl2str(int lvl, char *str) {
  switch (lvl) {
  case 0:
    snprintf(str, 9, "%s", "[CORE ] ");
    break;
  case 1:
    snprintf(str, 9, "%s", "[ERROR] ");
    break;
  case 2:
    snprintf(str, 9, "%s", "[WARN ] ");
    break;
  case 3:
    snprintf(str, 9, "%s", "[INFO ] ");
    break;
  default:
    snprintf(str, 9, "%s", "[DEBUG] ");
    break;
  }
}


x86 assembly (clang, -O0):
<log_lvl2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     11c8 <log_lvl2str+0xb8>
mov    -0x18(%rbp),%rax
lea    0xec5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
lea    0xebc(%rip),%rdx
lea    0xeb8(%rip),%rcx
call   1030 <snprintf@plt>
jmp    11e4 <log_lvl2str+0xd4>
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
lea    0xe9b(%rip),%rdx
lea    0xea0(%rip),%rcx
call   1030 <snprintf@plt>
jmp    11e4 <log_lvl2str+0xd4>
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
lea    0xe7a(%rip),%rdx
lea    0xe88(%rip),%rcx
call   1030 <snprintf@plt>
jmp    11e4 <log_lvl2str+0xd4>
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
lea    0xe59(%rip),%rdx
lea    0xe70(%rip),%rcx
call   1030 <snprintf@plt>
jmp    11e4 <log_lvl2str+0xd4>
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
lea    0xe38(%rip),%rdx
lea    0xe58(%rip),%rcx
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_lvl2str>:
cmp    $0x3,%edi
ja     1128 <log_lvl2str+0x18>
movslq %edi,%rax
lea    0xf11(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
jmp    112f <log_lvl2str+0x1f>
lea    0xef8(%rip),%rcx
lea    0xeca(%rip),%rdx
mov    %rsi,%rdi
mov    $0x9,%esi
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [9 x i8] c"[CORE ] \00"
@.str.2 = [9 x i8] c"[ERROR] \00"
@.str.3 = [9 x i8] c"[WARN ] \00"
@.str.4 = [9 x i8] c"[INFO ] \00"
@.str.5 = [9 x i8] c"[DEBUG] \00"
define void @log_lvl2str(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
switch i32 %5, label %18 [
i32 0, label %6
i32 1, label %9
i32 2, label %12
i32 3, label %15
]
6: ; preds = %2
%7 = load i8*, i8** %4
%8 = call i32 @snprintf(i8* %7, i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %21
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @snprintf(i8* %10, i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %21
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @snprintf(i8* %13, i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %21
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @snprintf(i8* %16, i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %21
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @snprintf(i8* %19, i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %18, %15, %12, %9, %6
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [9 x i8] c"[CORE ] \00"
@.str.2 = [9 x i8] c"[ERROR] \00"
@.str.3 = [9 x i8] c"[WARN ] \00"
@.str.4 = [9 x i8] c"[INFO ] \00"
@.str.5 = [9 x i8] c"[DEBUG] \00"
@reltable.log_lvl2str = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.log_lvl2str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.log_lvl2str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.log_lvl2str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.log_lvl2str to i64)) to i32)]
define void @log_lvl2str(i32 %0, i8* %1) {
%3 = icmp ult i32 %0, 4
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = sext i32 %0 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.log_lvl2str to i8*), i64 %6)
br label %8
8: ; preds = %2, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %2 ]
%10 = tail call i32 @snprintf(i8* %1, i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
ret void
}