int compareDownReal(void *arg, const void *v1, const void *v2) {
  double *prevCol = (double *)arg;
  int e1 = *(const int *)v1;
  int e2 = *(const int *)v2;
  double a = prevCol[e1];
  double b = prevCol[e2];
  if (a > b)
    return -1;
  else if (b > a)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<compareDownReal>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    116a <compareDownReal+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <compareDownReal+0x92>
movsd  -0x40(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1186 <compareDownReal+0x86>
movl   $0x1,-0x4(%rbp)
jmp    1192 <compareDownReal+0x92>
jmp    118b <compareDownReal+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<compareDownReal>:
movslq (%rsi),%rax
movslq (%rdx),%rcx
movsd  (%rdi,%rax,8),%xmm0
movsd  (%rdi,%rcx,8),%xmm1
xor    %ecx,%ecx
ucomisd %xmm0,%xmm1
seta   %cl
ucomisd %xmm1,%xmm0
mov    $0xffffffff,%eax
cmovbe %ecx,%eax
ret

LLVM IR (-O0):
define i32 @compareDownReal(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%13 = load i8*, i8** %5
%14 = bitcast i8* %13 to double*
store double* %14, double** %8
%15 = load i8*, i8** %6
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
store i32 %17, i32* %9
%18 = load i8*, i8** %7
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
store i32 %20, i32* %10
%21 = load double*, double** %8
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
store double %25, double* %11
%26 = load double*, double** %8
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
store double %30, double* %12
%31 = load double, double* %11
%32 = load double, double* %12
%33 = fcmp ogt double %31, %32
br i1 %33, label %34, label %35
34: ; preds = %3
store i32 -1, i32* %4
br label %42
35: ; preds = %3
%36 = load double, double* %12
%37 = load double, double* %11
%38 = fcmp ogt double %36, %37
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* %4
br label %42
40: ; preds = %35
br label %41
41: ; preds = %40
store i32 0, i32* %4
br label %42
42: ; preds = %41, %39, %34
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
define i32 @compareDownReal(i8* nocapture %0, i8* nocapture %1, i8* nocapture %2) {
%4 = bitcast i8* %0 to double*
%5 = bitcast i8* %1 to i32*
%6 = load i32, i32* %5
%7 = bitcast i8* %2 to i32*
%8 = load i32, i32* %7
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds double, double* %4, i64 %9
%11 = load double, double* %10
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds double, double* %4, i64 %12
%14 = load double, double* %13
%15 = fcmp ogt double %11, %14
%16 = fcmp ogt double %14, %11
%17 = zext i1 %16 to i32
%18 = select i1 %15, i32 -1, i32 %17
ret i32 %18
}