#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ replay_file(char *);
int /*<<< orphan*/ run_perft_test(int, char **);
int /*<<< orphan*/ run_tactics_test(int, char **);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ time_test(int);
int /*<<< orphan*/ transposition_table_counters_init();
int /*<<< orphan*/ transposition_table_counters_print();
int /*<<< orphan*/ transposition_table_init();
int /*<<< orphan*/ xboard_uci_main();
int /*<<< orphan*/ zobrist_hash_module_init();
int main(int argc, char **argv) {
  zobrist_hash_module_init();
  transposition_table_init();
  transposition_table_counters_init();
  if (argc < 2) {
    xboard_uci_main();
  }
  if (strcmp(argv[1], "perft") == 0) {
    run_perft_test(argc - 2, argv + 2);
  } else if (strcmp(argv[1], "timetest") == 0) {
    for (int depth = 0; depth < 8; ++depth) {
      time_test(depth);
    }
  } else if (strcmp(argv[1], "tactics") == 0) {
    run_tactics_test(argc - 2, argv + 2);
    transposition_table_counters_print();
  } else if (strcmp(argv[1], "replay") == 0) {
    if (argc == 3) {
      replay_file(argv[2]);
    } else {
      fprintf(stderr, "Usage: ./lesschess replay <FILE>\n");
    }
  } else {
    fprintf(stderr, "Unrecognized command: %s\n", argv[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10d0 <zobrist_hash_module_init@plt>
mov    $0x0,%al
call   1070 <transposition_table_init@plt>
mov    $0x0,%al
call   1040 <transposition_table_counters_init@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11ec <main+0x3c>
mov    $0x0,%al
call   10b0 <xboard_uci_main@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe05(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1222 <main+0x72>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1030 <run_perft_test@plt>
jmp    132d <main+0x17d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd5(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    126c <main+0xbc>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    1267 <main+0xb7>
mov    -0x14(%rbp),%edi
call   1050 <time_test@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1247 <main+0x97>
jmp    1328 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd94(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12a9 <main+0xf9>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1090 <run_tactics_test@plt>
mov    $0x0,%al
call   10a0 <transposition_table_counters_print@plt>
jmp    1323 <main+0x173>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd5f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12ff <main+0x14f>
cmpl   $0x3,-0x8(%rbp)
jne    12e3 <main+0x133>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <replay_file@plt>
jmp    12fa <main+0x14a>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    131e <main+0x16e>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1323 <main+0x173>
jmp    1328 <main+0x178>
jmp    132d <main+0x17d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   10d0 <zobrist_hash_module_init@plt>
xor    %eax,%eax
call   1070 <transposition_table_init@plt>
xor    %eax,%eax
call   1040 <transposition_table_counters_init@plt>
cmp    $0x1,%ebp
jg     11d9 <main+0x29>
xor    %eax,%eax
call   10b0 <xboard_uci_main@plt>
mov    0x8(%rbx),%rdi
lea    0xe1c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1255 <main+0xa5>
mov    0x8(%rbx),%rdi
lea    0xe0d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     126b <main+0xbb>
mov    0x8(%rbx),%rdi
lea    0xe01(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12ba <main+0x10a>
mov    0x8(%rbx),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12d4 <main+0x124>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdf7(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12fb <main+0x14b>
add    $0xfffffffe,%ebp
add    $0x10,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <run_perft_test@plt>
jmp    12fb <main+0x14b>
xor    %edi,%edi
call   1050 <time_test@plt>
mov    $0x1,%edi
call   1050 <time_test@plt>
mov    $0x2,%edi
call   1050 <time_test@plt>
mov    $0x3,%edi
call   1050 <time_test@plt>
mov    $0x4,%edi
call   1050 <time_test@plt>
mov    $0x5,%edi
call   1050 <time_test@plt>
mov    $0x6,%edi
call   1050 <time_test@plt>
mov    $0x7,%edi
call   1050 <time_test@plt>
jmp    12fb <main+0x14b>
add    $0xfffffffe,%ebp
add    $0x10,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <run_tactics_test@plt>
xor    %eax,%eax
call   10a0 <transposition_table_counters_print@plt>
jmp    12fb <main+0x14b>
cmp    $0x3,%ebp
jne    12e4 <main+0x134>
mov    0x10(%rbx),%rdi
call   10c0 <replay_file@plt>
jmp    12fb <main+0x14b>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"perft\00"
@.str.1 = [9 x i8] c"timetest\00"
@.str.2 = [8 x i8] c"tactics\00"
@.str.3 = [7 x i8] c"replay\00"
@stderr = global i32 0
@.str.4 = [34 x i8] c"Usage: ./lesschess replay <FILE>\0A\00"
@.str.5 = [26 x i8] c"Unrecognized command: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @zobrist_hash_module_init()
%8 = call i32 (...) @transposition_table_init()
%9 = call i32 (...) @transposition_table_counters_init()
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @xboard_uci_main()
br label %14
14: ; preds = %12, %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = call i32 @run_perft_test(i32 %22, i8** %24)
br label %83
26: ; preds = %14
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %26
store i32 0, i32* %6
br label %33
33: ; preds = %39, %32
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 8
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i32, i32* %6
%38 = call i32 @time_test(i32 %37)
br label %39
39: ; preds = %36
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %33
42: ; preds = %33
br label %82
43: ; preds = %26
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %56
49: ; preds = %43
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, 2
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = call i32 @run_tactics_test(i32 %51, i8** %53)
%55 = call i32 (...) @transposition_table_counters_print()
br label %81
56: ; preds = %43
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %74
62: ; preds = %56
%63 = load i32, i32* %4
%64 = icmp eq i32 %63, 3
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @replay_file(i8* %68)
br label %73
70: ; preds = %62
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %73
73: ; preds = %70, %65
br label %80
74: ; preds = %56
%75 = load i32, i32* @stderr
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %74, %73
br label %81
81: ; preds = %80, %49
br label %82
82: ; preds = %81, %42
br label %83
83: ; preds = %82, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"perft\00"
@.str.1 = [9 x i8] c"timetest\00"
@.str.2 = [8 x i8] c"tactics\00"
@.str.3 = [7 x i8] c"replay\00"
@stderr = global i32 0
@.str.4 = [34 x i8] c"Usage: ./lesschess replay <FILE>\0A\00"
@.str.5 = [26 x i8] c"Unrecognized command: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @zobrist_hash_module_init()
%4 = tail call i32 (...) @transposition_table_init()
%5 = tail call i32 (...) @transposition_table_counters_init()
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (...) @xboard_uci_main()
br label %9
9: ; preds = %7, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = add nsw i32 %0, -2
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = tail call i32 @run_perft_test(i32 %15, i8** %16)
br label %57
18: ; preds = %9
%19 = load i8*, i8** %10
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = tail call i32 @time_test(i32 0)
%24 = tail call i32 @time_test(i32 1)
%25 = tail call i32 @time_test(i32 2)
%26 = tail call i32 @time_test(i32 3)
%27 = tail call i32 @time_test(i32 4)
%28 = tail call i32 @time_test(i32 5)
%29 = tail call i32 @time_test(i32 6)
%30 = tail call i32 @time_test(i32 7)
br label %57
31: ; preds = %18
%32 = load i8*, i8** %10
%33 = tail call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = add nsw i32 %0, -2
%37 = getelementptr inbounds i8*, i8** %1, i64 2
%38 = tail call i32 @run_tactics_test(i32 %36, i8** %37)
%39 = tail call i32 (...) @transposition_table_counters_print()
br label %57
40: ; preds = %31
%41 = load i8*, i8** %10
%42 = tail call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = icmp eq i32 %0, 3
br i1 %45, label %46, label %50
46: ; preds = %44
%47 = getelementptr inbounds i8*, i8** %1, i64 2
%48 = load i8*, i8** %47
%49 = tail call i32 @replay_file(i8* %48)
br label %57
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %57
53: ; preds = %40
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %10
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %22, %53, %50, %46, %35, %14
ret i32 0
}