const char *logger_getSeverityStr(unsigned short sev) {
  static struct LOG_SEVERITY {
    unsigned short sev;
    char descr[6];
  } SEVERITY_LIST[] = {{1, "CRTL"}, {2, "EROR"}, {3, "WARN"}, {4, "INFO"},
                       {5, "DEBG"}, {6, "DBGV"}, {7, "DBVV"}};
  if (sev > 0 && sev <= (sizeof(SEVERITY_LIST) / sizeof(SEVERITY_LIST[0]))) {
    return SEVERITY_LIST[sev - 1].descr;
  }
  return SEVERITY_LIST[3].descr;
}


x86 assembly (clang, -O0):
<logger_getSeverityStr>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
cmp    $0x0,%eax
jle    114b <logger_getSeverityStr+0x4b>
movzwl -0xa(%rbp),%eax
cmp    $0x7,%rax
ja     114b <logger_getSeverityStr+0x4b>
movzwl -0xa(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ef9(%rip),%rax
shl    $0x3,%rcx
add    %rcx,%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    115a <logger_getSeverityStr+0x5a>
lea    0x2ede(%rip),%rax
add    $0x1a,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<logger_getSeverityStr>:
add    $0xffffffff,%edi
mov    %rdi,%rax
shl    $0x3,%rax
cmp    $0x7,%di
lea    0x2f1b(%rip),%rcx
mov    $0x18,%edx
cmovb  %rax,%rdx
lea    (%rdx,%rcx,1),%rax
add    $0x2,%rax
ret

LLVM IR (-O0):
%struct.LOG_SEVERITY = type { i16, [6 x i8] }
@logger_getSeverityStr.SEVERITY_LIST = internal global [7 x %struct.LOG_SEVERITY] [%struct.LOG_SEVERITY { i16 1, [6 x i8] c"CRTL\00\00" }, %struct.LOG_SEVERITY { i16 2, [6 x i8] c"EROR\00\00" }, %struct.LOG_SEVERITY { i16 3, [6 x i8] c"WARN\00\00" }, %struct.LOG_SEVERITY { i16 4, [6 x i8] c"INFO\00\00" }, %struct.LOG_SEVERITY { i16 5, [6 x i8] c"DEBG\00\00" }, %struct.LOG_SEVERITY { i16 6, [6 x i8] c"DBGV\00\00" }, %struct.LOG_SEVERITY { i16 7, [6 x i8] c"DBVV\00\00" }]
define i8* @logger_getSeverityStr(i16 zeroext %0) {
%2 = alloca i8*
%3 = alloca i16
store i16 %0, i16* %3
%4 = load i16, i16* %3
%5 = zext i16 %4 to i32
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = load i16, i16* %3
%9 = zext i16 %8 to i64
%10 = icmp ule i64 %9, 7
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = load i16, i16* %3
%13 = zext i16 %12 to i32
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [7 x %struct.LOG_SEVERITY], [7 x %struct.LOG_SEVERITY]* @logger_getSeverityStr.SEVERITY_LIST, i64 0, i64 %15
%17 = getelementptr inbounds %struct.LOG_SEVERITY, %struct.LOG_SEVERITY* %16, i32 0, i32 1
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %17, i64 0, i64 0
store i8* %18, i8** %2
br label %20
19: ; preds = %7, %1
store i8* getelementptr inbounds ([7 x %struct.LOG_SEVERITY], [7 x %struct.LOG_SEVERITY]* @logger_getSeverityStr.SEVERITY_LIST, i64 0, i64 3, i32 1, i64 0), i8** %2
br label %20
20: ; preds = %19, %11
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
%struct.LOG_SEVERITY = type { i16, [6 x i8] }
@logger_getSeverityStr.SEVERITY_LIST = internal global [7 x %struct.LOG_SEVERITY] [%struct.LOG_SEVERITY { i16 1, [6 x i8] c"CRTL\00\00" }, %struct.LOG_SEVERITY { i16 2, [6 x i8] c"EROR\00\00" }, %struct.LOG_SEVERITY { i16 3, [6 x i8] c"WARN\00\00" }, %struct.LOG_SEVERITY { i16 4, [6 x i8] c"INFO\00\00" }, %struct.LOG_SEVERITY { i16 5, [6 x i8] c"DEBG\00\00" }, %struct.LOG_SEVERITY { i16 6, [6 x i8] c"DBGV\00\00" }, %struct.LOG_SEVERITY { i16 7, [6 x i8] c"DBVV\00\00" }]
define i8* @logger_getSeverityStr(i16 zeroext %0) {
%2 = add i16 %0, -1
%3 = icmp ult i16 %2, 7
%4 = zext i16 %0 to i64
%5 = add nuw nsw i64 %4, 4294967295
%6 = and i64 %5, 4294967295
%7 = getelementptr inbounds [7 x %struct.LOG_SEVERITY], [7 x %struct.LOG_SEVERITY]* @logger_getSeverityStr.SEVERITY_LIST, i64 0, i64 %6, i32 1, i64 0
%8 = select i1 %3, i8* %7, i8* getelementptr inbounds ([7 x %struct.LOG_SEVERITY], [7 x %struct.LOG_SEVERITY]* @logger_getSeverityStr.SEVERITY_LIST, i64 0, i64 3, i32 1, i64 0)
ret i8* %8
}