#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 */

/* Variables and functions */
scalar_t__ is_bishop(char);
scalar_t__ is_king(char);
scalar_t__ is_knight(char);
scalar_t__ is_pawn(char);
scalar_t__ is_queen(char);
scalar_t__ is_rook(char);
char get_chesspiece(char p) {
  if (is_king(p))
    return (1 << 5);
  if (is_queen(p))
    return (1 << 4);
  if (is_rook(p))
    return (1 << 3);
  if (is_bishop(p))
    return (1 << 2);
  if (is_knight(p))
    return (1 << 1);
  if (is_pawn(p))
    return (1 << 0);
  return (-1);
}


x86 assembly (clang, -O0):
<get_chesspiece>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%edi
call   1030 <is_king@plt>
cmp    $0x0,%rax
je     118a <get_chesspiece+0x2a>
movb   $0x20,-0x1(%rbp)
jmp    121a <get_chesspiece+0xba>
movsbl -0x2(%rbp),%edi
call   1040 <is_queen@plt>
cmp    $0x0,%rax
je     11a6 <get_chesspiece+0x46>
movb   $0x10,-0x1(%rbp)
jmp    121a <get_chesspiece+0xba>
movsbl -0x2(%rbp),%edi
call   1060 <is_rook@plt>
cmp    $0x0,%rax
je     11c2 <get_chesspiece+0x62>
movb   $0x8,-0x1(%rbp)
jmp    121a <get_chesspiece+0xba>
movsbl -0x2(%rbp),%edi
call   1070 <is_bishop@plt>
cmp    $0x0,%rax
je     11de <get_chesspiece+0x7e>
movb   $0x4,-0x1(%rbp)
jmp    121a <get_chesspiece+0xba>
movsbl -0x2(%rbp),%edi
call   1080 <is_knight@plt>
cmp    $0x0,%rax
je     11fa <get_chesspiece+0x9a>
movb   $0x2,-0x1(%rbp)
jmp    121a <get_chesspiece+0xba>
movsbl -0x2(%rbp),%edi
call   1050 <is_pawn@plt>
cmp    $0x0,%rax
je     1216 <get_chesspiece+0xb6>
movb   $0x1,-0x1(%rbp)
jmp    121a <get_chesspiece+0xba>
movb   $0xff,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_chesspiece>:
push   %rbx
mov    %edi,%ebx
call   1030 <is_king@plt>
mov    %rax,%rcx
mov    $0x20,%al
test   %rcx,%rcx
je     1174 <get_chesspiece+0x14>
pop    %rbx
ret
movsbl %bl,%ebx
mov    %ebx,%edi
call   1040 <is_queen@plt>
mov    %rax,%rcx
mov    $0x10,%al
test   %rcx,%rcx
jne    1172 <get_chesspiece+0x12>
mov    %ebx,%edi
call   1060 <is_rook@plt>
mov    %rax,%rcx
mov    $0x8,%al
test   %rcx,%rcx
jne    1172 <get_chesspiece+0x12>
mov    %ebx,%edi
call   1070 <is_bishop@plt>
mov    %rax,%rcx
mov    $0x4,%al
test   %rcx,%rcx
jne    1172 <get_chesspiece+0x12>
mov    %ebx,%edi
call   1080 <is_knight@plt>
mov    %rax,%rcx
mov    $0x2,%al
test   %rcx,%rcx
jne    1172 <get_chesspiece+0x12>
mov    %ebx,%edi
call   1050 <is_pawn@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     $0x1,%al
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @get_chesspiece(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = call i64 @is_king(i8 signext %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i8 32, i8* %2
br label %34
8: ; preds = %1
%9 = load i8, i8* %3
%10 = call i64 @is_queen(i8 signext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i8 16, i8* %2
br label %34
13: ; preds = %8
%14 = load i8, i8* %3
%15 = call i64 @is_rook(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i8 8, i8* %2
br label %34
18: ; preds = %13
%19 = load i8, i8* %3
%20 = call i64 @is_bishop(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i8 4, i8* %2
br label %34
23: ; preds = %18
%24 = load i8, i8* %3
%25 = call i64 @is_knight(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i8 2, i8* %2
br label %34
28: ; preds = %23
%29 = load i8, i8* %3
%30 = call i64 @is_pawn(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i8 1, i8* %2
br label %34
33: ; preds = %28
store i8 -1, i8* %2
br label %34
34: ; preds = %33, %32, %27, %22, %17, %12, %7
%35 = load i8, i8* %2
ret i8 %35
}

LLVM IR (-O2):
define signext i8 @get_chesspiece(i8 signext %0) {
%2 = tail call i64 @is_king(i8 signext %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = tail call i64 @is_queen(i8 signext %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = tail call i64 @is_rook(i8 signext %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = tail call i64 @is_bishop(i8 signext %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = tail call i64 @is_knight(i8 signext %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = tail call i64 @is_pawn(i8 signext %0)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8 -1, i8 1
br label %20
20: ; preds = %16, %13, %10, %7, %4, %1
%21 = phi i8 [ 32, %1 ], [ 16, %4 ], [ 8, %7 ], [ 4, %10 ], [ 2, %13 ], [ %19, %16 ]
ret i8 %21
}