char *field2str(const char fld_type) {
  switch (fld_type) {
  case 'B':
    return "byte";
  case 'C':
    return "char";
  case 'D':
    return "double";
  case 'F':
    return "float";
  case 'I':
    return "int";
  case 'J':
    return "long";
  case 'L':
    return "reference";
  case 'S':
    return "short";
  case 'Z':
    return "boolean";
  case '[':
    return "array";
  default:
    return "Undefined";
  }
}


x86 assembly (clang, -O0):
<field2str>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x19,%eax
ja     11d4 <field2str+0xd4>
mov    -0x18(%rbp),%rax
lea    0xed5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf2d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xf22(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xf17(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xf0e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xf04(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xef8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xeed(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xee7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xedd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xed5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <field2str+0xdf>
lea    0xecb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<field2str>:
add    $0xffffffbe,%edi
cmp    $0x19,%edi
ja     112f <field2str+0x2f>
lea    0xf59(%rip),%rax
lea    0xeea(%rip),%rcx
movslq (%rcx,%rdi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
lea    0xf47(%rip),%rax
ret
lea    0xf44(%rip),%rax
ret
lea    0xf70(%rip),%rax
ret
lea    0xf3b(%rip),%rax
ret
lea    0xf39(%rip),%rax
ret
lea    0xf35(%rip),%rax
ret
lea    0xf32(%rip),%rax
ret
lea    0xf34(%rip),%rax
ret
lea    0xf32(%rip),%rax
ret
lea    0xf32(%rip),%rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"byte\00"
@.str.1 = [5 x i8] c"char\00"
@.str.2 = [7 x i8] c"double\00"
@.str.3 = [6 x i8] c"float\00"
@.str.4 = [4 x i8] c"int\00"
@.str.5 = [5 x i8] c"long\00"
@.str.6 = [10 x i8] c"reference\00"
@.str.7 = [6 x i8] c"short\00"
@.str.8 = [8 x i8] c"boolean\00"
@.str.9 = [6 x i8] c"array\00"
@.str.10 = [10 x i8] c"Undefined\00"
define i8* @field2str(i8 signext %0) {
%2 = alloca i8*
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
switch i32 %5, label %16 [
i32 66, label %6
i32 67, label %7
i32 68, label %8
i32 70, label %9
i32 73, label %10
i32 74, label %11
i32 76, label %12
i32 83, label %13
i32 90, label %14
i32 91, label %15
]
6: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
br label %17
7: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %17
8: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %17
9: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %17
10: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %17
11: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %17
12: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %17
13: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %17
14: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %17
15: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %17
16: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %17
17: ; preds = %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@.str = [5 x i8] c"byte\00"
@.str.1 = [5 x i8] c"char\00"
@.str.2 = [7 x i8] c"double\00"
@.str.3 = [6 x i8] c"float\00"
@.str.4 = [4 x i8] c"int\00"
@.str.5 = [5 x i8] c"long\00"
@.str.6 = [10 x i8] c"reference\00"
@.str.7 = [6 x i8] c"short\00"
@.str.8 = [8 x i8] c"boolean\00"
@.str.9 = [6 x i8] c"array\00"
@.str.10 = [10 x i8] c"Undefined\00"
define i8* @field2str(i8 signext %0) {
%2 = sext i8 %0 to i32
switch i32 %2, label %12 [
i32 66, label %13
i32 67, label %3
i32 68, label %4
i32 70, label %5
i32 73, label %6
i32 74, label %7
i32 76, label %8
i32 83, label %9
i32 90, label %10
i32 91, label %11
]
3: ; preds = %1
br label %13
4: ; preds = %1
br label %13
5: ; preds = %1
br label %13
6: ; preds = %1
br label %13
7: ; preds = %1
br label %13
8: ; preds = %1
br label %13
9: ; preds = %1
br label %13
10: ; preds = %1
br label %13
11: ; preds = %1
br label %13
12: ; preds = %1
br label %13
13: ; preds = %1, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3
%14 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), %12 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), %11 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), %10 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), %8 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %7 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %4 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %14
}