#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__ safe(int **, int, int, int);
int /*<<< orphan*/ set(int **, int, int, int);
int canPlaceQueen(int **board, int dimension, int col) {
  int row;
  for (row = 0; row < dimension; row++) {
    if (safe(board, dimension, row, col)) {
      set(board, 1, row, col);
      if (col == dimension - 1) {
        return 1;
      } else {
        if (canPlaceQueen(board, dimension, col + 1)) {
          return 1;
        } else {
          set(board, 0, row, col);
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<canPlaceQueen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f7 <canPlaceQueen+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <safe@plt>
cmp    $0x0,%rax
je     11e4 <canPlaceQueen+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    $0x1,%esi
call   1050 <set@plt>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11a2 <canPlaceQueen+0x72>
movl   $0x1,-0x4(%rbp)
jmp    11fe <canPlaceQueen+0xce>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1030 <canPlaceQueen@plt>
cmp    $0x0,%eax
je     11c9 <canPlaceQueen+0x99>
movl   $0x1,-0x4(%rbp)
jmp    11fe <canPlaceQueen+0xce>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
xor    %esi,%esi
call   1050 <set@plt>
jmp    11df <canPlaceQueen+0xaf>
jmp    11e4 <canPlaceQueen+0xb4>
jmp    11e9 <canPlaceQueen+0xb9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <canPlaceQueen+0x19>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canPlaceQueen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11b8 <canPlaceQueen+0x88>
mov    %edx,%r13d
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x1(%r13),%eax
mov    %eax,0x4(%rsp)
lea    -0x1(%r14),%r12d
xor    %ebp,%ebp
mov    $0x1,%ebx
jmp    1177 <canPlaceQueen+0x47>
nopl   (%rax)
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
call   1050 <set@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
je     11b8 <canPlaceQueen+0x88>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
call   1040 <safe@plt>
test   %rax,%rax
je     116f <canPlaceQueen+0x3f>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
call   1050 <set@plt>
cmp    %r13d,%r12d
je     11ba <canPlaceQueen+0x8a>
mov    %r15,%rdi
mov    %r14d,%esi
mov    0x4(%rsp),%edx
call   1030 <canPlaceQueen@plt>
test   %eax,%eax
je     1160 <canPlaceQueen+0x30>
jmp    11ba <canPlaceQueen+0x8a>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @canPlaceQueen(i32** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32** %0, i32*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %46, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %49
13: ; preds = %9
%14 = load i32**, i32*** %5
%15 = load i32, i32* %6
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = call i64 @safe(i32** %14, i32 %15, i32 %16, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %45
20: ; preds = %13
%21 = load i32**, i32*** %5
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = call i32 @set(i32** %21, i32 1, i32 %22, i32 %23)
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = icmp eq i32 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 1, i32* %4
br label %50
30: ; preds = %20
%31 = load i32**, i32*** %5
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
%35 = call i32 @canPlaceQueen(i32** %31, i32 %32, i32 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %30
store i32 1, i32* %4
br label %50
38: ; preds = %30
%39 = load i32**, i32*** %5
%40 = load i32, i32* %8
%41 = load i32, i32* %7
%42 = call i32 @set(i32** %39, i32 0, i32 %40, i32 %41)
br label %43
43: ; preds = %38
br label %44
44: ; preds = %43
br label %45
45: ; preds = %44, %13
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %9
49: ; preds = %9
store i32 0, i32* %4
br label %50
50: ; preds = %49, %37, %29
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
define i32 @canPlaceQueen(i32** %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = add nsw i32 %1, -1
%8 = icmp eq i32 %7, %2
br label %9
9: ; preds = %6, %20
%10 = phi i32 [ 0, %6 ], [ %21, %20 ]
%11 = tail call i64 @safe(i32** %0, i32 %1, i32 %10, i32 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = tail call i32 @set(i32** %0, i32 1, i32 %10, i32 %2)
br i1 %8, label %23, label %15
15: ; preds = %13
%16 = tail call i32 @canPlaceQueen(i32** %0, i32 %1, i32 %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = tail call i32 @set(i32** %0, i32 0, i32 %10, i32 %2)
br label %20
20: ; preds = %9, %18
%21 = add nuw nsw i32 %10, 1
%22 = icmp eq i32 %21, %1
br i1 %22, label %23, label %9
23: ; preds = %13, %15, %20, %3
%24 = phi i32 [ 0, %3 ], [ 0, %20 ], [ 1, %15 ], [ 1, %13 ]
ret i32 %24
}