#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__ fnPlace(int, int, int *);
int /*<<< orphan*/ printf(char *, ...);
void fnQueens(int iK, int iN) {
  int iI, iJ, iL;
  static int iCount, iX[10];
  for (iI = 1; iI <= iN; iI++) {
    if (fnPlace(iK, iI, iX)) {
      iX[iK] = iI;
      if (iK == iN) {
        printf("\nFeassible solution : %d", ++iCount);
        printf("\nSolutions are : ");
        for (iJ = 1; iJ <= iN; iJ++)
          printf(" %d ", iX[iJ]);
        for (iJ = 1; iJ <= iN; iJ++) {
          printf("\n");
          for (iL = 1; iL <= iN; iL++) {
            if (iL == iX[iJ])
              printf(" X ");
            else
              printf(" 0 ");
          }
        }
      } else
        fnQueens(iK + 1, iN);
    }
  }
}


x86 assembly (clang, -O0):
<fnQueens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12af <fnQueens+0x17f>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    0x2f02(%rip),%rdx
call   1050 <fnPlace@plt>
cmp    $0x0,%rax
je     129c <fnQueens+0x16c>
mov    -0xc(%rbp),%edx
movslq -0x4(%rbp),%rcx
lea    0x2ee5(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1289 <fnQueens+0x159>
mov    0x2ec0(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2eb7(%rip)
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11f2 <fnQueens+0xc2>
movslq -0x10(%rbp),%rcx
lea    0x2e8d(%rip),%rax
mov    (%rax,%rcx,4),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bc <fnQueens+0x8c>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1284 <fnQueens+0x154>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1271 <fnQueens+0x141>
mov    -0x14(%rbp),%eax
movslq -0x10(%rbp),%rdx
lea    0x2e2c(%rip),%rcx
cmp    (%rcx,%rdx,4),%eax
jne    1250 <fnQueens+0x120>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125e <fnQueens+0x12e>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1263 <fnQueens+0x133>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121a <fnQueens+0xea>
jmp    1276 <fnQueens+0x146>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f9 <fnQueens+0xc9>
jmp    1297 <fnQueens+0x167>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
call   1030 <fnQueens@plt>
jmp    129c <fnQueens+0x16c>
jmp    12a1 <fnQueens+0x171>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1145 <fnQueens+0x15>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnQueens>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,(%rsp)
test   %esi,%esi
jle    12ab <fnQueens+0x16b>
movslq (%rsp),%rcx
mov    %rcx,%rax
mov    %rcx,0x18(%rsp)
lea    0x1(%rcx),%eax
mov    %eax,0x4(%rsp)
lea    0x1(%rsi),%r14d
mov    %esi,%r12d
neg    %r12d
mov    $0x1,%eax
lea    0x2ede(%rip),%rbp
lea    0xea7(%rip),%r15
lea    0xea4(%rip),%r13
mov    %rsi,0x8(%rsp)
mov    %r14,0x20(%rsp)
jmp    11be <fnQueens+0x7e>
nopl   0x0(%rax)
mov    0x4(%rsp),%edi
call   1040 <fnQueens@plt>
mov    0x10(%rsp),%rcx
lea    0x1(%rcx),%eax
mov    0x8(%rsp),%rsi
cmp    %esi,%ecx
je     12ab <fnQueens+0x16b>
mov    (%rsp),%edi
mov    %rax,0x10(%rsp)
mov    %eax,%esi
mov    %rbp,%rdx
call   1060 <fnPlace@plt>
test   %rax,%rax
je     11a9 <fnQueens+0x69>
mov    0x18(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    %ecx,0x0(%rbp,%rax,4)
mov    0x8(%rsp),%rsi
cmp    %esi,(%rsp)
jne    11a0 <fnQueens+0x60>
mov    0x2e5d(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2e54(%rip)
lea    0xdfd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
nopl   (%rax)
mov    0x0(%rbp,%rbx,4),%esi
lea    0xe00(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1220 <fnQueens+0xe0>
mov    $0x1,%ebx
jmp    1262 <fnQueens+0x122>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
mov    0x20(%rsp),%r14
cmp    %r14,%rbx
je     11a9 <fnQueens+0x69>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%r14d
jmp    129c <fnQueens+0x15c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%r12,%r14,1),%eax
add    $0x1,%eax
mov    %r14d,%ecx
add    $0x1,%ecx
mov    %ecx,%r14d
cmp    $0x1,%eax
je     1250 <fnQueens+0x110>
mov    %r15,%rdi
cmp    0x0(%rbp,%rbx,4),%r14d
je     1280 <fnQueens+0x140>
mov    %r13,%rdi
jmp    1280 <fnQueens+0x140>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@fnQueens.iCount = internal unnamed_addr global i32 0
@fnQueens.iX = internal global [10 x i32] zeroinitializer
@.str = [25 x i8] c"\0AFeassible solution : %d\00"
@.str.1 = [18 x i8] c"\0ASolutions are : \00"
@.str.2 = [5 x i8] c" %d \00"
@.str.4 = [4 x i8] c" X \00"
@.str.5 = [4 x i8] c" 0 \00"
define void @fnQueens(i32 %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %48, label %4
4: ; preds = %2
%5 = sext i32 %0 to i64
%6 = getelementptr inbounds [10 x i32], [10 x i32]* @fnQueens.iX, i64 0, i64 %5
%7 = icmp eq i32 %0, %1
%8 = add nsw i32 %0, 1
%9 = add nuw i32 %1, 1
%10 = zext i32 %9 to i64
%11 = zext i32 %9 to i64
br label %12
12: ; preds = %4, %45
%13 = phi i32 [ 1, %4 ], [ %46, %45 ]
%14 = tail call i64 @fnPlace(i32 %0, i32 %13, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @fnQueens.iX, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %45, label %16
16: ; preds = %12
store i32 %13, i32* %6
br i1 %7, label %17, label %44
17: ; preds = %16
%18 = load i32, i32* @fnQueens.iCount
%19 = add nsw i32 %18, 1
store i32 %19, i32* @fnQueens.iCount
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %17, %22
%23 = phi i64 [ 1, %17 ], [ %27, %22 ]
%24 = getelementptr inbounds [10 x i32], [10 x i32]* @fnQueens.iX, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %10
br i1 %28, label %29, label %22
29: ; preds = %22, %41
%30 = phi i64 [ %42, %41 ], [ 1, %22 ]
%31 = tail call i32 @putchar(i32 10)
%32 = getelementptr inbounds [10 x i32], [10 x i32]* @fnQueens.iX, i64 0, i64 %30
br label %33
33: ; preds = %29, %33
%34 = phi i32 [ 1, %29 ], [ %39, %33 ]
%35 = load i32, i32* %32
%36 = icmp eq i32 %34, %35
%37 = select i1 %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %37)
%39 = add nuw i32 %34, 1
%40 = icmp eq i32 %34, %1
br i1 %40, label %41, label %33
41: ; preds = %33
%42 = add nuw nsw i64 %30, 1
%43 = icmp eq i64 %42, %11
br i1 %43, label %45, label %29
44: ; preds = %16
tail call void @fnQueens(i32 %8, i32 %1)
br label %45
45: ; preds = %41, %12, %44
%46 = add nuw i32 %13, 1
%47 = icmp eq i32 %13, %1
br i1 %47, label %48, label %12
48: ; preds = %45, %2
ret void
}