#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 */
char *str_alloc_printf(char *, char *, char const *);
char *logging_colored_formatter(int level, const char *message) {
  char *log_level;
  switch (level) {
  case 1:
    log_level = "\x1b[36m"
                "DEBUGM"
                "\x1b[0m";
    break;
  case 2:
    log_level = "\x1b[34m"
                "DEBUG"
                "\x1b[0m";
    break;
  case 3:
    log_level = "\x1b[32m"
                "INFO"
                "\x1b[0m";
    break;
  case 4:
    log_level = "\x1b[33m"
                "WARNING"
                "\x1b[0m";
    break;
  case 5:
    log_level = "\x1b[31m"
                "ERROR"
                "\x1b[0m";
    break;
  default:
    log_level = "UNKNOWN";
    break;
  }
  char *formatted = str_alloc_printf("%s: %s", log_level, message);
  return formatted;
}


x86 assembly (clang, -O0):
<logging_colored_formatter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     1198 <logging_colored_formatter+0x88>
mov    -0x28(%rbp),%rax
lea    0xec1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec5(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <logging_colored_formatter+0x93>
lea    0xec5(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <logging_colored_formatter+0x93>
lea    0xec4(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <logging_colored_formatter+0x93>
lea    0xec2(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <logging_colored_formatter+0x93>
lea    0xec3(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <logging_colored_formatter+0x93>
lea    0xec2(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xeb7(%rip),%rdi
call   1030 <str_alloc_printf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logging_colored_formatter>:
mov    %rsi,%rdx
add    $0xffffffff,%edi
cmp    $0x4,%edi
ja     1138 <logging_colored_formatter+0x28>
movslq %edi,%rax
lea    0xf37(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
lea    0xf22(%rip),%rdi
jmp    1030 <str_alloc_printf@plt>
lea    0xf0e(%rip),%rsi
lea    0xf0f(%rip),%rdi
jmp    1030 <str_alloc_printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"\1B[36mDEBUGM\1B[0m\00"
@.str.1 = [15 x i8] c"\1B[34mDEBUG\1B[0m\00"
@.str.2 = [14 x i8] c"\1B[32mINFO\1B[0m\00"
@.str.3 = [17 x i8] c"\1B[33mWARNING\1B[0m\00"
@.str.4 = [15 x i8] c"\1B[31mERROR\1B[0m\00"
@.str.5 = [8 x i8] c"UNKNOWN\00"
@.str.6 = [7 x i8] c"%s: %s\00"
define i8* @logging_colored_formatter(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
switch i32 %7, label %13 [
i32 1, label %8
i32 2, label %9
i32 3, label %10
i32 4, label %11
i32 5, label %12
]
8: ; preds = %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %5
br label %14
9: ; preds = %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %14
10: ; preds = %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %14
11: ; preds = %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8** %5
br label %14
12: ; preds = %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %5
br label %14
13: ; preds = %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %5
br label %14
14: ; preds = %13, %12, %11, %10, %9, %8
%15 = load i8*, i8** %5
%16 = load i8*, i8** %4
%17 = call i8* @str_alloc_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %15, i8* %16)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
ret i8* %18
}

LLVM IR (-O2):
@.str = [16 x i8] c"\1B[36mDEBUGM\1B[0m\00"
@.str.1 = [15 x i8] c"\1B[34mDEBUG\1B[0m\00"
@.str.2 = [14 x i8] c"\1B[32mINFO\1B[0m\00"
@.str.3 = [17 x i8] c"\1B[33mWARNING\1B[0m\00"
@.str.4 = [15 x i8] c"\1B[31mERROR\1B[0m\00"
@.str.5 = [8 x i8] c"UNKNOWN\00"
@.str.6 = [7 x i8] c"%s: %s\00"
@reltable.logging_colored_formatter = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_colored_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_colored_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_colored_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_colored_formatter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.logging_colored_formatter to i64)) to i32)]
define i8* @logging_colored_formatter(i32 %0, i8* %1) {
%3 = add i32 %0, -1
%4 = icmp ult i32 %3, 5
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.logging_colored_formatter to i8*), i64 %7)
br label %9
9: ; preds = %2, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %2 ]
%11 = tail call i8* @str_alloc_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %10, i8* %1)
ret i8* %11
}