#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*/ generatePiecesFile(int);
int playAIGame(short *, int, float *);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ readPiecesFile(char *, short *, int);
short determineDirection(float *coefs, short indexToDetermine) {
  int scoreLeft = 0, scoreStay = 0, scoreRight = 0;
  short pieces[10][10000];
  short i = 0;
  printf("Determining direction\n");
  generatePiecesFile(10000);
  readPiecesFile("pieces", pieces[i], 10000);
  coefs[indexToDetermine] -= 0.001;
  scoreLeft = playAIGame(pieces[i], 10000, coefs);
  coefs[indexToDetermine] += 0.001;
  scoreStay = playAIGame(pieces[i], 10000, coefs);
  coefs[indexToDetermine] += 0.001;
  scoreRight = playAIGame(pieces[i], 10000, coefs);
  coefs[indexToDetermine] -= 0.001;
  if (scoreLeft >= scoreStay && scoreLeft > scoreRight)
    return -1;
  else if (scoreRight >= scoreStay && scoreRight > scoreLeft)
    return 1;
  else if (scoreStay > scoreLeft && scoreStay > scoreRight)
    return 0;
  else
    return (rand() % 2 == 0 ? -1 : 1);
}


x86 assembly (clang, -O0):
<determineDirection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d70,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movw   $0x0,-0x30d62(%rbp)
lea    0xe7d(%rip),%rdi
call   1060 <printf@plt>
mov    $0x2710,%edi
call   1030 <generatePiecesFile@plt>
movswq -0x30d62(%rbp),%rax
ff
lea    -0x30d60(%rbp),%rsi
imul   $0x4e20,%rax,%rax
add    %rax,%rsi
lea    0xe65(%rip),%rdi
mov    $0x2710,%edx
call   1040 <readPiecesFile@plt>
mov    -0x10(%rbp),%rax
movswq -0x12(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe22(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
movswq -0x30d62(%rbp),%rax
ff
lea    -0x30d60(%rbp),%rdi
imul   $0x4e20,%rax,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2710,%esi
call   1050 <playAIGame@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movswq -0x12(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdd1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
movswq -0x30d62(%rbp),%rax
ff
lea    -0x30d60(%rbp),%rdi
imul   $0x4e20,%rax,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2710,%esi
call   1050 <playAIGame@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movswq -0x12(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd80(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
movswq -0x30d62(%rbp),%rax
ff
lea    -0x30d60(%rbp),%rdi
imul   $0x4e20,%rax,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2710,%esi
call   1050 <playAIGame@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movswq -0x12(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd2f(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1301 <determineDirection+0x1b1>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1301 <determineDirection+0x1b1>
movw   $0xffff,-0x2(%rbp)
jmp    136a <determineDirection+0x21a>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1324 <determineDirection+0x1d4>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1324 <determineDirection+0x1d4>
movw   $0x1,-0x2(%rbp)
jmp    136a <determineDirection+0x21a>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1347 <determineDirection+0x1f7>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1347 <determineDirection+0x1f7>
movw   $0x0,-0x2(%rbp)
jmp    136a <determineDirection+0x21a>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x30d70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<determineDirection>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30d40,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2710,%edi
call   1030 <generatePiecesFile@plt>
lea    0xe8f(%rip),%rdi
mov    %rsp,%r15
mov    %r15,%rsi
mov    $0x2710,%edx
call   1050 <readPiecesFile@plt>
movslq %ebp,%rbp
movss  (%rbx,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe5b(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
mov    %r15,%rdi
mov    $0x2710,%esi
mov    %rbx,%rdx
call   1060 <playAIGame@plt>
mov    %eax,%r12d
movss  (%rbx,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe36(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
mov    %r15,%rdi
mov    $0x2710,%esi
mov    %rbx,%rdx
call   1060 <playAIGame@plt>
mov    %eax,%r14d
movss  (%rbx,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe09(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
mov    %r15,%rdi
mov    $0x2710,%esi
mov    %rbx,%rdx
call   1060 <playAIGame@plt>
movss  (%rbx,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xdd7(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
cmp    %r14d,%r12d
jl     1240 <determineDirection+0xf0>
mov    $0xffff,%cx
cmp    %eax,%r12d
jg     126e <determineDirection+0x11e>
cmp    %r14d,%eax
jl     124e <determineDirection+0xfe>
mov    $0x1,%cx
cmp    %r12d,%eax
jg     126e <determineDirection+0x11e>
cmp    %r12d,%r14d
jle    125c <determineDirection+0x10c>
cmp    %eax,%r14d
jle    125c <determineDirection+0x10c>
xor    %ecx,%ecx
jmp    126e <determineDirection+0x11e>
xor    %eax,%eax
call   1070 <rand@plt>
and    $0x1,%eax
cmp    $0x1,%eax
sbb    %ecx,%ecx
or     $0x1,%ecx
mov    %ecx,%eax
add    $0x30d40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Determining direction\0A\00"
@.str.1 = [7 x i8] c"pieces\00"
define signext i16 @determineDirection(float* %0, i16 signext %1) {
%3 = alloca i16
%4 = alloca float*
%5 = alloca i16
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [10 x [10000 x i16]]
%10 = alloca i16
store float* %0, float** %4
store i16 %1, i16* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i16 0, i16* %10
%11 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @generatePiecesFile(i32 10000)
%13 = load i16, i16* %10
%14 = sext i16 %13 to i64
%15 = getelementptr inbounds [10 x [10000 x i16]], [10 x [10000 x i16]]* %9, i64 0, i64 %14
%16 = getelementptr inbounds [10000 x i16], [10000 x i16]* %15, i64 0, i64 0
%17 = call i32 @readPiecesFile(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i16* %16, i32 10000)
%18 = load float*, float** %4
%19 = load i16, i16* %5
%20 = sext i16 %19 to i64
%21 = getelementptr inbounds float, float* %18, i64 %20
%22 = load float, float* %21
%23 = fpext float %22 to double
%24 = fsub double %23, 1.000000e-03
%25 = fptrunc double %24 to float
store float %25, float* %21
%26 = load i16, i16* %10
%27 = sext i16 %26 to i64
%28 = getelementptr inbounds [10 x [10000 x i16]], [10 x [10000 x i16]]* %9, i64 0, i64 %27
%29 = getelementptr inbounds [10000 x i16], [10000 x i16]* %28, i64 0, i64 0
%30 = load float*, float** %4
%31 = call i32 @playAIGame(i16* %29, i32 10000, float* %30)
store i32 %31, i32* %6
%32 = load float*, float** %4
%33 = load i16, i16* %5
%34 = sext i16 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
%36 = load float, float* %35
%37 = fpext float %36 to double
%38 = fadd double %37, 1.000000e-03
%39 = fptrunc double %38 to float
store float %39, float* %35
%40 = load i16, i16* %10
%41 = sext i16 %40 to i64
%42 = getelementptr inbounds [10 x [10000 x i16]], [10 x [10000 x i16]]* %9, i64 0, i64 %41
%43 = getelementptr inbounds [10000 x i16], [10000 x i16]* %42, i64 0, i64 0
%44 = load float*, float** %4
%45 = call i32 @playAIGame(i16* %43, i32 10000, float* %44)
store i32 %45, i32* %7
%46 = load float*, float** %4
%47 = load i16, i16* %5
%48 = sext i16 %47 to i64
%49 = getelementptr inbounds float, float* %46, i64 %48
%50 = load float, float* %49
%51 = fpext float %50 to double
%52 = fadd double %51, 1.000000e-03
%53 = fptrunc double %52 to float
store float %53, float* %49
%54 = load i16, i16* %10
%55 = sext i16 %54 to i64
%56 = getelementptr inbounds [10 x [10000 x i16]], [10 x [10000 x i16]]* %9, i64 0, i64 %55
%57 = getelementptr inbounds [10000 x i16], [10000 x i16]* %56, i64 0, i64 0
%58 = load float*, float** %4
%59 = call i32 @playAIGame(i16* %57, i32 10000, float* %58)
store i32 %59, i32* %8
%60 = load float*, float** %4
%61 = load i16, i16* %5
%62 = sext i16 %61 to i64
%63 = getelementptr inbounds float, float* %60, i64 %62
%64 = load float, float* %63
%65 = fpext float %64 to double
%66 = fsub double %65, 1.000000e-03
%67 = fptrunc double %66 to float
store float %67, float* %63
%68 = load i32, i32* %6
%69 = load i32, i32* %7
%70 = icmp sge i32 %68, %69
br i1 %70, label %71, label %76
71: ; preds = %2
%72 = load i32, i32* %6
%73 = load i32, i32* %8
%74 = icmp sgt i32 %72, %73
br i1 %74, label %75, label %76
75: ; preds = %71
store i16 -1, i16* %3
br label %101
76: ; preds = %71, %2
%77 = load i32, i32* %8
%78 = load i32, i32* %7
%79 = icmp sge i32 %77, %78
br i1 %79, label %80, label %85
80: ; preds = %76
%81 = load i32, i32* %8
%82 = load i32, i32* %6
%83 = icmp sgt i32 %81, %82
br i1 %83, label %84, label %85
84: ; preds = %80
store i16 1, i16* %3
br label %101
85: ; preds = %80, %76
%86 = load i32, i32* %7
%87 = load i32, i32* %6
%88 = icmp sgt i32 %86, %87
br i1 %88, label %89, label %94
89: ; preds = %85
%90 = load i32, i32* %7
%91 = load i32, i32* %8
%92 = icmp sgt i32 %90, %91
br i1 %92, label %93, label %94
93: ; preds = %89
store i16 0, i16* %3
br label %101
94: ; preds = %89, %85
%95 = call i32 (...) @rand()
%96 = srem i32 %95, 2
%97 = icmp eq i32 %96, 0
%98 = zext i1 %97 to i64
%99 = select i1 %97, i32 -1, i32 1
%100 = trunc i32 %99 to i16
store i16 %100, i16* %3
br label %101
101: ; preds = %94, %93, %84, %75
%102 = load i16, i16* %3
ret i16 %102
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"pieces\00"
@str = [22 x i8] c"Determining direction\00"
define signext i16 @determineDirection(float* %0, i16 signext %1) {
%3 = alloca [10 x [10000 x i16]]
%4 = bitcast [10 x [10000 x i16]]* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @generatePiecesFile(i32 10000)
%7 = getelementptr inbounds [10 x [10000 x i16]], [10 x [10000 x i16]]* %3, i64 0, i64 0, i64 0
%8 = call i32 @readPiecesFile(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i16* %7, i32 10000)
%9 = sext i16 %1 to i64
%10 = getelementptr inbounds float, float* %0, i64 %9
%11 = load float, float* %10
%12 = fpext float %11 to double
%13 = fadd double %12, -1.000000e-03
%14 = fptrunc double %13 to float
store float %14, float* %10
%15 = call i32 @playAIGame(i16* %7, i32 10000, float* %0)
%16 = load float, float* %10
%17 = fpext float %16 to double
%18 = fadd double %17, 1.000000e-03
%19 = fptrunc double %18 to float
store float %19, float* %10
%20 = call i32 @playAIGame(i16* %7, i32 10000, float* %0)
%21 = load float, float* %10
%22 = fpext float %21 to double
%23 = fadd double %22, 1.000000e-03
%24 = fptrunc double %23 to float
store float %24, float* %10
%25 = call i32 @playAIGame(i16* %7, i32 10000, float* %0)
%26 = load float, float* %10
%27 = fpext float %26 to double
%28 = fadd double %27, -1.000000e-03
%29 = fptrunc double %28 to float
store float %29, float* %10
%30 = icmp sge i32 %15, %20
%31 = icmp sgt i32 %15, %25
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %46, label %33
33: ; preds = %2
%34 = icmp sge i32 %25, %20
%35 = icmp sgt i32 %25, %15
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %46, label %37
37: ; preds = %33
%38 = icmp sgt i32 %20, %15
%39 = icmp sgt i32 %20, %25
%40 = select i1 %38, i1 %39, i1 false
br i1 %40, label %46, label %41
41: ; preds = %37
%42 = call i32 (...) @rand()
%43 = and i32 %42, 1
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i16 -1, i16 1
br label %46
46: ; preds = %37, %33, %2, %41
%47 = phi i16 [ %45, %41 ], [ -1, %2 ], [ 1, %33 ], [ 0, %37 ]
ret i16 %47
}