char *httpd_method_str(int method) {
  static char *method_get = "GET";
  static char *method_head = "HEAD";
  static char *method_post = "POST";
  static char *unknown = "UNKNOWN";
  switch (method) {
  case 1:
    return method_get;
  case 3:
    return method_head;
  case 2:
    return method_post;
  default:
    return unknown;
  }
}


x86 assembly (clang, -O0):
<httpd_method_str>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     113d <httpd_method_str+0x3d>
jmp    111b <httpd_method_str+0x1b>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     115d <httpd_method_str+0x5d>
jmp    112c <httpd_method_str+0x2c>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     114d <httpd_method_str+0x4d>
jmp    116d <httpd_method_str+0x6d>
mov    0x2edc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <httpd_method_str+0x78>
mov    0x2ed4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <httpd_method_str+0x78>
mov    0x2ecc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <httpd_method_str+0x78>
mov    0x2ec4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<httpd_method_str>:
add    $0xffffffff,%edi
cmp    $0x2,%edi
ja     111a <httpd_method_str+0x1a>
movslq %edi,%rax
lea    0xf06(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xeed(%rip),%rax
ret

LLVM IR (-O0):
@httpd_method_str.method_get = internal global i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0)
@.str = [4 x i8] c"GET\00"
@httpd_method_str.method_head = internal global i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0)
@.str.1 = [5 x i8] c"HEAD\00"
@httpd_method_str.method_post = internal global i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)
@.str.2 = [5 x i8] c"POST\00"
@httpd_method_str.unknown = internal global i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0)
@.str.3 = [8 x i8] c"UNKNOWN\00"
define i8* @httpd_method_str(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %11 [
i32 1, label %5
i32 3, label %7
i32 2, label %9
]
5: ; preds = %1
%6 = load i8*, i8** @httpd_method_str.method_get
store i8* %6, i8** %2
br label %13
7: ; preds = %1
%8 = load i8*, i8** @httpd_method_str.method_head
store i8* %8, i8** %2
br label %13
9: ; preds = %1
%10 = load i8*, i8** @httpd_method_str.method_post
store i8* %10, i8** %2
br label %13
11: ; preds = %1
%12 = load i8*, i8** @httpd_method_str.unknown
store i8* %12, i8** %2
br label %13
13: ; preds = %11, %9, %7, %5
%14 = load i8*, i8** %2
ret i8* %14
}

LLVM IR (-O2):
@.str = [4 x i8] c"GET\00"
@.str.1 = [5 x i8] c"HEAD\00"
@.str.2 = [5 x i8] c"POST\00"
@.str.3 = [8 x i8] c"UNKNOWN\00"
@reltable.httpd_method_str = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.httpd_method_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.httpd_method_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.httpd_method_str to i64)) to i32)]
define i8* @httpd_method_str(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 3
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.httpd_method_str to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %1 ]
ret i8* %9
}