#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 check_valid_move_pawn(int, int, int, int, int, int **);
int /*<<< orphan*/ get_piece(int, int, int **);
int get_piece_color(int /*<<< orphan*/);
char get_piece_type(int /*<<< orphan*/);
int is_piece_move_legal(int x1, int y1, int x2, int y2, int **board) {
  char thisPieceType = get_piece_type(get_piece(x1, y1, board));
  int thisPieceColor = get_piece_color(get_piece(x1, y1, board));
  int isLegal = 0;
  switch (thisPieceType) {
  case 'P':
    isLegal = check_valid_move_pawn(x1, y1, x2, y2, thisPieceColor, board);
    break;
  case 'N':
    isLegal = 0;
  }
  return isLegal;
}


x86 assembly (clang, -O0):
<is_piece_move_legal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <get_piece@plt>
mov    %eax,%edi
call   1030 <get_piece_type@plt>
mov    %al,-0x19(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <get_piece@plt>
mov    %eax,%edi
call   1060 <get_piece_color@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x4e,%eax
je     11d8 <is_piece_move_legal+0x98>
jmp    11a6 <is_piece_move_legal+0x66>
mov    -0x28(%rbp),%eax
sub    $0x50,%eax
jne    11df <is_piece_move_legal+0x9f>
jmp    11b7 <is_piece_move_legal+0x77>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x18(%rbp),%r9
call   1040 <check_valid_move_pawn@plt>
mov    %eax,-0x24(%rbp)
jmp    11df <is_piece_move_legal+0x9f>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_piece_move_legal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%ebx
mov    %r8,%rdx
call   1050 <get_piece@plt>
mov    %eax,%edi
call   1030 <get_piece_type@plt>
mov    %eax,%r13d
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r12,%rdx
call   1050 <get_piece@plt>
mov    %eax,%edi
call   1060 <get_piece_color@plt>
cmp    $0x50,%r13b
jne    11a6 <is_piece_move_legal+0x66>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    %eax,%r8d
mov    %r12,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <check_valid_move_pawn@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_piece_move_legal(i32 %0, i32 %1, i32 %2, i32 %3, i32** %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32**
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32** %4, i32*** %10
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = load i32**, i32*** %10
%17 = call i32 @get_piece(i32 %14, i32 %15, i32** %16)
%18 = call signext i8 @get_piece_type(i32 %17)
store i8 %18, i8* %11
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = load i32**, i32*** %10
%22 = call i32 @get_piece(i32 %19, i32 %20, i32** %21)
%23 = call i32 @get_piece_color(i32 %22)
store i32 %23, i32* %12
store i32 0, i32* %13
%24 = load i8, i8* %11
%25 = sext i8 %24 to i32
switch i32 %25, label %35 [
i32 80, label %26
i32 78, label %34
]
26: ; preds = %5
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = load i32, i32* %12
%32 = load i32**, i32*** %10
%33 = call i32 @check_valid_move_pawn(i32 %27, i32 %28, i32 %29, i32 %30, i32 %31, i32** %32)
store i32 %33, i32* %13
br label %35
34: ; preds = %5
store i32 0, i32* %13
br label %35
35: ; preds = %34, %5, %26
%36 = load i32, i32* %13
ret i32 %36
}

LLVM IR (-O2):
define i32 @is_piece_move_legal(i32 %0, i32 %1, i32 %2, i32 %3, i32** %4) {
%6 = tail call i32 @get_piece(i32 %0, i32 %1, i32** %4)
%7 = tail call signext i8 @get_piece_type(i32 %6)
%8 = tail call i32 @get_piece(i32 %0, i32 %1, i32** %4)
%9 = tail call i32 @get_piece_color(i32 %8)
%10 = icmp eq i8 %7, 80
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @check_valid_move_pawn(i32 %0, i32 %1, i32 %2, i32 %3, i32 %9, i32** %4)
br label %13
13: ; preds = %5, %11
%14 = phi i32 [ %12, %11 ], [ 0, %5 ]
ret i32 %14
}