#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*/ place_queen(size_t, unsigned int **, size_t, size_t);
int /*<<< orphan*/ remove_queen(size_t, unsigned int **, size_t, size_t);
unsigned long long queens_arrangements_aux(size_t x, unsigned board[x][x],
                                           size_t curr_row) {
  if (curr_row == x) {
    return 1;
  }
  unsigned long long res = 0;
  size_t i;
  for (i = 0; i < x; i++) {
    if (board[curr_row][i] == 0) {
      place_queen(x, board, curr_row, i);
      res += queens_arrangements_aux(x, board, curr_row + 1);
      remove_queen(x, board, curr_row, i);
    }
  }
  return res;
}


x86 assembly (clang, -O0):
<queens_arrangements_aux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1167 <queens_arrangements_aux+0x37>
movq   $0x1,-0x8(%rbp)
jmp    120c <queens_arrangements_aux+0xdc>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1204 <queens_arrangements_aux+0xd4>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    -0x30(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11ee <queens_arrangements_aux+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <place_queen@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
call   1030 <queens_arrangements_aux@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1050 <remove_queen@plt>
jmp    11f3 <queens_arrangements_aux+0xc3>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1177 <queens_arrangements_aux+0x47>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<queens_arrangements_aux>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r12d
cmp    %rdi,%rdx
je     11ba <queens_arrangements_aux+0x8a>
mov    %rdi,%rbx
test   %rdi,%rdi
je     11b7 <queens_arrangements_aux+0x87>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdx,%rax
imul   %rbx,%rax
lea    (%rsi,%rax,4),%r13
lea    0x1(%rdx),%rax
mov    %rax,(%rsp)
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1179 <queens_arrangements_aux+0x49>
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11ba <queens_arrangements_aux+0x8a>
cmpl   $0x0,0x0(%r13,%rbp,4)
jne    1170 <queens_arrangements_aux+0x40>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1040 <place_queen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    (%rsp),%rdx
call   1030 <queens_arrangements_aux@plt>
add    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1050 <remove_queen@plt>
jmp    1170 <queens_arrangements_aux+0x40>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @queens_arrangements_aux(i64 %0, i32* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %5
store i32* %1, i32** %6
store i64 %2, i64* %7
%10 = load i64, i64* %5
%11 = load i64, i64* %5
%12 = load i64, i64* %7
%13 = load i64, i64* %5
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %3
store i64 1, i64* %4
br label %56
16: ; preds = %3
store i64 0, i64* %8
store i64 0, i64* %9
br label %17
17: ; preds = %51, %16
%18 = load i64, i64* %9
%19 = load i64, i64* %5
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %54
21: ; preds = %17
%22 = load i32*, i32** %6
%23 = load i64, i64* %7
%24 = mul nsw i64 %23, %11
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i64, i64* %9
%27 = getelementptr inbounds i32, i32* %25, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %50
30: ; preds = %21
%31 = load i64, i64* %5
%32 = load i32*, i32** %6
%33 = bitcast i32* %32 to i32**
%34 = load i64, i64* %7
%35 = load i64, i64* %9
%36 = call i32 @place_queen(i64 %31, i32** %33, i64 %34, i64 %35)
%37 = load i64, i64* %5
%38 = load i32*, i32** %6
%39 = load i64, i64* %7
%40 = add i64 %39, 1
%41 = call i64 @queens_arrangements_aux(i64 %37, i32* %38, i64 %40)
%42 = load i64, i64* %8
%43 = add i64 %42, %41
store i64 %43, i64* %8
%44 = load i64, i64* %5
%45 = load i32*, i32** %6
%46 = bitcast i32* %45 to i32**
%47 = load i64, i64* %7
%48 = load i64, i64* %9
%49 = call i32 @remove_queen(i64 %44, i32** %46, i64 %47, i64 %48)
br label %50
50: ; preds = %30, %21
br label %51
51: ; preds = %50
%52 = load i64, i64* %9
%53 = add i64 %52, 1
store i64 %53, i64* %9
br label %17
54: ; preds = %17
%55 = load i64, i64* %8
store i64 %55, i64* %4
br label %56
56: ; preds = %54, %15
%57 = load i64, i64* %4
ret i64 %57
}

LLVM IR (-O2):
define i64 @queens_arrangements_aux(i64 %0, i32* %1, i64 %2) {
%4 = icmp eq i64 %2, %0
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = icmp eq i64 %0, 0
br i1 %6, label %27, label %7
7: ; preds = %5
%8 = mul nsw i64 %2, %0
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = bitcast i32* %1 to i32**
%11 = add i64 %2, 1
br label %12
12: ; preds = %7, %23
%13 = phi i64 [ 0, %7 ], [ %25, %23 ]
%14 = phi i64 [ 0, %7 ], [ %24, %23 ]
%15 = getelementptr inbounds i32, i32* %9, i64 %13
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = tail call i32 @place_queen(i64 %0, i32** %10, i64 %2, i64 %13)
%20 = tail call i64 @queens_arrangements_aux(i64 %0, i32* %1, i64 %11)
%21 = add i64 %20, %14
%22 = tail call i32 @remove_queen(i64 %0, i32** %10, i64 %2, i64 %13)
br label %23
23: ; preds = %12, %18
%24 = phi i64 [ %21, %18 ], [ %14, %12 ]
%25 = add nuw i64 %13, 1
%26 = icmp eq i64 %25, %0
br i1 %26, label %27, label %12
27: ; preds = %23, %5, %3
%28 = phi i64 [ 1, %3 ], [ 0, %5 ], [ %24, %23 ]
ret i64 %28
}