#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ checkBoard(int *, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int *malloc(int);
int nChancellors(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i, j, k, n, s;
  FILE *fp = fopen("input.txt", "r");
  fscanf(fp, " %d", &n);
  for (i = 0; i < n; i++) {
    printf("Solving problem %d:\n", i + 1);
    fscanf(fp, " %d", &s);
    int *board = malloc(sizeof(int) * s);
    int hasConflict = 0;
    for (int j = 0; j < s; j++)
      board[i] = 0;
    for (int j = 0; j < s; j++)
      for (int k = 0; k < s; k++) {
        int tmp;
        fscanf(fp, " %d", &tmp);
        if (tmp > 0)
          if (board[k] == 0)
            board[k] = -(j + 1);
          else
            hasConflict = 1;
      }
    if (checkBoard(board, n) || hasConflict)
      printf("UH OH! There is a conflict in the initial board.\nNumber of "
             "solutions: 0\n\n");
    else
      printf("Number of solutions: %d\n\n", nChancellors(board, s));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7b(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1323 <main+0x1c3>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe40(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    121f <main+0xbf>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11f6 <main+0x96>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12c1 <main+0x161>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12ae <main+0x14e>
mov    -0x20(%rbp),%rdi
lea    0xdbc(%rip),%rsi
lea    -0x3c(%rbp),%rdx
call   1050 <fscanf@plt>
cmpl   $0x0,-0x3c(%rbp)
jle    129b <main+0x13b>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    128f <main+0x12f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
sub    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1296 <main+0x136>
movl   $0x1,-0x2c(%rbp)
jmp    129b <main+0x13b>
jmp    12a0 <main+0x140>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1239 <main+0xd9>
jmp    12b3 <main+0x153>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1226 <main+0xc6>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <checkBoard@plt>
cmp    $0x0,%rax
jne    12e1 <main+0x181>
cmpl   $0x0,-0x2c(%rbp)
je     12f4 <main+0x194>
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1b0>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <nChancellors@plt>
mov    %eax,%esi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1315 <main+0x1b5>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a1 <main+0x41>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
lea    0xe74(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmpl   $0x0,0x10(%rsp)
jle    12ee <main+0x17e>
xor    %ebp,%ebp
jmp    11e2 <main+0x72>
nopw   0x0(%rax,%rax,1)
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
movslq 0x10(%rsp),%rax
mov    0x20(%rsp),%rcx
mov    %rcx,%rbp
cmp    %rax,%rcx
jge    12ee <main+0x17e>
lea    0x1(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    %rsi,0x20(%rsp)
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
lea    0xe09(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%r15d
lea    0x0(,%r15,4),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x0,%ebx
test   %r15d,%r15d
jle    12b0 <main+0x140>
movl   $0x0,(%r14,%rbp,4)
xor    %eax,%eax
xor    %ebx,%ebx
jmp    124c <main+0xdc>
xchg   %ax,%ax
mov    0x14(%rsp),%eax
add    $0x1,%eax
cmp    %r15d,%eax
jge    12b0 <main+0x140>
test   %r15d,%r15d
jle    1244 <main+0xd4>
mov    %eax,0x14(%rsp)
not    %eax
mov    %eax,0x18(%rsp)
xor    %r13d,%r13d
jmp    1270 <main+0x100>
mov    %ebp,%ebx
add    $0x1,%r13
movslq 0xc(%rsp),%r15
cmp    %r15,%r13
jge    1240 <main+0xd0>
mov    %ebx,%ebp
mov    %r12,%rdi
lea    0xd90(%rip),%rsi
lea    0x1c(%rsp),%rdx
call   1060 <fscanf@plt>
cmpl   $0x0,0x1c(%rsp)
jle    1260 <main+0xf0>
mov    $0x1,%ebx
cmpl   $0x0,(%r14,%r13,4)
jne    1262 <main+0xf2>
mov    0x18(%rsp),%eax
mov    %eax,(%r14,%r13,4)
jmp    1260 <main+0xf0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%esi
mov    %r14,%rdi
call   1090 <checkBoard@plt>
test   %rax,%rax
jne    11c0 <main+0x50>
test   %ebx,%ebx
jne    11c0 <main+0x50>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1040 <nChancellors@plt>
lea    0xd45(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11cc <main+0x5c>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [21 x i8] c"Solving problem %d:\0A\00"
@.str.4 = [74 x i8] c"UH OH! There is a conflict in the initial board.\0ANumber of solutions: 0\0A\0A\00"
@.str.5 = [26 x i8] c"Number of solutions: %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
%14 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
store i32 0, i32* %2
br label %17
17: ; preds = %100, %0
%18 = load i32, i32* %2
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %103
21: ; preds = %17
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %7
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = mul i64 4, %28
%30 = trunc i64 %29 to i32
%31 = call i32* @malloc(i32 %30)
store i32* %31, i32** %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %32
32: ; preds = %41, %21
%33 = load i32, i32* %10
%34 = load i32, i32* %6
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i32*, i32** %8
%38 = load i32, i32* %2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 0, i32* %40
br label %41
41: ; preds = %36
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %32
44: ; preds = %32
store i32 0, i32* %11
br label %45
45: ; preds = %81, %44
%46 = load i32, i32* %11
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %84
49: ; preds = %45
store i32 0, i32* %12
br label %50
50: ; preds = %77, %49
%51 = load i32, i32* %12
%52 = load i32, i32* %6
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %80
54: ; preds = %50
%55 = load i32*, i32** %7
%56 = call i32 @fscanf(i32* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %13)
%57 = load i32, i32* %13
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %76
59: ; preds = %54
%60 = load i32*, i32** %8
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %59
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
%69 = sub nsw i32 0, %68
%70 = load i32*, i32** %8
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
store i32 %69, i32* %73
br label %75
74: ; preds = %59
store i32 1, i32* %9
br label %75
75: ; preds = %74, %66
br label %76
76: ; preds = %75, %54
br label %77
77: ; preds = %76
%78 = load i32, i32* %12
%79 = add nsw i32 %78, 1
store i32 %79, i32* %12
br label %50
80: ; preds = %50
br label %81
81: ; preds = %80
%82 = load i32, i32* %11
%83 = add nsw i32 %82, 1
store i32 %83, i32* %11
br label %45
84: ; preds = %45
%85 = load i32*, i32** %8
%86 = load i32, i32* %5
%87 = call i64 @checkBoard(i32* %85, i32 %86)
%88 = icmp ne i64 %87, 0
br i1 %88, label %92, label %89
89: ; preds = %84
%90 = load i32, i32* %9
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %89, %84
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0))
br label %99
94: ; preds = %89
%95 = load i32*, i32** %8
%96 = load i32, i32* %6
%97 = call i32 @nChancellors(i32* %95, i32 %96)
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %97)
br label %99
99: ; preds = %94, %92
br label %100
100: ; preds = %99
%101 = load i32, i32* %2
%102 = add nsw i32 %101, 1
store i32 %102, i32* %2
br label %17
103: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [21 x i8] c"Solving problem %d:\0A\00"
@.str.5 = [26 x i8] c"Number of solutions: %d\0A\0A\00"
@str = [73 x i8] c"UH OH! There is a conflict in the initial board.\0ANumber of solutions: 0\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %70
10: ; preds = %0
%11 = bitcast i32* %3 to i8*
br label %12
12: ; preds = %10, %66
%13 = phi i64 [ 0, %10 ], [ %14, %66 ]
%14 = add nuw nsw i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%18 = load i32, i32* %2
%19 = shl i32 %18, 2
%20 = call i32* @malloc(i32 %19)
%21 = icmp sgt i32 %18, 0
br i1 %21, label %22, label %31
22: ; preds = %12
%23 = getelementptr inbounds i32, i32* %20, i64 %13
store i32 0, i32* %23
br label %24
24: ; preds = %22, %38
%25 = phi i32 [ %39, %38 ], [ %18, %22 ]
%26 = phi i32 [ %41, %38 ], [ 0, %22 ]
%27 = phi i32 [ %40, %38 ], [ 0, %22 ]
%28 = icmp sgt i32 %25, 0
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = xor i32 %26, -1
br label %43
31: ; preds = %38, %12
%32 = phi i32 [ 0, %12 ], [ %40, %38 ]
%33 = load i32, i32* %1
%34 = call i64 @checkBoard(i32* %20, i32 %33)
%35 = icmp ne i64 %34, 0
%36 = icmp ne i32 %32, 0
%37 = select i1 %35, i1 true, i1 %36
br i1 %37, label %60, label %62
38: ; preds = %54, %24
%39 = phi i32 [ %25, %24 ], [ %57, %54 ]
%40 = phi i32 [ %27, %24 ], [ %55, %54 ]
%41 = add nuw nsw i32 %26, 1
%42 = icmp slt i32 %41, %39
br i1 %42, label %24, label %31
43: ; preds = %29, %54
%44 = phi i64 [ 0, %29 ], [ %56, %54 ]
%45 = phi i32 [ %27, %29 ], [ %55, %54 ]
%46 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%47 = load i32, i32* %3
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %43
%50 = getelementptr inbounds i32, i32* %20, i64 %44
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
store i32 %30, i32* %50
br label %54
54: ; preds = %49, %53, %43
%55 = phi i32 [ %45, %53 ], [ %45, %43 ], [ 1, %49 ]
%56 = add nuw nsw i64 %44, 1
%57 = load i32, i32* %2
%58 = sext i32 %57 to i64
%59 = icmp slt i64 %56, %58
br i1 %59, label %43, label %38
60: ; preds = %31
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str, i64 0, i64 0))
br label %66
62: ; preds = %31
%63 = load i32, i32* %2
%64 = call i32 @nChancellors(i32* %20, i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %62, %60
%67 = load i32, i32* %1
%68 = sext i32 %67 to i64
%69 = icmp slt i64 %14, %68
br i1 %69, label %12, label %70
70: ; preds = %66, %0
ret i32 0
}