#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 */
scalar_t__ randomMT();
int sample_best(double *score, int nscores, double empty) {
  int i, bestind;
  double bestscore;
  bestind = 0;
  bestscore = score[0];
  for (i = 1; i < nscores; i++) {
    score[i] =
        score[i] - 0.0001 * (double)(((unsigned long)randomMT()) / 4294967296.);
    if (score[i] > bestscore) {
      bestscore = score[i];
      bestind = i;
    }
  }
  return bestind;
}


x86 assembly (clang, -O0):
<sample_best>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <sample_best+0xec>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
xor    %eax,%eax
call   1030 <randomMT@plt>
movsd  -0x30(%rbp),%xmm1
movq   %rax,%xmm0
movaps 0xe9b(%rip),%xmm2
punpckldq %xmm2,%xmm0
movapd 0xe9f(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0xe70(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  0xe5c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11e9 <sample_best+0xd9>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11ee <sample_best+0xde>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <sample_best+0x2f>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sample_best>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
cmp    $0x2,%esi
jl     11b0 <sample_best+0xa0>
mov    %rdi,%r15
movsd  (%rdi),%xmm1
mov    %esi,%r14d
mov    $0x1,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <randomMT@plt>
movq   %rax,%xmm0
punpckldq 0xe9a(%rip),%xmm0
subpd  0xea2(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0xe9e(%rip),%xmm1
mulsd  0xe9e(%rip),%xmm1
addsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
ucomisd %xmm0,%xmm1
cmova  %ebx,%ebp
movsd  %xmm1,(%r15,%rbx,8)
maxsd  %xmm0,%xmm1
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <sample_best+0x30>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sample_best(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
store i32 0, i32* %8
%10 = load double*, double** %4
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
store double %12, double* %9
store i32 1, i32* %7
br label %13
13: ; preds = %46, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %49
17: ; preds = %13
%18 = load double*, double** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = call i64 (...) @randomMT()
%24 = uitofp i64 %23 to double
%25 = fdiv double %24, 0x41F0000000000000
%26 = call double @llvm.fmuladd.f64(double -1.000000e-04, double %25, double %22)
%27 = load double*, double** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
store double %26, double* %30
%31 = load double*, double** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double, double* %9
%37 = fcmp ogt double %35, %36
br i1 %37, label %38, label %45
38: ; preds = %17
%39 = load double*, double** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
store double %43, double* %9
%44 = load i32, i32* %7
store i32 %44, i32* %8
br label %45
45: ; preds = %38, %17
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %13
49: ; preds = %13
%50 = load i32, i32* %8
ret i32 %50
}

LLVM IR (-O2):
define i32 @sample_best(double* nocapture %0, i32 %1, double %2) {
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %24
5: ; preds = %3
%6 = load double, double* %0
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %5, %8
%9 = phi i64 [ 1, %5 ], [ %22, %8 ]
%10 = phi double [ %6, %5 ], [ %21, %8 ]
%11 = phi i32 [ 0, %5 ], [ %20, %8 ]
%12 = getelementptr inbounds double, double* %0, i64 %9
%13 = load double, double* %12
%14 = tail call i64 (...) @randomMT()
%15 = uitofp i64 %14 to double
%16 = fmul double %15, 0x3DF0000000000000
%17 = tail call double @llvm.fmuladd.f64(double %16, double -1.000000e-04, double %13)
store double %17, double* %12
%18 = fcmp ogt double %17, %10
%19 = trunc i64 %9 to i32
%20 = select i1 %18, i32 %19, i32 %11
%21 = select i1 %18, double %17, double %10
%22 = add nuw nsw i64 %9, 1
%23 = icmp eq i64 %22, %7
br i1 %23, label %24, label %8
24: ; preds = %8, %3
%25 = phi i32 [ 0, %3 ], [ %20, %8 ]
ret i32 %25
}