#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 */
scalar_t__ isPermissible(int **, int, int);
int /*<<< orphan*/ printBoard(int **);
void knightTourHelper(int board[8][8], int row, int col, int knight) {
  if (knight == 8 * 8 + 1) {
    printBoard(board);
    return;
  }
  int motion[8][2] = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2},
                      {1, -2},  {1, 2},  {2, -1},  {2, 1}};
  int drow, dcol;
  int i;
  for (i = 0; i < 8; i++) {
    drow = motion[i][0];
    dcol = motion[i][1];
    if (isPermissible(board, row + drow, col + dcol)) {
      board[row + drow][col + dcol] = knight;
      knightTourHelper(board, row + drow, col + dcol, knight + 1);
      board[row + drow][col + dcol] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<knightTourHelper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpl   $0x41,-0x14(%rbp)
jne    116d <knightTourHelper+0x2d>
mov    -0x8(%rbp),%rdi
call   1030 <printBoard@plt>
jmp    123d <knightTourHelper+0xfd>
lea    -0x60(%rbp),%rdi
lea    0xe88(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x8,-0x6c(%rbp)
jge    123d <knightTourHelper+0xfd>
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%eax
mov    %eax,-0x64(%rbp)
movslq -0x6c(%rbp),%rax
mov    -0x5c(%rbp,%rax,8),%eax
mov    %eax,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    -0x64(%rbp),%esi
mov    -0x10(%rbp),%edx
add    -0x68(%rbp),%edx
call   1060 <isPermissible@plt>
cmp    $0x0,%rax
je     122a <knightTourHelper+0xea>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    -0x64(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x5,%rcx
add    %rcx,%rax
mov    -0x10(%rbp),%ecx
add    -0x68(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    -0x64(%rbp),%esi
mov    -0x10(%rbp),%edx
add    -0x68(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
call   1040 <knightTourHelper@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    -0x64(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x5,%rcx
add    %rcx,%rax
mov    -0x10(%rbp),%ecx
add    -0x68(%rbp),%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    122f <knightTourHelper+0xef>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1189 <knightTourHelper+0x49>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<knightTourHelper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
cmp    $0x41,%ecx
jne    115c <knightTourHelper+0x2c>
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printBoard@plt>
mov    %rcx,0x8(%rsp)
lea    0x1(%rcx),%eax
mov    %eax,0x4(%rsp)
xor    %ebx,%ebx
movslq %esi,%rax
mov    %rax,0x10(%rsp)
movslq %edx,%r15
jmp    118a <knightTourHelper+0x5a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x8,%rbx
je     11e4 <knightTourHelper+0xb4>
lea    0xe6f(%rip),%rax
movslq (%rax,%rbx,8),%r14
add    0x10(%rsp),%r14
movslq 0x4(%rax,%rbx,8),%rbp
add    %r15,%rbp
mov    %r12,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1050 <isPermissible@plt>
test   %rax,%rax
je     1180 <knightTourHelper+0x50>
mov    %r14,%r13
shl    $0x5,%r13
add    %r12,%r13
mov    0x8(%rsp),%rax
mov    %eax,0x0(%r13,%rbp,4)
mov    %r12,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    0x4(%rsp),%ecx
call   1040 <knightTourHelper@plt>
movl   $0x0,0x0(%r13,%rbp,4)
jmp    1180 <knightTourHelper+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.knightTourHelper.motion = [8 x [2 x i32]] [[2 x i32] [i32 -2, i32 -1], [2 x i32] [i32 -2, i32 1], [2 x i32] [i32 -1, i32 -2], [2 x i32] [i32 -1, i32 2], [2 x i32] [i32 1, i32 -2], [2 x i32] [i32 1, i32 2], [2 x i32] [i32 2, i32 -1], [2 x i32] [i32 2, i32 1]]
define void @knightTourHelper([8 x i32]* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [8 x i32]*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [8 x [2 x i32]]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store [8 x i32]* %0, [8 x i32]** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, 65
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load [8 x i32]*, [8 x i32]** %5
%17 = bitcast [8 x i32]* %16 to i32**
%18 = call i32 @printBoard(i32** %17)
br label %82
19: ; preds = %4
%20 = bitcast [8 x [2 x i32]]* %9 to i8*
store i32 0, i32* %12
br label %21
21: ; preds = %79, %19
%22 = load i32, i32* %12
%23 = icmp slt i32 %22, 8
br i1 %23, label %24, label %82
24: ; preds = %21
%25 = load i32, i32* %12
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [8 x [2 x i32]], [8 x [2 x i32]]* %9, i64 0, i64 %26
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %27, i64 0, i64 0
%29 = load i32, i32* %28
store i32 %29, i32* %10
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [8 x [2 x i32]], [8 x [2 x i32]]* %9, i64 0, i64 %31
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %32, i64 0, i64 1
%34 = load i32, i32* %33
store i32 %34, i32* %11
%35 = load [8 x i32]*, [8 x i32]** %5
%36 = bitcast [8 x i32]* %35 to i32**
%37 = load i32, i32* %6
%38 = load i32, i32* %10
%39 = add nsw i32 %37, %38
%40 = load i32, i32* %7
%41 = load i32, i32* %11
%42 = add nsw i32 %40, %41
%43 = call i64 @isPermissible(i32** %36, i32 %39, i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %78
45: ; preds = %24
%46 = load i32, i32* %8
%47 = load [8 x i32]*, [8 x i32]** %5
%48 = load i32, i32* %6
%49 = load i32, i32* %10
%50 = add nsw i32 %48, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [8 x i32], [8 x i32]* %47, i64 %51
%53 = load i32, i32* %7
%54 = load i32, i32* %11
%55 = add nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [8 x i32], [8 x i32]* %52, i64 0, i64 %56
store i32 %46, i32* %57
%58 = load [8 x i32]*, [8 x i32]** %5
%59 = load i32, i32* %6
%60 = load i32, i32* %10
%61 = add nsw i32 %59, %60
%62 = load i32, i32* %7
%63 = load i32, i32* %11
%64 = add nsw i32 %62, %63
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
%67 = load [8 x i32]*, [8 x i32]** %5
%68 = load i32, i32* %6
%69 = load i32, i32* %10
%70 = add nsw i32 %68, %69
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [8 x i32], [8 x i32]* %67, i64 %71
%73 = load i32, i32* %7
%74 = load i32, i32* %11
%75 = add nsw i32 %73, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [8 x i32], [8 x i32]* %72, i64 0, i64 %76
store i32 0, i32* %77
br label %78
78: ; preds = %45, %24
br label %79
79: ; preds = %78
%80 = load i32, i32* %12
%81 = add nsw i32 %80, 1
store i32 %81, i32* %12
br label %21
82: ; preds = %15, %21
ret void
}

LLVM IR (-O2):
@__const.knightTourHelper.motion = [8 x [2 x i32]] [[2 x i32] [i32 -2, i32 -1], [2 x i32] [i32 -2, i32 1], [2 x i32] [i32 -1, i32 -2], [2 x i32] [i32 -1, i32 2], [2 x i32] [i32 1, i32 -2], [2 x i32] [i32 1, i32 2], [2 x i32] [i32 2, i32 -1], [2 x i32] [i32 2, i32 1]]
define void @knightTourHelper([8 x i32]* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 65
%6 = bitcast [8 x i32]* %0 to i32**
br i1 %5, label %9, label %7
7: ; preds = %4
%8 = add nsw i32 %3, 1
br label %11
9: ; preds = %4
%10 = tail call i32 @printBoard(i32** %6)
br label %28
11: ; preds = %7, %25
%12 = phi i64 [ 0, %7 ], [ %26, %25 ]
%13 = getelementptr inbounds [8 x [2 x i32]], [8 x [2 x i32]]* @__const.knightTourHelper.motion, i64 0, i64 %12, i64 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds [8 x [2 x i32]], [8 x [2 x i32]]* @__const.knightTourHelper.motion, i64 0, i64 %12, i64 1
%16 = load i32, i32* %15
%17 = add nsw i32 %14, %1
%18 = add nsw i32 %16, %2
%19 = tail call i64 @isPermissible(i32** %6, i32 %17, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %11
%22 = sext i32 %17 to i64
%23 = sext i32 %18 to i64
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %0, i64 %22, i64 %23
store i32 %3, i32* %24
tail call void @knightTourHelper([8 x i32]* %0, i32 %17, i32 %18, i32 %8)
store i32 0, i32* %24
br label %25
25: ; preds = %11, %21
%26 = add nuw nsw i64 %12, 1
%27 = icmp eq i64 %26, 8
br i1 %27, label %28, label %11
28: ; preds = %25, %9
ret void
}