char *http_code2str(int code) {
  struct table_t {
    int code;
    char *str;
  };
  static const struct table_t table[] = {{200, "OK"},
                                         {400, "Bad Request"},
                                         {404, "Not Found"},
                                         {413, "Request Entity Too Large"},
                                         {501, "Not Implemented"}};
  int i, table_size;
  table_size = sizeof(table) / sizeof(table[0]);
  for (i = 0; i != table_size; ++i)
    if (code == table[i].code)
      return table[i].str;
  return table[1].str;
}


x86 assembly (clang, -O0):
<http_code2str>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
movl   $0x5,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1170 <http_code2str+0x70>
mov    -0xc(%rbp),%eax
movslq -0x10(%rbp),%rdx
lea    0x2cd1(%rip),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
cmp    (%rcx),%eax
jne    115d <http_code2str+0x5d>
movslq -0x10(%rbp),%rcx
lea    0x2cb7(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    117b <http_code2str+0x7b>
jmp    1162 <http_code2str+0x62>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1115 <http_code2str+0x15>
mov    0x2ca1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_code2str>:
lea    0xefc(%rip),%rax
cmp    $0x193,%edi
jle    112e <http_code2str+0x2e>
cmp    $0x194,%edi
je     1145 <http_code2str+0x45>
cmp    $0x19d,%edi
je     114c <http_code2str+0x4c>
cmp    $0x1f5,%edi
jne    1165 <http_code2str+0x65>
mov    $0x4,%eax
jmp    1155 <http_code2str+0x55>
cmp    $0xc8,%edi
je     1153 <http_code2str+0x53>
cmp    $0x190,%edi
jne    1165 <http_code2str+0x65>
mov    $0x1,%eax
jmp    1155 <http_code2str+0x55>
mov    $0x2,%eax
jmp    1155 <http_code2str+0x55>
mov    $0x3,%eax
jmp    1155 <http_code2str+0x55>
xor    %eax,%eax
shl    $0x4,%rax
lea    0x2ca0(%rip),%rcx
mov    0x8(%rax,%rcx,1),%rax
ret

LLVM IR (-O0):
%struct.table_t = type { i32, i8* }
@http_code2str.table = internal constant [5 x %struct.table_t] [%struct.table_t { i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0) }, %struct.table_t { i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i32 0, i32 0) }, %struct.table_t { i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0) }, %struct.table_t { i32 413, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i32 0, i32 0) }, %struct.table_t { i32 501, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i32 0, i32 0) }]
@.str = [3 x i8] c"OK\00"
@.str.1 = [12 x i8] c"Bad Request\00"
@.str.2 = [10 x i8] c"Not Found\00"
@.str.3 = [25 x i8] c"Request Entity Too Large\00"
@.str.4 = [16 x i8] c"Not Implemented\00"
define i8* @http_code2str(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 5, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %5
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [5 x %struct.table_t], [5 x %struct.table_t]* @http_code2str.table, i64 0, i64 %13
%15 = getelementptr inbounds %struct.table_t, %struct.table_t* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = icmp eq i32 %11, %16
br i1 %17, label %18, label %24
18: ; preds = %10
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [5 x %struct.table_t], [5 x %struct.table_t]* @http_code2str.table, i64 0, i64 %20
%22 = getelementptr inbounds %struct.table_t, %struct.table_t* %21, i32 0, i32 1
%23 = load i8*, i8** %22
store i8* %23, i8** %2
br label %30
24: ; preds = %10
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %6
28: ; preds = %6
%29 = load i8*, i8** getelementptr inbounds ([5 x %struct.table_t], [5 x %struct.table_t]* @http_code2str.table, i64 0, i64 1, i32 1)
store i8* %29, i8** %2
br label %30
30: ; preds = %28, %18
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
%struct.table_t = type { i32, i8* }
@http_code2str.table = internal unnamed_addr constant [5 x %struct.table_t] [%struct.table_t { i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0) }, %struct.table_t { i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i32 0, i32 0) }, %struct.table_t { i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0) }, %struct.table_t { i32 413, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i32 0, i32 0) }, %struct.table_t { i32 501, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i32 0, i32 0) }]
@.str = [3 x i8] c"OK\00"
@.str.1 = [12 x i8] c"Bad Request\00"
@.str.2 = [10 x i8] c"Not Found\00"
@.str.3 = [25 x i8] c"Request Entity Too Large\00"
@.str.4 = [16 x i8] c"Not Implemented\00"
define i8* @http_code2str(i32 %0) {
switch i32 %0, label %10 [
i32 200, label %6
i32 400, label %2
i32 404, label %3
i32 413, label %4
i32 501, label %5
]
2: ; preds = %1
br label %6
3: ; preds = %1
br label %6
4: ; preds = %1
br label %6
5: ; preds = %1
br label %6
6: ; preds = %1, %5, %4, %3, %2
%7 = phi i64 [ 0, %1 ], [ 1, %2 ], [ 2, %3 ], [ 3, %4 ], [ 4, %5 ]
%8 = getelementptr inbounds [5 x %struct.table_t], [5 x %struct.table_t]* @http_code2str.table, i64 0, i64 %7, i32 1
%9 = load i8*, i8** %8
br label %10
10: ; preds = %1, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %1 ]
ret i8* %11
}