#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*/ FILE;

/* Variables and functions */
short determineDirection(float *, short);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, short, long, long);
scalar_t__ playAIGame(short *, int, float *);
int /*<<< orphan*/ printf(char *, short, long, long);
short specificCoefHillClimbing(short **pieces, float *coefs, short *directions,
                               short indexToHillClimb, FILE *f) {
  int previousScore = 0;
  int nextScore = 0;
  int counter = 0;
  long globalScore = 0;
  directions[indexToHillClimb] = determineDirection(coefs, indexToHillClimb);
  if (directions[indexToHillClimb] == 0)
    return 0;
  do {
    previousScore = nextScore;
    nextScore = 0;
    coefs[indexToHillClimb] += directions[indexToHillClimb] * 0.001;
    for (short i = 0; i < 10; i++)
      nextScore += playAIGame(pieces[i], 10000, coefs);
    globalScore += nextScore;
    printf("Coef %d, score %d, fitness %f\n", indexToHillClimb, nextScore,
           nextScore / (5.0 * 10000 * 10));
    counter++;
  } while (nextScore >= previousScore);
  coefs[indexToHillClimb] -= directions[indexToHillClimb] * 0.001;
  fprintf(f, "Coef %d, score %li, fitness %f\n", indexToHillClimb, globalScore,
          globalScore / (5.0 * 10 * 10000 * counter));
  printf("Coef %d, score %li, fitness %f\n", indexToHillClimb, globalScore,
         globalScore / (5.0 * 10 * 10000 * counter));
  return 1;
}


x86 assembly (clang, -O0):
<specificCoefHillClimbing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ax,-0x22(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
movswl -0x22(%rbp),%esi
call   1060 <determineDirection@plt>
mov    %ax,%dx
mov    -0x20(%rbp),%rax
movswq -0x22(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x20(%rbp),%rax
movswq -0x22(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
cmp    $0x0,%eax
jne    11ba <specificCoefHillClimbing+0x7a>
movw   $0x0,-0x2(%rbp)
jmp    136d <specificCoefHillClimbing+0x22d>
jmp    11bf <specificCoefHillClimbing+0x7f>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movswq -0x22(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movswq -0x22(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe09(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
movw   $0x0,-0x4a(%rbp)
movswl -0x4a(%rbp),%eax
cmp    $0xa,%eax
jge    1254 <specificCoefHillClimbing+0x114>
mov    -0x10(%rbp),%rax
movswq -0x4a(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2710,%esi
call   1030 <playAIGame@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x4a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x4a(%rbp)
jmp    120e <specificCoefHillClimbing+0xce>
movslq -0x38(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x22(%rbp),%ax
movslq -0x38(%rbp),%rdx
cvtsi2sdl -0x38(%rbp),%xmm0
movsd  0xd93(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
lea    0xd8b(%rip),%rdi
movswl %ax,%esi
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11bf <specificCoefHillClimbing+0x7f>
mov    -0x20(%rbp),%rax
movswq -0x22(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movswq -0x22(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
movq   %xmm0,%rdx
movabs $0x8000000000000000,%rsi
xor    %rsi,%rdx
movq   %rdx,%xmm0
movsd  0xd1c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%rdi
mov    -0x22(%rbp),%ax
mov    -0x48(%rbp),%rcx
cvtsi2sdq -0x48(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm2
movsd  0xcf4(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r8
lea    0xd07(%rip),%rsi
movswl %ax,%edx
call   1050 <fprintf@plt>
mov    -0x22(%rbp),%ax
mov    -0x48(%rbp),%rdx
cvtsi2sdq -0x48(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm2
movsd  0xcbd(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
lea    0xcd0(%rip),%rdi
movswl %ax,%esi
call   1040 <printf@plt>
movw   $0x1,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<specificCoefHillClimbing>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %ecx,%esi
call   1060 <determineDirection@plt>
movslq %r15d,%rdx
mov    %ax,(%r12,%rdx,2)
xor    %esi,%esi
test   %ax,%ax
je     1379 <specificCoefHillClimbing+0x239>
mov    %rbx,0x8(%rsp)
movswl %r15w,%ecx
mov    %ecx,(%rsp)
xor    %ecx,%ecx
xor    %r15d,%r15d
mov    %rdx,0x18(%rsp)
mov    %r12,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rsi,0x20(%rsp)
mov    %ecx,0x4(%rsp)
cwtl
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movss  0x0(%r13,%rdx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xe3c(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x0(%r13,%rdx,4)
mov    (%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %r15,%rbx
mov    %rax,%r15
mov    0x8(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%r12
add    %r15d,%r12d
mov    %rbx,%r15
mov    0x10(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbp
add    %r12d,%ebp
mov    0x10(%rsp),%r12
mov    0x18(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    0x20(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    0x28(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    0x30(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    0x38(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    0x40(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    0x48(%r14),%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1030 <playAIGame@plt>
mov    %rax,%rbx
add    %ebp,%ebx
movslq %ebx,%rbp
cvtsi2sd %ebp,%xmm0
add    %rbp,%r15
divsd  0xd3d(%rip),%xmm0
cvttsd2si %xmm0,%rcx
lea    0xd41(%rip),%rdi
mov    (%rsp),%esi
mov    %rbp,%rdx
call   1040 <printf@plt>
mov    0x4(%rsp),%ecx
mov    0x18(%rsp),%rdx
add    $0x1,%ecx
movzwl (%r12,%rdx,2),%eax
cmp    0x20(%rsp),%ebp
mov    %ebx,%esi
jge    11a0 <specificCoefHillClimbing+0x60>
cwtl
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movss  0x0(%r13,%rdx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xcf6(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r15,%xmm1
cvtsi2sd %ecx,%xmm2
mulsd  0xcd2(%rip),%xmm2
movss  %xmm0,0x0(%r13,%rdx,4)
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rbx
lea    0xcea(%rip),%r14
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    (%rsp),%ebp
mov    %ebp,%edx
mov    %r15,%rcx
mov    %rbx,%r8
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
mov    $0x1,%si
mov    %esi,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Coef %d, score %d, fitness %f\0A\00"
@.str.1 = [32 x i8] c"Coef %d, score %li, fitness %f\0A\00"
define signext i16 @specificCoefHillClimbing(i16** %0, float* %1, i16* %2, i16 signext %3, i32* %4) {
%6 = alloca i16
%7 = alloca i16**
%8 = alloca float*
%9 = alloca i16*
%10 = alloca i16
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i16
store i16** %0, i16*** %7
store float* %1, float** %8
store i16* %2, i16** %9
store i16 %3, i16* %10
store i32* %4, i32** %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i64 0, i64* %15
%17 = load float*, float** %8
%18 = load i16, i16* %10
%19 = call signext i16 @determineDirection(float* %17, i16 signext %18)
%20 = load i16*, i16** %9
%21 = load i16, i16* %10
%22 = sext i16 %21 to i64
%23 = getelementptr inbounds i16, i16* %20, i64 %22
store i16 %19, i16* %23
%24 = load i16*, i16** %9
%25 = load i16, i16* %10
%26 = sext i16 %25 to i64
%27 = getelementptr inbounds i16, i16* %24, i64 %26
%28 = load i16, i16* %27
%29 = sext i16 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %5
store i16 0, i16* %6
br label %126
32: ; preds = %5
br label %33
33: ; preds = %84, %32
%34 = load i32, i32* %13
store i32 %34, i32* %12
store i32 0, i32* %13
%35 = load i16*, i16** %9
%36 = load i16, i16* %10
%37 = sext i16 %36 to i64
%38 = getelementptr inbounds i16, i16* %35, i64 %37
%39 = load i16, i16* %38
%40 = sext i16 %39 to i32
%41 = sitofp i32 %40 to double
%42 = load float*, float** %8
%43 = load i16, i16* %10
%44 = sext i16 %43 to i64
%45 = getelementptr inbounds float, float* %42, i64 %44
%46 = load float, float* %45
%47 = fpext float %46 to double
%48 = call double @llvm.fmuladd.f64(double %41, double 1.000000e-03, double %47)
%49 = fptrunc double %48 to float
store float %49, float* %45
store i16 0, i16* %16
br label %50
50: ; preds = %66, %33
%51 = load i16, i16* %16
%52 = sext i16 %51 to i32
%53 = icmp slt i32 %52, 10
br i1 %53, label %54, label %69
54: ; preds = %50
%55 = load i16**, i16*** %7
%56 = load i16, i16* %16
%57 = sext i16 %56 to i64
%58 = getelementptr inbounds i16*, i16** %55, i64 %57
%59 = load i16*, i16** %58
%60 = load float*, float** %8
%61 = call i64 @playAIGame(i16* %59, i32 10000, float* %60)
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = add nsw i64 %63, %61
%65 = trunc i64 %64 to i32
store i32 %65, i32* %13
br label %66
66: ; preds = %54
%67 = load i16, i16* %16
%68 = add i16 %67, 1
store i16 %68, i16* %16
br label %50
69: ; preds = %50
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = load i64, i64* %15
%73 = add nsw i64 %72, %71
store i64 %73, i64* %15
%74 = load i16, i16* %10
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = load i32, i32* %13
%78 = sitofp i32 %77 to double
%79 = fdiv double %78, 5.000000e+05
%80 = fptosi double %79 to i64
%81 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i16 signext %74, i64 %76, i64 %80)
%82 = load i32, i32* %14
%83 = add nsw i32 %82, 1
store i32 %83, i32* %14
br label %84
84: ; preds = %69
%85 = load i32, i32* %13
%86 = load i32, i32* %12
%87 = icmp sge i32 %85, %86
br i1 %87, label %33, label %88
88: ; preds = %84
%89 = load i16*, i16** %9
%90 = load i16, i16* %10
%91 = sext i16 %90 to i64
%92 = getelementptr inbounds i16, i16* %89, i64 %91
%93 = load i16, i16* %92
%94 = sext i16 %93 to i32
%95 = sitofp i32 %94 to double
%96 = load float*, float** %8
%97 = load i16, i16* %10
%98 = sext i16 %97 to i64
%99 = getelementptr inbounds float, float* %96, i64 %98
%100 = load float, float* %99
%101 = fpext float %100 to double
%102 = fneg double %95
%103 = call double @llvm.fmuladd.f64(double %102, double 1.000000e-03, double %101)
%104 = fptrunc double %103 to float
store float %104, float* %99
%105 = load i32*, i32** %11
%106 = load i16, i16* %10
%107 = load i64, i64* %15
%108 = load i64, i64* %15
%109 = sitofp i64 %108 to double
%110 = load i32, i32* %14
%111 = sitofp i32 %110 to double
%112 = fmul double 5.000000e+05, %111
%113 = fdiv double %109, %112
%114 = fptosi double %113 to i64
%115 = call i32 @fprintf(i32* %105, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i16 signext %106, i64 %107, i64 %114)
%116 = load i16, i16* %10
%117 = load i64, i64* %15
%118 = load i64, i64* %15
%119 = sitofp i64 %118 to double
%120 = load i32, i32* %14
%121 = sitofp i32 %120 to double
%122 = fmul double 5.000000e+05, %121
%123 = fdiv double %119, %122
%124 = fptosi double %123 to i64
%125 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i16 signext %116, i64 %117, i64 %124)
store i16 1, i16* %6
br label %126
126: ; preds = %88, %31
%127 = load i16, i16* %6
ret i16 %127
}

LLVM IR (-O2):
@.str = [31 x i8] c"Coef %d, score %d, fitness %f\0A\00"
@.str.1 = [32 x i8] c"Coef %d, score %li, fitness %f\0A\00"
define signext i16 @specificCoefHillClimbing(i16** nocapture %0, float* %1, i16* nocapture %2, i16 signext %3, i32* nocapture %4) {
%6 = tail call signext i16 @determineDirection(float* %1, i16 signext %3)
%7 = sext i16 %3 to i64
%8 = getelementptr inbounds i16, i16* %2, i64 %7
store i16 %6, i16* %8
%9 = icmp eq i16 %6, 0
br i1 %9, label %93, label %10
10: ; preds = %5
%11 = getelementptr inbounds float, float* %1, i64 %7
%12 = getelementptr inbounds i16*, i16** %0, i64 1
%13 = getelementptr inbounds i16*, i16** %0, i64 2
%14 = getelementptr inbounds i16*, i16** %0, i64 3
%15 = getelementptr inbounds i16*, i16** %0, i64 4
%16 = getelementptr inbounds i16*, i16** %0, i64 5
%17 = getelementptr inbounds i16*, i16** %0, i64 6
%18 = getelementptr inbounds i16*, i16** %0, i64 7
%19 = getelementptr inbounds i16*, i16** %0, i64 8
%20 = getelementptr inbounds i16*, i16** %0, i64 9
br label %21
21: ; preds = %21, %10
%22 = phi i16 [ %6, %10 ], [ %78, %21 ]
%23 = phi i32 [ 0, %10 ], [ %69, %21 ]
%24 = phi i32 [ 0, %10 ], [ %76, %21 ]
%25 = phi i64 [ 0, %10 ], [ %71, %21 ]
%26 = sitofp i16 %22 to double
%27 = load float, float* %11
%28 = fpext float %27 to double
%29 = tail call double @llvm.fmuladd.f64(double %26, double 1.000000e-03, double %28)
%30 = fptrunc double %29 to float
store float %30, float* %11
%31 = load i16*, i16** %0
%32 = tail call i64 @playAIGame(i16* %31, i32 10000, float* %1)
%33 = trunc i64 %32 to i32
%34 = load i16*, i16** %12
%35 = tail call i64 @playAIGame(i16* %34, i32 10000, float* %1)
%36 = trunc i64 %35 to i32
%37 = add i32 %33, %36
%38 = load i16*, i16** %13
%39 = tail call i64 @playAIGame(i16* %38, i32 10000, float* %1)
%40 = trunc i64 %39 to i32
%41 = add i32 %37, %40
%42 = load i16*, i16** %14
%43 = tail call i64 @playAIGame(i16* %42, i32 10000, float* %1)
%44 = trunc i64 %43 to i32
%45 = add i32 %41, %44
%46 = load i16*, i16** %15
%47 = tail call i64 @playAIGame(i16* %46, i32 10000, float* %1)
%48 = trunc i64 %47 to i32
%49 = add i32 %45, %48
%50 = load i16*, i16** %16
%51 = tail call i64 @playAIGame(i16* %50, i32 10000, float* %1)
%52 = trunc i64 %51 to i32
%53 = add i32 %49, %52
%54 = load i16*, i16** %17
%55 = tail call i64 @playAIGame(i16* %54, i32 10000, float* %1)
%56 = trunc i64 %55 to i32
%57 = add i32 %53, %56
%58 = load i16*, i16** %18
%59 = tail call i64 @playAIGame(i16* %58, i32 10000, float* %1)
%60 = trunc i64 %59 to i32
%61 = add i32 %57, %60
%62 = load i16*, i16** %19
%63 = tail call i64 @playAIGame(i16* %62, i32 10000, float* %1)
%64 = trunc i64 %63 to i32
%65 = add i32 %61, %64
%66 = load i16*, i16** %20
%67 = tail call i64 @playAIGame(i16* %66, i32 10000, float* %1)
%68 = trunc i64 %67 to i32
%69 = add i32 %65, %68
%70 = sext i32 %69 to i64
%71 = add nsw i64 %25, %70
%72 = sitofp i32 %69 to double
%73 = fdiv double %72, 5.000000e+05
%74 = fptosi double %73 to i64
%75 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i16 signext %3, i64 %70, i64 %74)
%76 = add nuw nsw i32 %24, 1
%77 = icmp slt i32 %69, %23
%78 = load i16, i16* %8
br i1 %77, label %79, label %21
79: ; preds = %21
%80 = sitofp i16 %78 to double
%81 = load float, float* %11
%82 = fpext float %81 to double
%83 = fneg double %80
%84 = tail call double @llvm.fmuladd.f64(double %83, double 1.000000e-03, double %82)
%85 = fptrunc double %84 to float
store float %85, float* %11
%86 = sitofp i64 %71 to double
%87 = sitofp i32 %76 to double
%88 = fmul double %87, 5.000000e+05
%89 = fdiv double %86, %88
%90 = fptosi double %89 to i64
%91 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i16 signext %3, i64 %71, i64 %90)
%92 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i16 signext %3, i64 %71, i64 %90)
br label %93
93: ; preds = %5, %79
%94 = phi i16 [ 1, %79 ], [ 0, %5 ]
ret i16 %94
}