#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*/ bzero(char *, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void debug_log(short level, char *msg) {
  char log_level[10];
  bzero(log_level, 10);
  switch (level) {
  case 1:
    strcpy(log_level, "DEBUG");
    break;
  case 2:
    strcpy(log_level, "TRACE");
    break;
  case 3:
    strcpy(log_level, "NOTICE");
    break;
  case 4:
    strcpy(log_level, "WARNING");
    break;
  case 5:
    strcpy(log_level, "FATAL");
    break;
  default:
    strcpy(log_level, "NOTICE");
  }
  printf("[%s] %s\n", log_level, msg);
}


x86 assembly (clang, -O0):
<debug_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1a(%rbp),%rdi
mov    $0xa,%esi
call   1050 <bzero@plt>
movswl -0x2(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     11e4 <debug_log+0xb4>
mov    -0x28(%rbp),%rax
lea    0xe8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x1a(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f4 <debug_log+0xc4>
lea    -0x1a(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f4 <debug_log+0xc4>
lea    -0x1a(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f4 <debug_log+0xc4>
lea    -0x1a(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f4 <debug_log+0xc4>
lea    -0x1a(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f4 <debug_log+0xc4>
lea    -0x1a(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x1a(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_log>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
call   1050 <bzero@plt>
add    $0xffffffff,%ebp
cmp    $0x4,%ebp
ja     1165 <debug_log+0x35>
movslq %ebp,%rax
lea    0xed0(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    116c <debug_log+0x3c>
lea    0xea0(%rip),%rsi
lea    0xe(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xea1(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"DEBUG\00"
@.str.1 = [6 x i8] c"TRACE\00"
@.str.2 = [7 x i8] c"NOTICE\00"
@.str.3 = [8 x i8] c"WARNING\00"
@.str.4 = [6 x i8] c"FATAL\00"
@.str.5 = [9 x i8] c"[%s] %s\0A\00"
define void @debug_log(i16 signext %0, i8* %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca [10 x i8]
store i16 %0, i16* %3
store i8* %1, i8** %4
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 10)
%8 = load i16, i16* %3
%9 = sext i16 %8 to i32
switch i32 %9, label %25 [
i32 1, label %10
i32 2, label %13
i32 3, label %16
i32 4, label %19
i32 5, label %22
]
10: ; preds = %2
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %28
13: ; preds = %2
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %28
16: ; preds = %2
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %28
19: ; preds = %2
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %28
22: ; preds = %2
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %28
25: ; preds = %2
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %22, %19, %16, %13, %10
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%30 = load i8*, i8** %4
%31 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %29, i8* %30)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"DEBUG\00"
@.str.1 = [6 x i8] c"TRACE\00"
@.str.2 = [7 x i8] c"NOTICE\00"
@.str.3 = [8 x i8] c"WARNING\00"
@.str.4 = [6 x i8] c"FATAL\00"
@.str.5 = [9 x i8] c"[%s] %s\0A\00"
@reltable.debug_log = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.debug_log to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.debug_log to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.debug_log to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.debug_log to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.debug_log to i64)) to i32)]
define void @debug_log(i16 signext %0, i8* %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i32 @bzero(i8* %4, i32 10)
%6 = sext i16 %0 to i32
%7 = add nsw i32 %6, -1
%8 = icmp ult i32 %7, 5
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.debug_log to i8*), i64 %11)
br label %13
13: ; preds = %2, %9
%14 = phi i8* [ %12, %9 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %2 ]
%15 = call i32 @strcpy(i8* %4, i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %4, i8* %1)
ret void
}