#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int Elf64_Half;

/* Variables and functions */
#define ET_CORE 132
#define ET_DYN 131
#define ET_EXEC 130
#define ET_NONE 129
#define ET_REL 128
int /*<<< orphan*/ printf(char *);
void parse_type(Elf64_Half e_type) {
  printf("File type: ");
  switch (e_type) {
  case ET_NONE:
    printf("No file type\n");
    break;
  case ET_REL:
    printf("Relocatable file\n");
    break;
  case ET_EXEC:
    printf("Executable file\n");
    break;
  case ET_DYN:
    printf("Shared object file\n");
    break;
  case ET_CORE:
    printf("Core file\n");
    break;
  default:
    printf("not found\n");
  }
}


x86 assembly (clang, -O0):
<parse_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xef2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     11a5 <parse_type+0x95>
mov    -0x10(%rbp),%rax
lea    0xeb9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <parse_type+0xa1>
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <parse_type+0xa1>
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <parse_type+0xa1>
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <parse_type+0xa1>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <parse_type+0xa1>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_type>:
push   %rbx
mov    %edi,%ebx
lea    0xed6(%rip),%rdi
call   1040 <printf@plt>
add    $0xffffff80,%ebx
cmp    $0x4,%ebx
ja     114e <parse_type+0x2e>
movslq %ebx,%rax
lea    0xf23(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xf02(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"File type: \00"
@.str.1 = [14 x i8] c"No file type\0A\00"
@.str.2 = [18 x i8] c"Relocatable file\0A\00"
@.str.3 = [17 x i8] c"Executable file\0A\00"
@.str.4 = [20 x i8] c"Shared object file\0A\00"
@.str.5 = [11 x i8] c"Core file\0A\00"
@.str.6 = [11 x i8] c"not found\0A\00"
define void @parse_type(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* %2
switch i32 %4, label %15 [
i32 129, label %5
i32 128, label %7
i32 130, label %9
i32 131, label %11
i32 132, label %13
]
5: ; preds = %1
%6 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %17
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %17
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %17
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %17
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %17
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %17
17: ; preds = %15, %13, %11, %9, %7, %5
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"File type: \00"
@str = [10 x i8] c"Core file\00"
@str.7 = [19 x i8] c"Shared object file\00"
@str.8 = [16 x i8] c"Executable file\00"
@str.9 = [17 x i8] c"Relocatable file\00"
@str.10 = [13 x i8] c"No file type\00"
@str.11 = [10 x i8] c"not found\00"
@reltable.parse_type = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @str.9 to i64), i64 ptrtoint ([5 x i32]* @reltable.parse_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.10 to i64), i64 ptrtoint ([5 x i32]* @reltable.parse_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.8 to i64), i64 ptrtoint ([5 x i32]* @reltable.parse_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @str.7 to i64), i64 ptrtoint ([5 x i32]* @reltable.parse_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @str to i64), i64 ptrtoint ([5 x i32]* @reltable.parse_type to i64)) to i32)]
define void @parse_type(i32 %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = add i32 %0, -128
%4 = icmp ult i32 %3, 5
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.parse_type to i8*), i64 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.11, i64 0, i64 0), %1 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
ret void
}