char *toString(char pieceId) {
  char *str;
  if (pieceId == 0) {
    str = (char *)"EMPTY";
  } else if (pieceId > 50) {
    pieceId = (char)(pieceId - 50);
    switch (pieceId) {
    case 1:
      str = (char *)"BLACK PAWN";
      break;
    case 2:
      str = (char *)"BLACK ROOK";
      break;
    case 3:
      str = (char *)"BLACK KNIGHT";
      break;
    case 4:
      str = (char *)"BLACK BISHOP";
      break;
    case 5:
      str = (char *)"BLACK QUEEN";
      break;
    case 6:
      str = (char *)"BLACK KING";
      break;
    }
  } else {
    switch (pieceId) {
    case 1:
      str = (char *)"WHITE PAWN";
      break;
    case 2:
      str = (char *)"WHITE ROOK";
      break;
    case 3:
      str = (char *)"WHITE KNIGHT";
      break;
    case 4:
      str = (char *)"WHITE BISHOP";
      break;
    case 5:
      str = (char *)"WHITE QUEEN";
      break;
    case 6:
      str = (char *)"WHITE KING";
      break;
    }
  }
  return str;
}


x86 assembly (clang, -O0):
<toString>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x0,%eax
jne    1127 <toString+0x27>
lea    0xf12(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1255 <toString+0x155>
movsbl -0x1(%rbp),%eax
cmp    $0x32,%eax
jle    11c6 <toString+0xc6>
mov    -0x1(%rbp),%al
add    $0xce,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11c1 <toString+0xc1>
mov    -0x18(%rbp),%rax
lea    0xebb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec9(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <toString+0xc1>
lea    0xec4(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <toString+0xc1>
lea    0xebf(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <toString+0xc1>
lea    0xebc(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <toString+0xc1>
lea    0xeb9(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <toString+0xc1>
lea    0xeb5(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1250 <toString+0x150>
movsbl -0x1(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     124b <toString+0x14b>
mov    -0x20(%rbp),%rax
lea    0xe19(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe86(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    124b <toString+0x14b>
lea    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    124b <toString+0x14b>
lea    0xe7c(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    124b <toString+0x14b>
lea    0xe79(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    124b <toString+0x14b>
lea    0xe76(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    124b <toString+0x14b>
lea    0xe72(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1250 <toString+0x150>
jmp    1255 <toString+0x155>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<toString>:
test   %dil,%dil
je     111f <toString+0x1f>
cmp    $0x33,%dil
jl     1127 <toString+0x27>
lea    -0x34(%rdi),%eax
cmp    $0x5,%al
jae    1141 <toString+0x41>
movsbq %al,%rax
lea    0x2ce3(%rip),%rcx
jmp    1139 <toString+0x39>
lea    0xeda(%rip),%rax
ret
add    $0xfffffffe,%edi
cmp    $0x5,%edi
jae    1149 <toString+0x49>
movslq %edi,%rax
lea    0x2cef(%rip),%rcx
lea    (%rcx,%rax,8),%rax
mov    (%rax),%rax
ret
lea    0xebe(%rip),%rax
ret
lea    0xefd(%rip),%rax
ret

LLVM IR (-O0):
@.str = [6 x i8] c"EMPTY\00"
@.str.1 = [11 x i8] c"BLACK PAWN\00"
@.str.2 = [11 x i8] c"BLACK ROOK\00"
@.str.3 = [13 x i8] c"BLACK KNIGHT\00"
@.str.4 = [13 x i8] c"BLACK BISHOP\00"
@.str.5 = [12 x i8] c"BLACK QUEEN\00"
@.str.6 = [11 x i8] c"BLACK KING\00"
@.str.7 = [11 x i8] c"WHITE PAWN\00"
@.str.8 = [11 x i8] c"WHITE ROOK\00"
@.str.9 = [13 x i8] c"WHITE KNIGHT\00"
@.str.10 = [13 x i8] c"WHITE BISHOP\00"
@.str.11 = [12 x i8] c"WHITE QUEEN\00"
@.str.12 = [11 x i8] c"WHITE KING\00"
define i8* @toString(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8*
store i8 %0, i8* %2
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %3
br label %37
8: ; preds = %1
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp sgt i32 %10, 50
br i1 %11, label %12, label %26
12: ; preds = %8
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = sub nsw i32 %14, 50
%16 = trunc i32 %15 to i8
store i8 %16, i8* %2
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
switch i32 %18, label %25 [
i32 1, label %19
i32 2, label %20
i32 3, label %21
i32 4, label %22
i32 5, label %23
i32 6, label %24
]
19: ; preds = %12
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %25
20: ; preds = %12
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %25
21: ; preds = %12
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %25
22: ; preds = %12
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %25
23: ; preds = %12
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %25
24: ; preds = %12
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %25
25: ; preds = %12, %24, %23, %22, %21, %20, %19
br label %36
26: ; preds = %8
%27 = load i8, i8* %2
%28 = sext i8 %27 to i32
switch i32 %28, label %35 [
i32 1, label %29
i32 2, label %30
i32 3, label %31
i32 4, label %32
i32 5, label %33
i32 6, label %34
]
29: ; preds = %26
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8** %3
br label %35
30: ; preds = %26
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8** %3
br label %35
31: ; preds = %26
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8** %3
br label %35
32: ; preds = %26
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8** %3
br label %35
33: ; preds = %26
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8** %3
br label %35
34: ; preds = %26
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8** %3
br label %35
35: ; preds = %26, %34, %33, %32, %31, %30, %29
br label %36
36: ; preds = %35, %25
br label %37
37: ; preds = %36, %7
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@.str = [6 x i8] c"EMPTY\00"
@.str.1 = [11 x i8] c"BLACK PAWN\00"
@.str.2 = [11 x i8] c"BLACK ROOK\00"
@.str.3 = [13 x i8] c"BLACK KNIGHT\00"
@.str.4 = [13 x i8] c"BLACK BISHOP\00"
@.str.5 = [12 x i8] c"BLACK QUEEN\00"
@.str.6 = [11 x i8] c"BLACK KING\00"
@.str.7 = [11 x i8] c"WHITE PAWN\00"
@.str.8 = [11 x i8] c"WHITE ROOK\00"
@.str.9 = [13 x i8] c"WHITE KNIGHT\00"
@.str.10 = [13 x i8] c"WHITE BISHOP\00"
@.str.11 = [12 x i8] c"WHITE QUEEN\00"
@.str.12 = [11 x i8] c"WHITE KING\00"
@switch.table.toString = [5 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0)]
@switch.table.toString.13 = [5 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0)]
define i8* @toString(i8 signext %0) {
%2 = sext i8 %0 to i32
%3 = icmp eq i8 %0, 0
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = icmp sgt i8 %0, 50
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = add i8 %0, -52
%8 = icmp ult i8 %7, 5
br i1 %8, label %12, label %21
9: ; preds = %4
%10 = add nsw i32 %2, -2
%11 = icmp ult i32 %10, 5
br i1 %11, label %15, label %21
12: ; preds = %6
%13 = sext i8 %7 to i64
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* @switch.table.toString, i64 0, i64 %13
br label %18
15: ; preds = %9
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* @switch.table.toString.13, i64 0, i64 %16
br label %18
18: ; preds = %12, %15
%19 = phi i8** [ %17, %15 ], [ %14, %12 ]
%20 = load i8*, i8** %19
br label %21
21: ; preds = %18, %9, %6, %1
%22 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), %9 ], [ %20, %18 ]
ret i8* %22
}