char *print_ph_type(int num) {
  static char *ph_table[] = {"PT_NULL", "PT_LOAD",  "PT_DYNAMIC", "PT_INTERP",
                             "PT_NOTE", "PT_SHLIB", "PT_PHDR",    "PT_TLS",
                             "PT_NUM",  ""};
  if ((num < 0) || (num > 8))
    return " ";
  return ph_table[num];
}


x86 assembly (clang, -O0):
<print_ph_type>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     111b <print_ph_type+0x1b>
cmpl   $0x8,-0xc(%rbp)
jle    112b <print_ph_type+0x2b>
lea    0xf2a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    113e <print_ph_type+0x3e>
movslq -0xc(%rbp),%rcx
lea    0x2efa(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ph_type>:
cmp    $0x8,%edi
jbe    110d <print_ph_type+0xd>
lea    0xf68(%rip),%rax
ret
mov    %edi,%eax
lea    0xeea(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@print_ph_type.ph_table = internal global [10 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i32 0, i32 0)]
@.str = [8 x i8] c"PT_NULL\00"
@.str.1 = [8 x i8] c"PT_LOAD\00"
@.str.2 = [11 x i8] c"PT_DYNAMIC\00"
@.str.3 = [10 x i8] c"PT_INTERP\00"
@.str.4 = [8 x i8] c"PT_NOTE\00"
@.str.5 = [9 x i8] c"PT_SHLIB\00"
@.str.6 = [8 x i8] c"PT_PHDR\00"
@.str.7 = [7 x i8] c"PT_TLS\00"
@.str.8 = [7 x i8] c"PT_NUM\00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [2 x i8] c" \00"
define i8* @print_ph_type(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 8
br i1 %8, label %9, label %10
9: ; preds = %6, %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %15
10: ; preds = %6
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i8*], [10 x i8*]* @print_ph_type.ph_table, i64 0, i64 %12
%14 = load i8*, i8** %13
store i8* %14, i8** %2
br label %15
15: ; preds = %10, %9
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
@reltable.print_ph_type = internal unnamed_addr constant [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([1 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.print_ph_type to i64)) to i32)]
@.str = [8 x i8] c"PT_NULL\00"
@.str.1 = [8 x i8] c"PT_LOAD\00"
@.str.2 = [11 x i8] c"PT_DYNAMIC\00"
@.str.3 = [10 x i8] c"PT_INTERP\00"
@.str.4 = [8 x i8] c"PT_NOTE\00"
@.str.5 = [9 x i8] c"PT_SHLIB\00"
@.str.6 = [8 x i8] c"PT_PHDR\00"
@.str.7 = [7 x i8] c"PT_TLS\00"
@.str.8 = [7 x i8] c"PT_NUM\00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [2 x i8] c" \00"
define i8* @print_ph_type(i32 %0) {
%2 = icmp ugt i32 %0, 8
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = zext i32 %0 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.print_ph_type to i8*), i64 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), %1 ]
ret i8* %8
}