#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 uint64_t;
typedef double uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(double *, double *, int);
void topCorrelations(double *correlations, uint32_t *indices,
                     uint64_t numCorrelations, double *correlations_top,
                     uint32_t *indices_top, int numTopScores) {
  for (uint64_t step = 0; step < numCorrelations - 1; ++step) {
    for (uint64_t i = 0; i < numCorrelations - step - 1; ++i) {
      if (correlations[i] < correlations[i + 1]) {
        double temp_corr = correlations[i];
        uint32_t temp_in1 = indices[2 * i];
        uint32_t temp_in2 = indices[2 * i + 1];
        correlations[i] = correlations[i + 1];
        indices[2 * i] = indices[2 * (i + 1)];
        indices[2 * i + 1] = indices[2 * (i + 1) + 1];
        correlations[i + 1] = temp_corr;
        indices[2 * (i + 1)] = temp_in1;
        indices[2 * (i + 1) + 1] = temp_in2;
      }
    }
  }
  memcpy(correlations_top, correlations, numTopScores * sizeof(double));
  memcpy(indices_top, indices, 2 * numTopScores * sizeof(uint32_t));
}


x86 assembly (clang, -O0):
<topCorrelations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12b5 <topCorrelations+0x1a5>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x30(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12a2 <topCorrelations+0x192>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    128f <topCorrelations+0x17f>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1294 <topCorrelations+0x184>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114e <topCorrelations+0x3e>
jmp    12a7 <topCorrelations+0x197>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1136 <topCorrelations+0x26>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<topCorrelations>:
push   %r15
push   %r14
push   %rbx
mov    %r9d,%r15d
mov    %r8,%r14
mov    %rsi,%rbx
mov    %rdi,%rsi
cmp    $0x2,%edx
jl     11ab <topCorrelations+0x9b>
lea    -0x1(%rdx),%r8d
xor    %r10d,%r10d
mov    %r8d,%r9d
jmp    114d <topCorrelations+0x3d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r10d
add    $0xffffffff,%r9d
cmp    %r8d,%r10d
je     11ab <topCorrelations+0x9b>
mov    %r10d,%eax
not    %eax
add    %edx,%eax
test   %eax,%eax
jle    1140 <topCorrelations+0x30>
mov    %r9d,%eax
shl    $0x3,%rax
xor    %edi,%edi
jmp    1179 <topCorrelations+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x8,%rdi
cmp    %rdi,%rax
je     1140 <topCorrelations+0x30>
movsd  (%rsi,%rdi,1),%xmm0
movsd  0x8(%rsi,%rdi,1),%xmm1
ucomisd %xmm0,%xmm1
jbe    1170 <topCorrelations+0x60>
movups (%rbx,%rdi,2),%xmm2
movsd  %xmm1,(%rsi,%rdi,1)
movupd 0x10(%rbx,%rdi,2),%xmm1
movupd %xmm1,(%rbx,%rdi,2)
movsd  %xmm0,0x8(%rsi,%rdi,1)
movups %xmm2,0x10(%rbx,%rdi,2)
jmp    1170 <topCorrelations+0x60>
lea    0x0(,%r15,8),%edx
mov    %rcx,%rdi
call   1030 <memcpy@plt>
shl    $0x4,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
define void @topCorrelations(double* %0, double* %1, i32 %2, double* %3, double* %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store i32 %2, i32* %9
store double* %3, double** %10
store double* %4, double** %11
store i32 %5, i32* %12
store i32 0, i32* %13
br label %18
18: ; preds = %125, %6
%19 = load i32, i32* %13
%20 = load i32, i32* %9
%21 = sub nsw i32 %20, 1
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %128
23: ; preds = %18
store i32 0, i32* %14
br label %24
24: ; preds = %121, %23
%25 = load i32, i32* %14
%26 = load i32, i32* %9
%27 = load i32, i32* %13
%28 = sub nsw i32 %26, %27
%29 = sub nsw i32 %28, 1
%30 = icmp slt i32 %25, %29
br i1 %30, label %31, label %124
31: ; preds = %24
%32 = load double*, double** %7
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double*, double** %7
%38 = load i32, i32* %14
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %37, i64 %40
%42 = load double, double* %41
%43 = fcmp olt double %36, %42
br i1 %43, label %44, label %120
44: ; preds = %31
%45 = load double*, double** %7
%46 = load i32, i32* %14
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
store double %49, double* %15
%50 = load double*, double** %8
%51 = load i32, i32* %14
%52 = mul nsw i32 2, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %50, i64 %53
%55 = load double, double* %54
store double %55, double* %16
%56 = load double*, double** %8
%57 = load i32, i32* %14
%58 = mul nsw i32 2, %57
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %56, i64 %60
%62 = load double, double* %61
store double %62, double* %17
%63 = load double*, double** %7
%64 = load i32, i32* %14
%65 = add nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %63, i64 %66
%68 = load double, double* %67
%69 = load double*, double** %7
%70 = load i32, i32* %14
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
store double %68, double* %72
%73 = load double*, double** %8
%74 = load i32, i32* %14
%75 = add nsw i32 %74, 1
%76 = mul nsw i32 2, %75
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %73, i64 %77
%79 = load double, double* %78
%80 = load double*, double** %8
%81 = load i32, i32* %14
%82 = mul nsw i32 2, %81
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %80, i64 %83
store double %79, double* %84
%85 = load double*, double** %8
%86 = load i32, i32* %14
%87 = add nsw i32 %86, 1
%88 = mul nsw i32 2, %87
%89 = add nsw i32 %88, 1
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %85, i64 %90
%92 = load double, double* %91
%93 = load double*, double** %8
%94 = load i32, i32* %14
%95 = mul nsw i32 2, %94
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds double, double* %93, i64 %97
store double %92, double* %98
%99 = load double, double* %15
%100 = load double*, double** %7
%101 = load i32, i32* %14
%102 = add nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %100, i64 %103
store double %99, double* %104
%105 = load double, double* %16
%106 = load double*, double** %8
%107 = load i32, i32* %14
%108 = add nsw i32 %107, 1
%109 = mul nsw i32 2, %108
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds double, double* %106, i64 %110
store double %105, double* %111
%112 = load double, double* %17
%113 = load double*, double** %8
%114 = load i32, i32* %14
%115 = add nsw i32 %114, 1
%116 = mul nsw i32 2, %115
%117 = add nsw i32 %116, 1
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds double, double* %113, i64 %118
store double %112, double* %119
br label %120
120: ; preds = %44, %31
br label %121
121: ; preds = %120
%122 = load i32, i32* %14
%123 = add nsw i32 %122, 1
store i32 %123, i32* %14
br label %24
124: ; preds = %24
br label %125
125: ; preds = %124
%126 = load i32, i32* %13
%127 = add nsw i32 %126, 1
store i32 %127, i32* %13
br label %18
128: ; preds = %18
%129 = load double*, double** %10
%130 = load double*, double** %7
%131 = load i32, i32* %12
%132 = sext i32 %131 to i64
%133 = mul i64 %132, 8
%134 = trunc i64 %133 to i32
%135 = call i32 @memcpy(double* %129, double* %130, i32 %134)
%136 = load double*, double** %11
%137 = load double*, double** %8
%138 = load i32, i32* %12
%139 = mul nsw i32 2, %138
%140 = sext i32 %139 to i64
%141 = mul i64 %140, 8
%142 = trunc i64 %141 to i32
%143 = call i32 @memcpy(double* %136, double* %137, i32 %142)
ret void
}

LLVM IR (-O2):
define void @topCorrelations(double* %0, double* %1, i32 %2, double* %3, double* %4, i32 %5) {
%7 = add i32 %2, -1
%8 = icmp sgt i32 %2, 1
br i1 %8, label %9, label %17
9: ; preds = %6, %22
%10 = phi i32 [ %24, %22 ], [ %7, %6 ]
%11 = phi i32 [ %23, %22 ], [ 0, %6 ]
%12 = xor i32 %11, -1
%13 = add i32 %12, %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %9
%16 = zext i32 %10 to i64
br label %26
17: ; preds = %22, %6
%18 = shl i32 %5, 3
%19 = tail call i32 @memcpy(double* %3, double* %0, i32 %18)
%20 = shl i32 %5, 4
%21 = tail call i32 @memcpy(double* %4, double* %1, i32 %20)
ret void
22: ; preds = %45, %9
%23 = add nuw nsw i32 %11, 1
%24 = add i32 %10, -1
%25 = icmp eq i32 %23, %7
br i1 %25, label %17, label %9
26: ; preds = %15, %45
%27 = phi i64 [ 0, %15 ], [ %30, %45 ]
%28 = getelementptr inbounds double, double* %0, i64 %27
%29 = load double, double* %28
%30 = add nuw nsw i64 %27, 1
%31 = getelementptr inbounds double, double* %0, i64 %30
%32 = load double, double* %31
%33 = fcmp olt double %29, %32
br i1 %33, label %34, label %45
34: ; preds = %26
%35 = shl nuw nsw i64 %27, 1
%36 = getelementptr inbounds double, double* %1, i64 %35
%37 = bitcast double* %36 to <2 x double>*
%38 = load <2 x double>, <2 x double>* %37
store double %32, double* %28
%39 = shl nuw nsw i64 %30, 1
%40 = getelementptr inbounds double, double* %1, i64 %39
%41 = bitcast double* %40 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = bitcast double* %36 to <2 x double>*
store <2 x double> %42, <2 x double>* %43
store double %29, double* %31
%44 = bitcast double* %40 to <2 x double>*
store <2 x double> %38, <2 x double>* %44
br label %45
45: ; preds = %26, %34
%46 = icmp eq i64 %30, %16
br i1 %46, label %22, label %26
}