#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 */
char KingFromPieceColor(unsigned char);
char NextPieceFromVector(unsigned long, unsigned long, int, int);
int PlayRook(unsigned char pieceColor, unsigned long boardRow,
             unsigned long boardCol) {
  char targetKing = KingFromPieceColor(pieceColor);
  char king1 = NextPieceFromVector(boardRow, boardCol, -1, 0);
  char king2 = NextPieceFromVector(boardRow, boardCol, 1, 0);
  char king3 = NextPieceFromVector(boardRow, boardCol, 0, -1);
  char king4 = NextPieceFromVector(boardRow, boardCol, 0, 1);
  if (king1 == targetKing || king2 == targetKing || king3 == targetKing ||
      king4 == targetKing) {
    return pieceColor;
  }
  return 0;
}


x86 assembly (clang, -O0):
<PlayRook>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movzbl -0x5(%rbp),%edi
call   1030 <KingFromPieceColor@plt>
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1040 <NextPieceFromVector@plt>
mov    %al,-0x1a(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <NextPieceFromVector@plt>
mov    %al,-0x1b(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
mov    $0xffffffff,%ecx
call   1040 <NextPieceFromVector@plt>
mov    %al,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <NextPieceFromVector@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1a(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
je     11de <PlayRook+0xbe>
movsbl -0x1b(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
je     11de <PlayRook+0xbe>
movsbl -0x1c(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
je     11de <PlayRook+0xbe>
movsbl -0x1d(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    11ea <PlayRook+0xca>
movzbl -0x5(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <PlayRook+0xd1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PlayRook>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%r15d
call   1030 <KingFromPieceColor@plt>
mov    %eax,%r14d
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1040 <NextPieceFromVector@plt>
mov    %al,0x7(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <NextPieceFromVector@plt>
mov    %al,0x6(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
mov    $0xffffffff,%ecx
call   1040 <NextPieceFromVector@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <NextPieceFromVector@plt>
cmp    %r14b,%al
cmove  %r15d,%ebp
cmp    %r14b,%r13b
cmove  %r15d,%ebp
cmp    %r14b,0x6(%rsp)
cmove  %r15d,%ebp
cmp    %r14b,0x7(%rsp)
cmove  %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @PlayRook(i8 zeroext %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
store i8 %0, i8* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%13 = load i8, i8* %5
%14 = call signext i8 @KingFromPieceColor(i8 zeroext %13)
store i8 %14, i8* %8
%15 = load i64, i64* %6
%16 = load i64, i64* %7
%17 = call signext i8 @NextPieceFromVector(i64 %15, i64 %16, i32 -1, i32 0)
store i8 %17, i8* %9
%18 = load i64, i64* %6
%19 = load i64, i64* %7
%20 = call signext i8 @NextPieceFromVector(i64 %18, i64 %19, i32 1, i32 0)
store i8 %20, i8* %10
%21 = load i64, i64* %6
%22 = load i64, i64* %7
%23 = call signext i8 @NextPieceFromVector(i64 %21, i64 %22, i32 0, i32 -1)
store i8 %23, i8* %11
%24 = load i64, i64* %6
%25 = load i64, i64* %7
%26 = call signext i8 @NextPieceFromVector(i64 %24, i64 %25, i32 0, i32 1)
store i8 %26, i8* %12
%27 = load i8, i8* %9
%28 = sext i8 %27 to i32
%29 = load i8, i8* %8
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %28, %30
br i1 %31, label %50, label %32
32: ; preds = %3
%33 = load i8, i8* %10
%34 = sext i8 %33 to i32
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %34, %36
br i1 %37, label %50, label %38
38: ; preds = %32
%39 = load i8, i8* %11
%40 = sext i8 %39 to i32
%41 = load i8, i8* %8
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %40, %42
br i1 %43, label %50, label %44
44: ; preds = %38
%45 = load i8, i8* %12
%46 = sext i8 %45 to i32
%47 = load i8, i8* %8
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %46, %48
br i1 %49, label %50, label %53
50: ; preds = %44, %38, %32, %3
%51 = load i8, i8* %5
%52 = zext i8 %51 to i32
store i32 %52, i32* %4
br label %54
53: ; preds = %44
store i32 0, i32* %4
br label %54
54: ; preds = %53, %50
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
define i32 @PlayRook(i8 zeroext %0, i64 %1, i64 %2) {
%4 = tail call signext i8 @KingFromPieceColor(i8 zeroext %0)
%5 = tail call signext i8 @NextPieceFromVector(i64 %1, i64 %2, i32 -1, i32 0)
%6 = tail call signext i8 @NextPieceFromVector(i64 %1, i64 %2, i32 1, i32 0)
%7 = tail call signext i8 @NextPieceFromVector(i64 %1, i64 %2, i32 0, i32 -1)
%8 = tail call signext i8 @NextPieceFromVector(i64 %1, i64 %2, i32 0, i32 1)
%9 = icmp eq i8 %5, %4
%10 = icmp eq i8 %6, %4
%11 = select i1 %9, i1 true, i1 %10
%12 = icmp eq i8 %7, %4
%13 = select i1 %11, i1 true, i1 %12
%14 = icmp eq i8 %8, %4
%15 = select i1 %13, i1 true, i1 %14
%16 = zext i8 %0 to i32
%17 = select i1 %15, i32 %16, i32 0
ret i32 %17
}