#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 /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ FEN_to_arr(char *, double *);
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  FILE *f = fopen("scored_examples_final", "r");
  char line[512];
  int num_positions = 0;
  while (fgets(line, sizeof(line), f)) {
    num_positions++;
  }
  printf("num_positions: %d\n", num_positions);
  double board[64];
  fseek(f, 0, SEEK_SET);
  FILE *out = fopen("fann_examples", "w");
  fprintf(out, "%d %d %d\n", num_positions, 64, 1);
  for (int i = 0; i < num_positions; i++) {
    fgets(line, sizeof(line), f);
    int score;
    char fen[512];
    sscanf(line, "%d %s", &score, fen);
    double score_d = (double)score;
    assert(FEN_to_arr(fen, board));
    for (int j = 0; j < 64; j++) {
      fprintf(out, "%f ", board[j]);
    }
    fprintf(out, "\n");
    fprintf(out, "%f\n", score_d);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe37(%rip),%rdi
lea    0xe46(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1216 <main+0x76>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    11e3 <main+0x43>
mov    -0x214(%rbp),%esi
lea    0xdf5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
lea    0xde8(%rip),%rdi
lea    0xdef(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
mov    -0x214(%rbp),%edx
lea    0xdd1(%rip),%rsi
mov    $0x40,%ecx
mov    $0x1,%r8d
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x214(%rbp),%eax
jge    138e <main+0x1ee>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
lea    -0x210(%rbp),%rdi
lea    -0x630(%rbp),%rcx
lea    0xd83(%rip),%rsi
lea    -0x430(%rbp),%rdx
call   1090 <sscanf@plt>
cvtsi2sdl -0x430(%rbp),%xmm0
ff
movsd  %xmm0,-0x638(%rbp)
ff
lea    -0x630(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10c0 <FEN_to_arr@plt>
mov    %eax,%edi
call   1060 <assert@plt>
movl   $0x0,-0x63c(%rbp)
cmpl   $0x40,-0x63c(%rbp)
jge    1348 <main+0x1a8>
mov    -0x428(%rbp),%rdi
movslq -0x63c(%rbp),%rax
movsd  -0x420(%rbp,%rax,8),%xmm0
ff ff
lea    0xd1e(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x63c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x63c(%rbp)
jmp    1302 <main+0x162>
mov    -0x428(%rbp),%rdi
lea    0xcd3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x428(%rbp),%rdi
movsd  -0x638(%rbp),%xmm0
ff
lea    0xcdc(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1286 <main+0xe6>
mov    -0x4(%rbp),%eax
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x628,%rsp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe2a(%rip),%rdi
lea    0xe39(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    $0x1,%ebx
lea    0x220(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
add    $0xffffffff,%ebx
test   %rax,%rax
jne    1200 <main+0x50>
mov    %ebx,%r12d
neg    %r12d
lea    0xdf3(%rip),%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
lea    0xde1(%rip),%rdi
lea    0xde8(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbp
lea    0xddb(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,0x8(%rsp)
mov    %r12d,%edx
mov    $0x40,%ecx
mov    $0x1,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %ebx,%ebx
je     1364 <main+0x1b4>
lea    0xdbf(%rip),%r13
mov    %r15,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x220(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
lea    0xd83(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x420(%rsp),%rbx
mov    %rbx,%rcx
call   10a0 <sscanf@plt>
mov    0xc(%rsp),%r15d
mov    %rbx,%rdi
lea    0x20(%rsp),%rsi
call   10d0 <FEN_to_arr@plt>
mov    %eax,%edi
call   1070 <assert@plt>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x20(%rsp,%r12,8),%xmm0
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
add    $0x1,%r12
cmp    $0x40,%r12
jne    1300 <main+0x150>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
mov    %rbp,%rdi
lea    0xd0c(%rip),%rsi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1080 <fprintf@plt>
add    $0x1,%r14d
cmp    %r14d,0x8(%rsp)
mov    0x10(%rsp),%r15
jne    12a0 <main+0xf0>
xor    %eax,%eax
add    $0x628,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"scored_examples_final\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"num_positions: %d\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [14 x i8] c"fann_examples\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [10 x i8] c"%d %d %d\0A\00"
@.str.6 = [6 x i8] c"%d %s\00"
@.str.7 = [4 x i8] c"%f \00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = alloca [64 x double]
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca double
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32 @time(i32* null)
%13 = call i32 @srand(i32 %12)
%14 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %2
store i32 0, i32* %4
br label %15
15: ; preds = %20, %0
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%17 = load i32*, i32** %2
%18 = call i64 @fgets(i8* %16, i32 512, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %15
23: ; preds = %15
%24 = load i32, i32* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %2
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i32 0, i32 %27)
%29 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = load i32, i32* %4
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 64, i32 1)
store i32 0, i32* %7
br label %33
33: ; preds = %69, %23
%34 = load i32, i32* %7
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %72
37: ; preds = %33
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%39 = load i32*, i32** %2
%40 = call i64 @fgets(i8* %38, i32 512, i32* %39)
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%43 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32* %8, i8* %42)
%44 = load i32, i32* %8
%45 = sitofp i32 %44 to double
store double %45, double* %10
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%47 = getelementptr inbounds [64 x double], [64 x double]* %5, i64 0, i64 0
%48 = call i32 @FEN_to_arr(i8* %46, double* %47)
%49 = call i32 @assert(i32 %48)
store i32 0, i32* %11
br label %50
50: ; preds = %60, %37
%51 = load i32, i32* %11
%52 = icmp slt i32 %51, 64
br i1 %52, label %53, label %63
53: ; preds = %50
%54 = load i32*, i32** %6
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [64 x double], [64 x double]* %5, i64 0, i64 %56
%58 = load double, double* %57
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), double %58)
br label %60
60: ; preds = %53
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %50
63: ; preds = %50
%64 = load i32*, i32** %6
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%66 = load i32*, i32** %6
%67 = load double, double* %10
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double %67)
br label %69
69: ; preds = %63
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %33
72: ; preds = %33
%73 = load i32, i32* %1
ret i32 %73
}

LLVM IR (-O2):
@.str = [22 x i8] c"scored_examples_final\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"num_positions: %d\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [14 x i8] c"fann_examples\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [10 x i8] c"%d %d %d\0A\00"
@.str.6 = [6 x i8] c"%d %s\00"
@.str.7 = [4 x i8] c"%f \00"
@.str.9 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = alloca [64 x double]
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
br label %9
9: ; preds = %9, %0
%10 = phi i32 [ 0, %0 ], [ %13, %9 ]
%11 = call i64 @fgets(i8* %8, i32 512, i32* %7)
%12 = icmp eq i64 %11, 0
%13 = add nuw nsw i32 %10, 1
br i1 %12, label %14, label %9
14: ; preds = %9
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%16 = bitcast [64 x double]* %2 to i8*
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %7, i32 0, i32 %17)
%19 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %10, i32 64, i32 1)
%21 = icmp eq i32 %10, 0
br i1 %21, label %26, label %22
22: ; preds = %14
%23 = bitcast i32* %3 to i8*
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%25 = getelementptr inbounds [64 x double], [64 x double]* %2, i64 0, i64 0
br label %27
26: ; preds = %34, %14
ret i32 0
27: ; preds = %22, %34
%28 = phi i32 [ 0, %22 ], [ %38, %34 ]
%29 = call i64 @fgets(i8* %8, i32 512, i32* %7)
%30 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32* %3, i8* %24)
%31 = load i32, i32* %3
%32 = call i32 @FEN_to_arr(i8* %24, double* %25)
%33 = call i32 @assert(i32 %32)
br label %40
34: ; preds = %40
%35 = sitofp i32 %31 to double
%36 = call i32 @fputc(i32 10, i32* %19)
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double %35)
%38 = add nuw nsw i32 %28, 1
%39 = icmp eq i32 %38, %10
br i1 %39, label %26, label %27
40: ; preds = %27, %40
%41 = phi i64 [ 0, %27 ], [ %45, %40 ]
%42 = getelementptr inbounds [64 x double], [64 x double]* %2, i64 0, i64 %41
%43 = load double, double* %42
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), double %43)
%45 = add nuw nsw i64 %41, 1
%46 = icmp eq i64 %45, 64
br i1 %46, label %34, label %40
}