int getIndexOfMinFail(double failures[3]) {
  int index = 0;
  double val = failures[0];
  for (int i = 1; i < 3; i++) {
    if (failures[i] < val && failures[i] != -1) {
      val = failures[i];
      index = i;
    }
  }
  return index;
}


x86 assembly (clang, -O0):
<getIndexOfMinFail>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    119e <getIndexOfMinFail+0x9e>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    118b <getIndexOfMinFail+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xea2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1173 <getIndexOfMinFail+0x73>
jp     1173 <getIndexOfMinFail+0x73>
jmp    118b <getIndexOfMinFail+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1190 <getIndexOfMinFail+0x90>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1123 <getIndexOfMinFail+0x23>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIndexOfMinFail>:
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm0
ucomisd %xmm0,%xmm1
seta   %al
movsd  0xee8(%rip),%xmm2
ucomisd %xmm2,%xmm0
setp   %cl
setne  %dl
or     %cl,%dl
and    %al,%dl
movzbl %dl,%ecx
test   %cl,%cl
jne    1131 <getIndexOfMinFail+0x31>
movapd %xmm1,%xmm0
movsd  0x10(%rdi),%xmm1
ucomisd %xmm2,%xmm1
mov    $0x2,%edx
mov    %ecx,%eax
cmovne %edx,%eax
cmovp  %edx,%eax
ucomisd %xmm1,%xmm0
cmovbe %ecx,%eax
ret

LLVM IR (-O0):
define i32 @getIndexOfMinFail(double* %0) {
%2 = alloca double*
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
store double* %0, double** %2
store i32 0, i32* %3
%6 = load double*, double** %2
%7 = getelementptr inbounds double, double* %6, i64 0
%8 = load double, double* %7
store double %8, double* %4
store i32 1, i32* %5
br label %9
9: ; preds = %35, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %38
12: ; preds = %9
%13 = load double*, double** %2
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = load double, double* %4
%19 = fcmp olt double %17, %18
br i1 %19, label %20, label %34
20: ; preds = %12
%21 = load double*, double** %2
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = fcmp une double %25, -1.000000e+00
br i1 %26, label %27, label %34
27: ; preds = %20
%28 = load double*, double** %2
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
store double %32, double* %4
%33 = load i32, i32* %5
store i32 %33, i32* %3
br label %34
34: ; preds = %27, %20, %12
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %9
38: ; preds = %9
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @getIndexOfMinFail(double* nocapture %0) {
%2 = load double, double* %0
%3 = getelementptr inbounds double, double* %0, i64 1
%4 = load double, double* %3
%5 = fcmp olt double %4, %2
%6 = fcmp une double %4, -1.000000e+00
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = select i1 %7, double %4, double %2
%10 = getelementptr inbounds double, double* %0, i64 2
%11 = load double, double* %10
%12 = fcmp olt double %11, %9
%13 = fcmp une double %11, -1.000000e+00
%14 = and i1 %12, %13
%15 = select i1 %14, i32 2, i32 %8
ret i32 %15
}