#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 getCellIdAbove(int);
int getCellIdBelow(int);
int getCellIdLeft(int);
int getCellIdRight(int);
int /*<<< orphan*/ isOnQueenRoute(int, int);
int isKingLockedByQueen(int kingCellId, int queenCellId) {
  int kingNeighborId[4];
  int numCanMove = 0, index;
  kingNeighborId[0] = getCellIdLeft(kingCellId);
  kingNeighborId[1] = getCellIdRight(kingCellId);
  kingNeighborId[2] = getCellIdAbove(kingCellId);
  kingNeighborId[3] = getCellIdBelow(kingCellId);
  for (index = 0; index < 4; index++)
    if (kingNeighborId[index] >= 0 &&
        !isOnQueenRoute(kingNeighborId[index], queenCellId))
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<isKingLockedByQueen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <getCellIdLeft@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <getCellIdRight@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <getCellIdAbove@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <getCellIdBelow@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11e9 <isKingLockedByQueen+0x99>
movslq -0x28(%rbp),%rax
cmpl   $0x0,-0x20(%rbp,%rax,4)
jl     11d6 <isKingLockedByQueen+0x86>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
mov    -0xc(%rbp),%esi
call   1070 <isOnQueenRoute@plt>
cmp    $0x0,%eax
jne    11d6 <isKingLockedByQueen+0x86>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <isKingLockedByQueen+0xa0>
jmp    11db <isKingLockedByQueen+0x8b>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1198 <isKingLockedByQueen+0x48>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isKingLockedByQueen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebx
call   1030 <getCellIdLeft@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <getCellIdRight@plt>
mov    %eax,%r13d
mov    %ebx,%edi
call   1060 <getCellIdAbove@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1040 <getCellIdBelow@plt>
mov    %eax,%r14d
test   %ebp,%ebp
js     1197 <isKingLockedByQueen+0x47>
mov    %ebp,%edi
mov    %r15d,%esi
call   1070 <isOnQueenRoute@plt>
test   %eax,%eax
je     11da <isKingLockedByQueen+0x8a>
test   %r13d,%r13d
js     11ab <isKingLockedByQueen+0x5b>
mov    %r13d,%edi
mov    %r15d,%esi
call   1070 <isOnQueenRoute@plt>
test   %eax,%eax
je     11da <isKingLockedByQueen+0x8a>
test   %r12d,%r12d
js     11bf <isKingLockedByQueen+0x6f>
mov    %r12d,%edi
mov    %r15d,%esi
call   1070 <isOnQueenRoute@plt>
test   %eax,%eax
je     11da <isKingLockedByQueen+0x8a>
test   %r14d,%r14d
js     11d3 <isKingLockedByQueen+0x83>
mov    %r14d,%edi
mov    %r15d,%esi
call   1070 <isOnQueenRoute@plt>
test   %eax,%eax
je     11da <isKingLockedByQueen+0x8a>
mov    $0x1,%eax
jmp    11dc <isKingLockedByQueen+0x8c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isKingLockedByQueen(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = call i32 @getCellIdLeft(i32 %9)
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
store i32 %10, i32* %11
%12 = load i32, i32* %4
%13 = call i32 @getCellIdRight(i32 %12)
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 1
store i32 %13, i32* %14
%15 = load i32, i32* %4
%16 = call i32 @getCellIdAbove(i32 %15)
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 2
store i32 %16, i32* %17
%18 = load i32, i32* %4
%19 = call i32 @getCellIdBelow(i32 %18)
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 3
store i32 %19, i32* %20
store i32 0, i32* %8
br label %21
21: ; preds = %40, %2
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %43
24: ; preds = %21
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %24
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %5
%36 = call i32 @isOnQueenRoute(i32 %34, i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %30
store i32 0, i32* %3
br label %44
39: ; preds = %30, %24
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %21
43: ; preds = %21
store i32 1, i32* %3
br label %44
44: ; preds = %43, %38
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @isKingLockedByQueen(i32 %0, i32 %1) {
%3 = tail call i32 @getCellIdLeft(i32 %0)
%4 = tail call i32 @getCellIdRight(i32 %0)
%5 = tail call i32 @getCellIdAbove(i32 %0)
%6 = tail call i32 @getCellIdBelow(i32 %0)
%7 = icmp sgt i32 %3, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @isOnQueenRoute(i32 %3, i32 %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %27, label %11
11: ; preds = %2, %8
%12 = icmp sgt i32 %4, -1
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = tail call i32 @isOnQueenRoute(i32 %4, i32 %1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13, %11
%17 = icmp sgt i32 %5, -1
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = tail call i32 @isOnQueenRoute(i32 %5, i32 %1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %18, %16
%22 = icmp sgt i32 %6, -1
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = tail call i32 @isOnQueenRoute(i32 %6, i32 %1)
%25 = icmp eq i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %23, %21
br label %27
27: ; preds = %26, %23, %18, %13, %8
%28 = phi i32 [ 0, %8 ], [ 0, %13 ], [ 0, %18 ], [ 0, %23 ], [ 1, %26 ]
ret i32 %28
}