const char *get_program_header_type(int type) {
  const char *types[] = {"NULL",  "LOAD", "DYNAMIC", "INTERP", "NOTE",
                         "SHLIB", "PHDR", "TLS",     "NUM"};
  if (type <= 8) {
    return types[type];
  }
  if (type == 0x6474e550) {
    return "GNU_EH_FRAME";
  }
  if (type == 0x6474e551) {
    return "GNU_STACK";
  }
  if (type == 0x6474e552) {
    return "GNU_RELRO";
  }
  return "UNKNOWN";
}


x86 assembly (clang, -O0):
<get_program_header_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2caa(%rip),%rsi
mov    $0x48,%edx
call   1030 <memcpy@plt>
cmpl   $0x8,-0xc(%rbp)
jg     114c <get_program_header_type+0x3c>
movslq -0xc(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <get_program_header_type+0x9e>
cmpl   $0x6474e550,-0xc(%rbp)
jne    1169 <get_program_header_type+0x59>
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <get_program_header_type+0x9e>
cmpl   $0x6474e551,-0xc(%rbp)
jne    1186 <get_program_header_type+0x76>
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <get_program_header_type+0x9e>
cmpl   $0x6474e552,-0xc(%rbp)
jne    11a3 <get_program_header_type+0x93>
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <get_program_header_type+0x9e>
lea    0xea8(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_program_header_type>:
cmp    $0x8,%edi
jg     1111 <get_program_header_type+0x11>
movslq %edi,%rax
lea    0x2ce1(%rip),%rcx
jmp    1126 <get_program_header_type+0x26>
add    $0x9b8b1ab0,%edi
cmp    $0x2,%edi
ja     112e <get_program_header_type+0x2e>
movslq %edi,%rax
lea    0x2d12(%rip),%rcx
lea    (%rcx,%rax,8),%rax
mov    (%rax),%rax
ret
lea    0xf1d(%rip),%rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"LOAD\00"
@.str.2 = [8 x i8] c"DYNAMIC\00"
@.str.3 = [7 x i8] c"INTERP\00"
@.str.4 = [5 x i8] c"NOTE\00"
@.str.5 = [6 x i8] c"SHLIB\00"
@.str.6 = [5 x i8] c"PHDR\00"
@.str.7 = [4 x i8] c"TLS\00"
@.str.8 = [4 x i8] c"NUM\00"
@__const.get_program_header_type.types = [9 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0)]
@.str.9 = [13 x i8] c"GNU_EH_FRAME\00"
@.str.10 = [10 x i8] c"GNU_STACK\00"
@.str.11 = [10 x i8] c"GNU_RELRO\00"
@.str.12 = [8 x i8] c"UNKNOWN\00"
define i8* @get_program_header_type(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [9 x i8*]
store i32 %0, i32* %3
%5 = bitcast [9 x i8*]* %4 to i8*
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 8
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [9 x i8*], [9 x i8*]* %4, i64 0, i64 %10
%12 = load i8*, i8** %11
store i8* %12, i8** %2
br label %26
13: ; preds = %1
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 1685382480
br i1 %15, label %16, label %17
16: ; preds = %13
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %26
17: ; preds = %13
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 1685382481
br i1 %19, label %20, label %21
20: ; preds = %17
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %26
21: ; preds = %17
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 1685382482
br i1 %23, label %24, label %25
24: ; preds = %21
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8** %2
br label %26
25: ; preds = %21
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i8** %2
br label %26
26: ; preds = %25, %24, %20, %16, %8
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"LOAD\00"
@.str.2 = [8 x i8] c"DYNAMIC\00"
@.str.3 = [7 x i8] c"INTERP\00"
@.str.4 = [5 x i8] c"NOTE\00"
@.str.5 = [6 x i8] c"SHLIB\00"
@.str.6 = [5 x i8] c"PHDR\00"
@.str.7 = [4 x i8] c"TLS\00"
@.str.8 = [4 x i8] c"NUM\00"
@__const.get_program_header_type.types = [9 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0)]
@.str.9 = [13 x i8] c"GNU_EH_FRAME\00"
@.str.10 = [10 x i8] c"GNU_STACK\00"
@.str.11 = [10 x i8] c"GNU_RELRO\00"
@.str.12 = [8 x i8] c"UNKNOWN\00"
@switch.table.get_program_header_type = [3 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0)]
define i8* @get_program_header_type(i32 %0) {
%2 = icmp slt i32 %0, 9
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = sext i32 %0 to i64
%5 = getelementptr inbounds [9 x i8*], [9 x i8*]* @__const.get_program_header_type.types, i64 0, i64 %4
br label %12
6: ; preds = %1
%7 = add i32 %0, -1685382480
%8 = icmp ult i32 %7, 3
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* @switch.table.get_program_header_type, i64 0, i64 %10
br label %12
12: ; preds = %3, %9
%13 = phi i8** [ %11, %9 ], [ %5, %3 ]
%14 = load i8*, i8** %13
br label %15
15: ; preds = %12, %6
%16 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), %6 ], [ %14, %12 ]
ret i8* %16
}