#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
scalar_t__ is_bishop(char);
scalar_t__ is_black(char);
scalar_t__ is_free(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);
void print_chesspiece(char p, FILE *f) {
  char output, black;
  output = '?';
  if (is_black(p))
    black = 1;
  else
    black = 0;
  if (is_king(p))
    output = 'K';
  if (is_queen(p))
    output = 'Q';
  if (is_rook(p))
    output = 'R';
  if (is_bishop(p))
    output = 'B';
  if (is_knight(p))
    output = 'N';
  if (is_pawn(p))
    output = 'P';
  if (black)
    output += 'a' - 'A';
  if (is_free(p))
    output = ' ';
  fprintf(f, "%c", output);
}


x86 assembly (clang, -O0):
<print_chesspiece>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x3f,-0x11(%rbp)
movsbl -0x1(%rbp),%edi
call   1090 <is_black@plt>
cmp    $0x0,%rax
je     11c2 <print_chesspiece+0x32>
movb   $0x1,-0x12(%rbp)
jmp    11c6 <print_chesspiece+0x36>
movb   $0x0,-0x12(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <is_king@plt>
cmp    $0x0,%rax
je     11dd <print_chesspiece+0x4d>
movb   $0x4b,-0x11(%rbp)
movsbl -0x1(%rbp),%edi
call   1040 <is_queen@plt>
cmp    $0x0,%rax
je     11f4 <print_chesspiece+0x64>
movb   $0x51,-0x11(%rbp)
movsbl -0x1(%rbp),%edi
call   1060 <is_rook@plt>
cmp    $0x0,%rax
je     120b <print_chesspiece+0x7b>
movb   $0x52,-0x11(%rbp)
movsbl -0x1(%rbp),%edi
call   1070 <is_bishop@plt>
cmp    $0x0,%rax
je     1222 <print_chesspiece+0x92>
movb   $0x42,-0x11(%rbp)
movsbl -0x1(%rbp),%edi
call   10b0 <is_knight@plt>
cmp    $0x0,%rax
je     1239 <print_chesspiece+0xa9>
movb   $0x4e,-0x11(%rbp)
movsbl -0x1(%rbp),%edi
call   1050 <is_pawn@plt>
cmp    $0x0,%rax
je     1250 <print_chesspiece+0xc0>
movb   $0x50,-0x11(%rbp)
cmpb   $0x0,-0x12(%rbp)
je     1264 <print_chesspiece+0xd4>
movsbl -0x11(%rbp),%eax
add    $0x20,%eax
mov    %al,-0x11(%rbp)
movsbl -0x1(%rbp),%edi
call   10a0 <is_free@plt>
cmp    $0x0,%rax
je     127b <print_chesspiece+0xeb>
movb   $0x20,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd7a(%rip),%rsi
movsbl -0x11(%rbp),%edx
call   1080 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_chesspiece>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r12d
call   1090 <is_black@plt>
mov    %rax,%r15
mov    %r12d,%edi
call   1030 <is_king@plt>
test   %rax,%rax
mov    $0x3f,%eax
mov    $0x4b,%ebx
cmove  %eax,%ebx
mov    %r12d,%edi
call   1040 <is_queen@plt>
test   %rax,%rax
mov    $0x51,%ebp
cmove  %ebx,%ebp
mov    %r12d,%edi
call   1060 <is_rook@plt>
test   %rax,%rax
mov    $0x52,%ebx
cmove  %ebp,%ebx
mov    %r12d,%edi
call   1080 <is_bishop@plt>
test   %rax,%rax
mov    $0x42,%ebp
cmove  %ebx,%ebp
mov    %r12d,%edi
call   10b0 <is_knight@plt>
test   %rax,%rax
mov    $0x4e,%ebx
cmove  %ebp,%ebx
mov    %r12d,%edi
call   1050 <is_pawn@plt>
test   %rax,%rax
mov    $0x50,%eax
cmove  %ebx,%eax
lea    0x20(%rax),%ecx
test   %r15,%r15
movzbl %cl,%ebx
cmove  %eax,%ebx
mov    %r12d,%edi
call   10a0 <is_free@plt>
test   %rax,%rax
movzbl %bl,%eax
mov    $0x20,%edi
cmove  %eax,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fputc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @print_chesspiece(i8 signext %0, i32* %1) {
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i8
store i8 %0, i8* %3
store i32* %1, i32** %4
store i8 63, i8* %5
%7 = load i8, i8* %3
%8 = call i64 @is_black(i8 signext %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i8 1, i8* %6
br label %12
11: ; preds = %2
store i8 0, i8* %6
br label %12
12: ; preds = %11, %10
%13 = load i8, i8* %3
%14 = call i64 @is_king(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i8 75, i8* %5
br label %17
17: ; preds = %16, %12
%18 = load i8, i8* %3
%19 = call i64 @is_queen(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i8 81, i8* %5
br label %22
22: ; preds = %21, %17
%23 = load i8, i8* %3
%24 = call i64 @is_rook(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i8 82, i8* %5
br label %27
27: ; preds = %26, %22
%28 = load i8, i8* %3
%29 = call i64 @is_bishop(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i8 66, i8* %5
br label %32
32: ; preds = %31, %27
%33 = load i8, i8* %3
%34 = call i64 @is_knight(i8 signext %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
store i8 78, i8* %5
br label %37
37: ; preds = %36, %32
%38 = load i8, i8* %3
%39 = call i64 @is_pawn(i8 signext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i8 80, i8* %5
br label %42
42: ; preds = %41, %37
%43 = load i8, i8* %6
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i8, i8* %5
%47 = sext i8 %46 to i32
%48 = add nsw i32 %47, 32
%49 = trunc i32 %48 to i8
store i8 %49, i8* %5
br label %50
50: ; preds = %45, %42
%51 = load i8, i8* %3
%52 = call i64 @is_free(i8 signext %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %50
store i8 32, i8* %5
br label %55
55: ; preds = %54, %50
%56 = load i32*, i32** %4
%57 = load i8, i8* %5
%58 = call i32 @fprintf(i32* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %57)
ret void
}

LLVM IR (-O2):
define void @print_chesspiece(i8 signext %0, i32* nocapture %1) {
%3 = tail call i64 @is_black(i8 signext %0)
%4 = icmp eq i64 %3, 0
%5 = tail call i64 @is_king(i8 signext %0)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8 63, i8 75
%8 = tail call i64 @is_queen(i8 signext %0)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8 %7, i8 81
%11 = tail call i64 @is_rook(i8 signext %0)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8 %10, i8 82
%14 = tail call i64 @is_bishop(i8 signext %0)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8 %13, i8 66
%17 = tail call i64 @is_knight(i8 signext %0)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8 %16, i8 78
%20 = tail call i64 @is_pawn(i8 signext %0)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i8 %19, i8 80
%23 = add nuw nsw i8 %22, 32
%24 = select i1 %4, i8 %22, i8 %23
%25 = tail call i64 @is_free(i8 signext %0)
%26 = icmp eq i64 %25, 0
%27 = zext i8 %24 to i32
%28 = select i1 %26, i32 %27, i32 32
%29 = tail call i32 @fputc(i32 %28, i32* %1)
ret void
}