#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 /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
scalar_t__ n_queens(int **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int board[(100)][(100)], i, j, n, m;
  printf("Enter the size of chess board: ");
  scanf("%d", &m);
  printf("Enter the number of queens: ");
  scanf("%d", &n);
  for (i = 0; i < m; i++)
    memset(board[i], 0, m);
  if (n_queens(board, n, m)) {
    printf("YES\n");
    for (i = 0; i < m; i++, printf("\n"))
      for (j = 0; j < m; j++)
        printf("%d ", board[i][j]);
  } else {
    printf("NO\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x9c60(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
lea    -0x9c5c(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x9c54(%rbp)
mov    -0x9c54(%rbp),%eax
cmp    -0x9c60(%rbp),%eax
jge    11e9 <main+0xa9>
movslq -0x9c54(%rbp),%rax
lea    -0x9c50(%rbp),%rdi
imul   $0x190,%rax,%rax
add    %rax,%rdi
mov    -0x9c60(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    119e <main+0x5e>
lea    -0x9c50(%rbp),%rdi
mov    -0x9c5c(%rbp),%esi
mov    -0x9c60(%rbp),%edx
call   1030 <n_queens@plt>
cmp    $0x0,%rax
je     12c1 <main+0x181>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x9c54(%rbp)
mov    -0x9c54(%rbp),%eax
cmp    -0x9c60(%rbp),%eax
jge    12bc <main+0x17c>
movl   $0x0,-0x9c58(%rbp)
mov    -0x9c58(%rbp),%eax
cmp    -0x9c60(%rbp),%eax
jge    1295 <main+0x155>
movslq -0x9c54(%rbp),%rcx
lea    -0x9c50(%rbp),%rax
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x9c58(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x9c58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c58(%rbp)
jmp    123f <main+0xff>
jmp    129a <main+0x15a>
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1223 <main+0xe3>
jmp    12cf <main+0x18f>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x9c58,%rsp
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe9d(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
mov    0x8(%rsp),%edx
test   %edx,%edx
jle    11df <main+0x7f>
lea    0x10(%rsp),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rdx
add    $0x190,%r14
cmp    %rdx,%rbx
jl     11c0 <main+0x60>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1040 <n_queens@plt>
test   %rax,%rax
je     126e <main+0x10e>
lea    0xe4b(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    127a <main+0x11a>
lea    0xe30(%rip),%r14
xor    %r15d,%r15d
jmp    123f <main+0xdf>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r15
mov    $0xa,%edi
call   1030 <putchar@plt>
movslq 0x8(%rsp),%rax
add    $0x190,%r12
cmp    %rax,%r15
jge    127a <main+0x11a>
test   %eax,%eax
jle    1220 <main+0xc0>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <main+0xf0>
jmp    1220 <main+0xc0>
lea    0xdcf(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x9c58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Enter the size of chess board: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Enter the number of queens: \00"
@.str.3 = [5 x i8] c"YES\0A\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [4 x i8] c"NO\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x [100 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 0, i32* %3
br label %11
11: ; preds = %22, %0
%12 = load i32, i32* %3
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %17
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %18, i64 0, i64 0
%20 = load i32, i32* %6
%21 = call i32 @memset(i32* %19, i32 0, i32 %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %11
25: ; preds = %11
%26 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 0
%27 = bitcast [100 x i32]* %26 to i32**
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i64 @n_queens(i32** %27, i32 %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %61
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %34
34: ; preds = %56, %32
%35 = load i32, i32* %3
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %60
38: ; preds = %34
store i32 0, i32* %4
br label %39
39: ; preds = %52, %38
%40 = load i32, i32* %4
%41 = load i32, i32* %6
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %45
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %46, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %43
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %39
55: ; preds = %39
br label %56
56: ; preds = %55
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %34
60: ; preds = %34
br label %63
61: ; preds = %25
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %61, %60
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Enter the size of chess board: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Enter the number of queens: \00"
@.str.4 = [4 x i8] c"%d \00"
@str = [3 x i8] c"NO\00"
@str.7 = [4 x i8] c"YES\00"
define i32 @main() {
%1 = alloca [100 x [100 x i32]]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [100 x [100 x i32]]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %0, %13
%14 = phi i64 [ %18, %13 ], [ 0, %0 ]
%15 = phi i32 [ %19, %13 ], [ %11, %0 ]
%16 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %1, i64 0, i64 %14, i64 0
%17 = call i32 @memset(i32* %16, i32 0, i32 %15)
%18 = add nuw nsw i64 %14, 1
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %13, label %22
22: ; preds = %13, %0
%23 = phi i32 [ %11, %0 ], [ %19, %13 ]
%24 = bitcast [100 x [100 x i32]]* %1 to i32**
%25 = load i32, i32* %2
%26 = call i64 @n_queens(i32** %24, i32 %25, i32 %23)
%27 = icmp eq i64 %26, 0
br i1 %27, label %51, label %28
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.7, i64 0, i64 0))
%30 = load i32, i32* %3
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %53
32: ; preds = %28, %45
%33 = phi i32 [ %48, %45 ], [ %30, %28 ]
%34 = phi i64 [ %46, %45 ], [ 0, %28 ]
%35 = icmp sgt i32 %33, 0
br i1 %35, label %36, label %45
36: ; preds = %32, %36
%37 = phi i64 [ %41, %36 ], [ 0, %32 ]
%38 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %1, i64 0, i64 %34, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = add nuw nsw i64 %37, 1
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = icmp slt i64 %41, %43
br i1 %44, label %36, label %45
45: ; preds = %36, %32
%46 = add nuw nsw i64 %34, 1
%47 = call i32 @putchar(i32 10)
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = icmp slt i64 %46, %49
br i1 %50, label %32, label %53
51: ; preds = %22
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %45, %28, %51
ret i32 0
}