#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 */
int /*<<< orphan*/ Current_Turn();
int Get_First_Coordinate();
int Get_Second_Coordinate();
scalar_t__ Get_Total_Legal_Moves_For_Piece(char ***, char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sameSide(char, int /*<<< orphan*/);
int getPieceFromCoordinates(char grid[8][8][33], char pieceTranslator[33]) {
  int x, y;
  do {
    printf("Please enter a pair of coordinates: ");
    while (x = Get_First_Coordinate(), y = Get_Second_Coordinate(),
           !sameSide(pieceTranslator[(int)grid[x][y][0]], Current_Turn()))
      printf("\nYou may only move your pieces.\n");
  } while (Get_Total_Legal_Moves_For_Piece(grid, grid[x][y][0]) == 0);
  return grid[x][y][0];
}


x86 assembly (clang, -O0):
<getPieceFromCoordinates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <Get_First_Coordinate@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1080 <Get_Second_Coordinate@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
imul   $0x108,%rdx,%rdx
add    %rdx,%rcx
movslq -0x18(%rbp),%rdx
imul   $0x21,%rdx,%rdx
add    %rdx,%rcx
movsbl (%rcx),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    $0x0,%al
call   1050 <Current_Turn@plt>
mov    %eax,%esi
mov    -0x19(%rbp),%al
movsbl %al,%edi
call   1040 <sameSide@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e6 <getPieceFromCoordinates+0x86>
jmp    11f7 <getPieceFromCoordinates+0x97>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
jmp    117c <getPieceFromCoordinates+0x1c>
jmp    11fc <getPieceFromCoordinates+0x9c>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x108,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
imul   $0x21,%rcx,%rcx
add    %rcx,%rax
movsbl (%rax),%esi
call   1060 <Get_Total_Legal_Moves_For_Piece@plt>
cmp    $0x0,%rax
je     1170 <getPieceFromCoordinates+0x10>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x108,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
imul   $0x21,%rcx,%rcx
add    %rcx,%rax
movsbl (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPieceFromCoordinates>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xe9d(%rip),%r12
jmp    11a7 <getPieceFromCoordinates+0x37>
nopw   0x0(%rax,%rax,1)
add    %r15,%rbx
movsbl (%rbx),%esi
mov    %r13,%rdi
call   1070 <Get_Total_Legal_Moves_For_Piece@plt>
test   %rax,%rax
jne    125c <getPieceFromCoordinates+0xec>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <Get_First_Coordinate@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <Get_Second_Coordinate@plt>
movslq %ebp,%rcx
cltq
mov    %rcx,%rdx
shl    $0x8,%rdx
lea    (%rdx,%rcx,8),%rbx
add    %r13,%rbx
mov    %rax,%r15
shl    $0x5,%r15
add    %rax,%r15
movsbq (%rbx,%r15,1),%rax
movsbl (%r14,%rax,1),%ebp
xor    %eax,%eax
call   1060 <Current_Turn@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <sameSide@plt>
test   %eax,%eax
jne    1190 <getPieceFromCoordinates+0x20>
xchg   %ax,%ax
mov    %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <Get_First_Coordinate@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <Get_Second_Coordinate@plt>
movslq %ebp,%rcx
cltq
mov    %rcx,%rdx
shl    $0x8,%rdx
lea    (%rdx,%rcx,8),%rbx
add    %r13,%rbx
mov    %rax,%rbp
shl    $0x5,%rbp
add    %rax,%rbp
movsbq (%rbx,%rbp,1),%rax
movsbl (%r14,%rax,1),%r15d
xor    %eax,%eax
call   1060 <Current_Turn@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1050 <sameSide@plt>
test   %eax,%eax
je     1200 <getPieceFromCoordinates+0x90>
add    %rbp,%rbx
jmp    1193 <getPieceFromCoordinates+0x23>
movsbl (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Please enter a pair of coordinates: \00"
@.str.1 = [33 x i8] c"\0AYou may only move your pieces.\0A\00"
define i32 @getPieceFromCoordinates([8 x [33 x i8]]* %0, i8* %1) {
%3 = alloca [8 x [33 x i8]]*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store [8 x [33 x i8]]* %0, [8 x [33 x i8]]** %3
store i8* %1, i8** %4
br label %7
7: ; preds = %33, %2
%8 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %30, %7
%10 = call i32 (...) @Get_First_Coordinate()
store i32 %10, i32* %5
%11 = call i32 (...) @Get_Second_Coordinate()
store i32 %11, i32* %6
%12 = load i8*, i8** %4
%13 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %13, i64 %15
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %16, i64 0, i64 %18
%20 = getelementptr inbounds [33 x i8], [33 x i8]* %19, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %12, i64 %23
%25 = load i8, i8* %24
%26 = call i32 (...) @Current_Turn()
%27 = call i32 @sameSide(i8 signext %25, i32 %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %32
30: ; preds = %9
%31 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %9
32: ; preds = %9
br label %33
33: ; preds = %32
%34 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%35 = bitcast [8 x [33 x i8]]* %34 to i8***
%36 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %36, i64 %38
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %39, i64 0, i64 %41
%43 = getelementptr inbounds [33 x i8], [33 x i8]* %42, i64 0, i64 0
%44 = load i8, i8* %43
%45 = call i64 @Get_Total_Legal_Moves_For_Piece(i8*** %35, i8 signext %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %7, label %47
47: ; preds = %33
%48 = load [8 x [33 x i8]]*, [8 x [33 x i8]]** %3
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %48, i64 %50
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %51, i64 0, i64 %53
%55 = getelementptr inbounds [33 x i8], [33 x i8]* %54, i64 0, i64 0
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
ret i32 %57
}

LLVM IR (-O2):
@.str = [37 x i8] c"Please enter a pair of coordinates: \00"
@str = [32 x i8] c"\0AYou may only move your pieces.\00"
define i32 @getPieceFromCoordinates([8 x [33 x i8]]* %0, i8* nocapture %1) {
%3 = bitcast [8 x [33 x i8]]* %0 to i8***
br label %4
4: ; preds = %32, %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @Get_First_Coordinate()
%7 = tail call i32 (...) @Get_Second_Coordinate()
%8 = sext i32 %6 to i64
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %0, i64 %8, i64 %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 (...) @Current_Turn()
%16 = tail call i32 @sameSide(i8 signext %14, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %4, %18
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 (...) @Get_First_Coordinate()
%21 = tail call i32 (...) @Get_Second_Coordinate()
%22 = sext i32 %20 to i64
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds [8 x [33 x i8]], [8 x [33 x i8]]* %0, i64 %22, i64 %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i64
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = load i8, i8* %27
%29 = tail call i32 (...) @Current_Turn()
%30 = tail call i32 @sameSide(i8 signext %28, i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %18, label %32
32: ; preds = %18, %4
%33 = phi i8* [ %10, %4 ], [ %24, %18 ]
%34 = load i8, i8* %33
%35 = tail call i64 @Get_Total_Legal_Moves_For_Piece(i8*** %3, i8 signext %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %4, label %37
37: ; preds = %32
%38 = load i8, i8* %33
%39 = sext i8 %38 to i32
ret i32 %39
}