#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*/ _IONBF;
int /*<<< orphan*/ bitboard_init();
int /*<<< orphan*/ eval_init();
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ position_init();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ prng_init(int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ tt_init(int);
int /*<<< orphan*/ uci_exec(char *);
int main(int argc, char **argv) {
  bitboard_init();
  prng_init(73);
  tt_init(144000000);
  position_init();
  eval_init();
  printf("Chess Engine By Sylvain Philip\n");
  setvbuf(stdin, NULL, _IONBF, 0);
  setvbuf(stdout, NULL, _IONBF, 0);
  char input[1024];
  while (1) {
    if (fgets(input, 1024, stdin) != NULL) {
      int s = strlen(input);
      if (s > 1 && input[s - 1] == '\n') {
        input[s - 1] = '\0';
      }
      uci_exec(input);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <bitboard_init@plt>
mov    $0x49,%edi
call   1040 <prng_init@plt>
mov    $0x8954400,%edi
call   10c0 <tt_init@plt>
mov    $0x0,%al
call   10b0 <position_init@plt>
mov    $0x0,%al
call   1090 <eval_init@plt>
lea    0xe17(%rip),%rdi
call   1060 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12a6 <main+0x106>
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x1,-0x414(%rbp)
jle    129a <main+0xfa>
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    129a <main+0xfa>
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1030 <uci_exec@plt>
jmp    1228 <main+0x88>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   1070 <bitboard_init@plt>
mov    $0x49,%edi
call   1050 <prng_init@plt>
mov    $0x8954400,%edi
call   10c0 <tt_init@plt>
xor    %eax,%eax
call   10b0 <position_init@plt>
xor    %eax,%eax
call   1090 <eval_init@plt>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e02(%rip),%r14
mov    (%r14),%edi
mov    0x2df0(%rip),%rbx
mov    (%rbx),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
mov    %rsp,%rbx
jmp    1228 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <uci_exec@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     1228 <main+0x88>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     1220 <main+0x80>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
jne    1220 <main+0x80>
movb   $0x0,(%rsp,%rax,1)
jmp    1220 <main+0x80>

LLVM IR (-O0):
@.str = [32 x i8] c"Chess Engine By Sylvain Philip\0A\00"
@stdin = global i32 0
@_IONBF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @bitboard_init()
%9 = call i32 @prng_init(i32 73)
%10 = call i32 @tt_init(i32 144000000)
%11 = call i32 (...) @position_init()
%12 = call i32 (...) @eval_init()
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = load i32, i32* @_IONBF
%16 = call i32 @setvbuf(i32 %14, i32* null, i32 %15, i32 0)
%17 = load i32, i32* @stdout
%18 = load i32, i32* @_IONBF
%19 = call i32 @setvbuf(i32 %17, i32* null, i32 %18, i32 0)
br label %20
20: ; preds = %2, %46
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* @stdin
%23 = call i32* @fgets(i8* %21, i32 1024, i32 %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %46
25: ; preds = %20
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %43
30: ; preds = %25
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %43
38: ; preds = %30
%39 = load i32, i32* %7
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %38, %30, %25
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = call i32 @uci_exec(i8* %44)
br label %46
46: ; preds = %43, %20
br label %20
}

LLVM IR (-O2):
@stdin = global i32 0
@_IONBF = global i32 0
@stdout = global i32 0
@str = [31 x i8] c"Chess Engine By Sylvain Philip\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32 (...) @bitboard_init()
%5 = tail call i32 @prng_init(i32 73)
%6 = tail call i32 @tt_init(i32 144000000)
%7 = tail call i32 (...) @position_init()
%8 = tail call i32 (...) @eval_init()
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = load i32, i32* @_IONBF
%12 = tail call i32 @setvbuf(i32 %10, i32* null, i32 %11, i32 0)
%13 = load i32, i32* @stdout
%14 = load i32, i32* @_IONBF
%15 = tail call i32 @setvbuf(i32 %13, i32* null, i32 %14, i32 0)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %17
17: ; preds = %33, %2
%18 = load i32, i32* @stdin
%19 = call i32* @fgets(i8* %16, i32 1024, i32 %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = call i32 @strlen(i8* %16)
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = add nsw i32 %22, -1
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 10
br i1 %29, label %30, label %31
30: ; preds = %24
store i8 0, i8* %27
br label %31
31: ; preds = %30, %24, %21
%32 = call i32 @uci_exec(i8* %16)
br label %33
33: ; preds = %31, %17
br label %17
}