#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
char ***solveNQueens(int, int *, int **);
int main(int argc, char **argv) {
  int i, n, row, col, num_of_solution;
  if (argc != 2) {
    printf("Usage: ./queen 8\n");
    exit(-1);
  }
  n = atoi(argv[1]);
  int *col_sizes;
  char ***solutions = solveNQueens(n, &num_of_solution, &col_sizes);
  for (i = 0; i < num_of_solution; i++) {
    char **solution = solutions[i];
    for (row = 0; row < n; row++) {
      char *line = solution[row];
      for (col = 0; col < n; col++) {
        putchar(line[col]);
      }
      putchar('\n');
    }
    printf("The %dth solution.\n", i + 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <solveNQueens@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    125e <main+0x10e>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    123c <main+0xec>
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1224 <main+0xd4>
mov    -0x48(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f9 <main+0xa9>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d6 <main+0x86>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b3 <main+0x63>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1239 <main+0xd9>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %eax,(%rsp)
mov    %eax,%edi
call   1060 <solveNQueens@plt>
mov    %rax,0x8(%rsp)
cmpl   $0x0,0x4(%rsp)
jle    1228 <main+0xc8>
mov    (%rsp),%ebp
xor    %r13d,%r13d
jmp    11cf <main+0x6f>
nopl   0x0(%rax)
add    $0x1,%r13
lea    0xe45(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0x4(%rsp),%rax
cmp    %rax,%r13
jge    1228 <main+0xc8>
cmpl   $0x0,(%rsp)
jle    11b0 <main+0x50>
mov    0x8(%rsp),%rax
mov    (%rax,%r13,8),%rbx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%r15,8),%r14
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%r12,1),%edi
call   1030 <putchar@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    1200 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
cmp    %rbp,%r15
jne    11f0 <main+0x90>
jmp    11b0 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: ./queen 8\0A\00"
@.str.1 = [20 x i8] c"The %dth solution.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i8***
%13 = alloca i8**
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = call i8*** @solveNQueens(i32 %25, i32* %10, i32** %11)
store i8*** %26, i8**** %12
store i32 0, i32* %6
br label %27
27: ; preds = %70, %20
%28 = load i32, i32* %6
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %73
31: ; preds = %27
%32 = load i8***, i8**** %12
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8**, i8*** %32, i64 %34
%36 = load i8**, i8*** %35
store i8** %36, i8*** %13
store i32 0, i32* %8
br label %37
37: ; preds = %63, %31
%38 = load i32, i32* %8
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %66
41: ; preds = %37
%42 = load i8**, i8*** %13
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
store i8* %46, i8** %14
store i32 0, i32* %9
br label %47
47: ; preds = %58, %41
%48 = load i32, i32* %9
%49 = load i32, i32* %7
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = load i8*, i8** %14
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @putchar(i8 signext %56)
br label %58
58: ; preds = %51
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %47
61: ; preds = %47
%62 = call i32 @putchar(i8 signext 10)
br label %63
63: ; preds = %61
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %37
66: ; preds = %37
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %66
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %27
73: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"The %dth solution.\0A\00"
@str = [17 x i8] c"Usage: ./queen 8\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = bitcast i32* %3 to i8*
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = bitcast i32** %4 to i8*
%15 = call i8*** @solveNQueens(i32 %13, i32* %3, i32** %4)
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %10
%19 = icmp sgt i32 %13, 0
%20 = zext i32 %13 to i64
br label %21
21: ; preds = %18, %40
%22 = phi i64 [ 0, %18 ], [ %41, %40 ]
%23 = getelementptr inbounds i8**, i8*** %15, i64 %22
%24 = load i8**, i8*** %23
br i1 %19, label %25, label %40
25: ; preds = %21, %36
%26 = phi i64 [ %38, %36 ], [ 0, %21 ]
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
br label %29
29: ; preds = %25, %29
%30 = phi i64 [ 0, %25 ], [ %34, %29 ]
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @putchar(i8 signext %32)
%34 = add nuw nsw i64 %30, 1
%35 = icmp eq i64 %34, %20
br i1 %35, label %36, label %29
36: ; preds = %29
%37 = call i32 @putchar(i8 signext 10)
%38 = add nuw nsw i64 %26, 1
%39 = icmp eq i64 %38, %20
br i1 %39, label %40, label %25
40: ; preds = %36, %21
%41 = add nuw nsw i64 %22, 1
%42 = trunc i64 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %41, %45
br i1 %46, label %21, label %47
47: ; preds = %40, %10
ret i32 0
}