#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 */
typedef int uint32_t;
struct position {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fen_build_string(struct position *, char *);
int /*<<< orphan*/ perft(struct position *, int, int *);
int /*<<< orphan*/ printf(char *, int);
int valid_position(struct position *);
void test_run_perft(struct position *pos, int depth) {
  uint32_t nleafs;
  char fenstr[256];
  assert(valid_position(pos));
  assert(depth > 0);
  fen_build_string(pos, fenstr);
  nleafs = 0;
  perft(pos, depth, &nleafs);
  printf("Nodes: %u\n", nleafs);
}


x86 assembly (clang, -O0):
<test_run_perft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <valid_position@plt>
mov    %eax,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1060 <fen_build_string@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   1050 <perft@plt>
mov    -0x10(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_run_perft>:
push   %rbp
push   %rbx
sub    $0x118,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1070 <valid_position@plt>
mov    %eax,%edi
call   1040 <assert@plt>
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
call   1040 <assert@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <fen_build_string@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <perft@plt>
mov    0xc(%rsp),%esi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
add    $0x118,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.position = type { i32 }
@.str = [11 x i8] c"Nodes: %u\0A\00"
define void @test_run_perft(%struct.position* %0, i32 %1) {
%3 = alloca %struct.position*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
store %struct.position* %0, %struct.position** %3
store i32 %1, i32* %4
%7 = load %struct.position*, %struct.position** %3
%8 = call i32 @valid_position(%struct.position* %7)
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load %struct.position*, %struct.position** %3
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i32 @fen_build_string(%struct.position* %14, i8* %15)
store i32 0, i32* %5
%17 = load %struct.position*, %struct.position** %3
%18 = load i32, i32* %4
%19 = call i32 @perft(%struct.position* %17, i32 %18, i32* %5)
%20 = load i32, i32* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %20)
ret void
}

LLVM IR (-O2):
%struct.position = type { i32 }
@.str = [11 x i8] c"Nodes: %u\0A\00"
define void @test_run_perft(%struct.position* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @valid_position(%struct.position* %0)
%8 = tail call i32 @assert(i32 %7)
%9 = icmp sgt i32 %1, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = call i32 @fen_build_string(%struct.position* %0, i8* %6)
store i32 0, i32* %3
%13 = call i32 @perft(%struct.position* %0, i32 %1, i32* %3)
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %14)
ret void
}