#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 */
double adjust_x(double, double, double, double, double);
double ind_expected(double, double *, double *, int, double);
double calc_ind_rating(double cume_score, double *rtng, double *weig, int r,
                       double beta) {
  int i;
  double olddev, curdev;
  int rounds = 10000;
  double delta = 200.0;
  double kappa = 0.05;
  double denom = 2;
  int phase = 0;
  int n = 20;
  double D, sc, oldx;
  double x = 2000;
  double xp;
  D = cume_score - ind_expected(x, rtng, weig, r, beta);
  curdev = D * D;
  olddev = curdev;
  while (n-- > 0) {
    double kk = 1.0;
    for (i = 0; i < rounds; i++) {
      oldx = x;
      olddev = curdev;
      sc = cume_score;
      xp = ind_expected(x, rtng, weig, r, beta);
      x = adjust_x(x, xp, sc, delta, kappa * kk);
      xp = ind_expected(x, rtng, weig, r, beta);
      D = xp - sc;
      curdev = D * D;
      if (curdev >= olddev) {
        x = oldx;
        curdev = olddev;
        break;
      };
      if (curdev < 0.000001)
        break;
      kk *= 0.995;
    }
    delta /= denom;
    kappa *= denom;
    phase++;
    if (curdev < 0.000001)
      break;
  }
  return x;
}


x86 assembly (clang, -O0):
<calc_ind_rating>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  %xmm1,-0x28(%rbp)
movl   $0x2710,-0x44(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe9f(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x14,-0x68(%rbp)
movsd  0xe7c(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
movsd  -0x28(%rbp),%xmm1
call   1030 <ind_expected@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x68(%rbp)
cmp    $0x0,%eax
jle    138c <calc_ind_rating+0x26c>
movsd  0xe21(%rip),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1344 <calc_ind_rating+0x224>
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x80(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
movsd  -0x28(%rbp),%xmm1
call   1030 <ind_expected@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x90(%rbp),%xmm1
ff
movsd  -0x78(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm3
movsd  -0x58(%rbp),%xmm4
mulsd  -0x98(%rbp),%xmm4
ff
call   1040 <adjust_x@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
movsd  -0x28(%rbp),%xmm1
call   1030 <ind_expected@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
subsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1306 <calc_ind_rating+0x1e6>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1344 <calc_ind_rating+0x224>
movsd  0xd1a(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    131e <calc_ind_rating+0x1fe>
jmp    1344 <calc_ind_rating+0x224>
movsd  0xd0a(%rip),%xmm0
mulsd  -0x98(%rbp),%xmm0
ff
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120e <calc_ind_rating+0xee>
movsd  -0x60(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
movsd  0xcb1(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1387 <calc_ind_rating+0x267>
jmp    138c <calc_ind_rating+0x26c>
jmp    11e3 <calc_ind_rating+0xc3>
movsd  -0x88(%rbp),%xmm0
ff
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_ind_rating>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
movsd  %xmm0,(%rsp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <ind_expected@plt>
movsd  0xeab(%rip),%xmm2
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
movaps 0xeb3(%rip),%xmm1
movaps %xmm1,0x20(%rsp)
mov    $0x14,%r15d
jmp    11b4 <calc_ind_rating+0x94>
nopw   0x0(%rax,%rax,1)
movapd %xmm0,%xmm3
movaps %xmm2,%xmm1
movapd 0x20(%rsp),%xmm0
mulpd  0xe9b(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0xe6d(%rip),%xmm0
ucomisd %xmm3,%xmm0
movapd %xmm3,%xmm0
movaps %xmm1,%xmm2
ja     12a4 <calc_ind_rating+0x184>
sub    $0x1,%r15d
jb     12a1 <calc_ind_rating+0x181>
movaps 0x20(%rsp),%xmm1
movhlps %xmm1,%xmm1
movaps %xmm1,0x40(%rsp)
mov    $0x2710,%ebx
movsd  0xe30(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
xchg   %ax,%ax
movsd  %xmm0,0x38(%rsp)
movaps %xmm2,%xmm0
movsd  %xmm2,0x18(%rsp)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
movsd  0x10(%rsp),%xmm1
call   1030 <ind_expected@plt>
movaps %xmm0,%xmm1
movapd 0x20(%rsp),%xmm4
mulsd  0x8(%rsp),%xmm4
movsd  0x18(%rsp),%xmm0
movsd  (%rsp),%xmm2
movaps 0x40(%rsp),%xmm3
call   1040 <adjust_x@plt>
movsd  %xmm0,0x30(%rsp)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
movsd  0x10(%rsp),%xmm1
call   1030 <ind_expected@plt>
movsd  0x38(%rsp),%xmm3
movsd  0x18(%rsp),%xmm1
movsd  0x30(%rsp),%xmm2
subsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    1187 <calc_ind_rating+0x67>
movsd  0x8(%rsp),%xmm3
movsd  0xd9c(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1180 <calc_ind_rating+0x60>
mulsd  0xd92(%rip),%xmm3
movsd  %xmm3,0x8(%rsp)
movapd %xmm0,%xmm3
movaps %xmm2,%xmm1
add    $0xffffffff,%ebx
jne    11e0 <calc_ind_rating+0xc0>
jmp    1187 <calc_ind_rating+0x67>
movaps %xmm2,%xmm1
movaps %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @calc_ind_rating(double %0, double* %1, double* %2, i32 %3, double %4) {
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
store double %0, double* %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store double %4, double* %10
store i32 10000, i32* %14
store double 2.000000e+02, double* %15
store double 5.000000e-02, double* %16
store double 2.000000e+00, double* %17
store i32 0, i32* %18
store i32 20, i32* %19
store double 2.000000e+03, double* %23
%26 = load double, double* %6
%27 = load double, double* %23
%28 = load double*, double** %7
%29 = load double*, double** %8
%30 = load i32, i32* %9
%31 = load double, double* %10
%32 = call double @ind_expected(double %27, double* %28, double* %29, i32 %30, double %31)
%33 = fsub double %26, %32
store double %33, double* %20
%34 = load double, double* %20
%35 = load double, double* %20
%36 = fmul double %34, %35
store double %36, double* %13
%37 = load double, double* %13
store double %37, double* %12
br label %38
38: ; preds = %105, %5
%39 = load i32, i32* %19
%40 = add nsw i32 %39, -1
store i32 %40, i32* %19
%41 = icmp sgt i32 %39, 0
br i1 %41, label %42, label %106
42: ; preds = %38
store double 1.000000e+00, double* %25
store i32 0, i32* %11
br label %43
43: ; preds = %90, %42
%44 = load i32, i32* %11
%45 = load i32, i32* %14
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %93
47: ; preds = %43
%48 = load double, double* %23
store double %48, double* %22
%49 = load double, double* %13
store double %49, double* %12
%50 = load double, double* %6
store double %50, double* %21
%51 = load double, double* %23
%52 = load double*, double** %7
%53 = load double*, double** %8
%54 = load i32, i32* %9
%55 = load double, double* %10
%56 = call double @ind_expected(double %51, double* %52, double* %53, i32 %54, double %55)
store double %56, double* %24
%57 = load double, double* %23
%58 = load double, double* %24
%59 = load double, double* %21
%60 = load double, double* %15
%61 = load double, double* %16
%62 = load double, double* %25
%63 = fmul double %61, %62
%64 = call double @adjust_x(double %57, double %58, double %59, double %60, double %63)
store double %64, double* %23
%65 = load double, double* %23
%66 = load double*, double** %7
%67 = load double*, double** %8
%68 = load i32, i32* %9
%69 = load double, double* %10
%70 = call double @ind_expected(double %65, double* %66, double* %67, i32 %68, double %69)
store double %70, double* %24
%71 = load double, double* %24
%72 = load double, double* %21
%73 = fsub double %71, %72
store double %73, double* %20
%74 = load double, double* %20
%75 = load double, double* %20
%76 = fmul double %74, %75
store double %76, double* %13
%77 = load double, double* %13
%78 = load double, double* %12
%79 = fcmp oge double %77, %78
br i1 %79, label %80, label %83
80: ; preds = %47
%81 = load double, double* %22
store double %81, double* %23
%82 = load double, double* %12
store double %82, double* %13
br label %93
83: ; preds = %47
%84 = load double, double* %13
%85 = fcmp olt double %84, 0x3EB0C6F7A0B5ED8D
br i1 %85, label %86, label %87
86: ; preds = %83
br label %93
87: ; preds = %83
%88 = load double, double* %25
%89 = fmul double %88, 0x3FEFD70A3D70A3D7
store double %89, double* %25
br label %90
90: ; preds = %87
%91 = load i32, i32* %11
%92 = add nsw i32 %91, 1
store i32 %92, i32* %11
br label %43
93: ; preds = %86, %80, %43
%94 = load double, double* %17
%95 = load double, double* %15
%96 = fdiv double %95, %94
store double %96, double* %15
%97 = load double, double* %17
%98 = load double, double* %16
%99 = fmul double %98, %97
store double %99, double* %16
%100 = load i32, i32* %18
%101 = add nsw i32 %100, 1
store i32 %101, i32* %18
%102 = load double, double* %13
%103 = fcmp olt double %102, 0x3EB0C6F7A0B5ED8D
br i1 %103, label %104, label %105
104: ; preds = %93
br label %106
105: ; preds = %93
br label %38
106: ; preds = %104, %38
%107 = load double, double* %23
ret double %107
}

LLVM IR (-O2):
define double @calc_ind_rating(double %0, double* %1, double* %2, i32 %3, double %4) {
%6 = tail call double @ind_expected(double 2.000000e+03, double* %1, double* %2, i32 %3, double %4)
%7 = fsub double %0, %6
%8 = fmul double %7, %7
br label %9
9: ; preds = %37, %5
%10 = phi i32 [ 20, %5 ], [ %14, %37 ]
%11 = phi double [ %8, %5 ], [ %38, %37 ]
%12 = phi double [ 2.000000e+03, %5 ], [ %39, %37 ]
%13 = phi <2 x double> [ <double 5.000000e-02, double 2.000000e+02>, %5 ], [ %40, %37 ]
%14 = add nsw i32 %10, -1
%15 = icmp eq i32 %10, 0
br i1 %15, label %42, label %16
16: ; preds = %9
%17 = extractelement <2 x double> %13, i64 0
%18 = extractelement <2 x double> %13, i64 1
br label %19
19: ; preds = %16, %33
%20 = phi double [ %34, %33 ], [ 1.000000e+00, %16 ]
%21 = phi i32 [ %35, %33 ], [ 0, %16 ]
%22 = phi double [ %26, %33 ], [ %12, %16 ]
%23 = phi double [ %29, %33 ], [ %11, %16 ]
%24 = tail call double @ind_expected(double %22, double* %1, double* %2, i32 %3, double %4)
%25 = fmul double %17, %20
%26 = tail call double @adjust_x(double %22, double %24, double %0, double %18, double %25)
%27 = tail call double @ind_expected(double %26, double* %1, double* %2, i32 %3, double %4)
%28 = fsub double %27, %0
%29 = fmul double %28, %28
%30 = fcmp ult double %29, %23
br i1 %30, label %31, label %37
31: ; preds = %19
%32 = fcmp olt double %29, 0x3EB0C6F7A0B5ED8D
br i1 %32, label %37, label %33
33: ; preds = %31
%34 = fmul double %20, 0x3FEFD70A3D70A3D7
%35 = add nuw nsw i32 %21, 1
%36 = icmp eq i32 %35, 10000
br i1 %36, label %37, label %19
37: ; preds = %19, %31, %33
%38 = phi double [ %29, %31 ], [ %29, %33 ], [ %23, %19 ]
%39 = phi double [ %26, %31 ], [ %26, %33 ], [ %22, %19 ]
%40 = fmul <2 x double> %13, <double 2.000000e+00, double 5.000000e-01>
%41 = fcmp olt double %38, 0x3EB0C6F7A0B5ED8D
br i1 %41, label %42, label %9
42: ; preds = %37, %9
%43 = phi double [ %39, %37 ], [ %12, %9 ]
ret double %43
}