#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 */
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
double mean(int, double *, double *);
int /*<<< orphan*/ mysort3(int, double *, double *, double *);
int /*<<< orphan*/ mysort4(int, double *, double *, double *, double *);
double sqrt(double);
int purge_bad(int *k, double *x, double *y, double *ysig, double a, double b,
              double max_sig, int use_sig) {
  int i, j;
  int numbad = 0;
  double stdval = 0.0;
  double *sigsqr;
  sigsqr = (double *)malloc((*k) * sizeof(double));
  if (!use_sig) {
    for (i = 0; i < *k; i++)
      sigsqr[i] = (y[i] - (a * x[i]) - b) * (y[i] - (a * x[i]) - b);
    stdval = sqrt(mean(*k, sigsqr, ysig));
    for (i = 0; i < *k; i++)
      sigsqr[i] = sqrt(sigsqr[i]) / stdval;
    mysort3(*k, sigsqr, x, y);
  } else {
    for (i = 0; i < *k; i++)
      sigsqr[i] =
          sqrt((y[i] - (a * x[i]) - b) * (y[i] - (a * x[i]) - b)) / ysig[i];
    mysort4(*k, sigsqr, x, y, ysig);
  }
  j = 0;
  while (sigsqr[j] < max_sig) {
    j++;
    if (j == *k)
      break;
  }
  numbad = *k - j;
  *k = j;
  free(sigsqr);
  return (numbad);
}


x86 assembly (clang, -O0):
<purge_bad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
movsd  %xmm2,-0x38(%rbp)
mov    %r8d,-0x3c(%rbp)
movl   $0x0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    12f6 <purge_bad+0x196>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    1275 <purge_bad+0x115>
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x58(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11c1 <purge_bad+0x61>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <mean@plt>
call   1080 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    12da <purge_bad+0x17a>
mov    -0x58(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1080 <sqrt@plt>
divsd  -0x50(%rbp),%xmm0
mov    -0x58(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1299 <purge_bad+0x139>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <mysort3@plt>
jmp    13de <purge_bad+0x27e>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    13c3 <purge_bad+0x263>
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1080 <sqrt@plt>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x58(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12fd <purge_bad+0x19d>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <mysort4@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x58(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1423 <purge_bad+0x2c3>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jne    141e <purge_bad+0x2be>
jmp    1423 <purge_bad+0x2c3>
jmp    13e5 <purge_bad+0x285>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<purge_bad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%ebx
movsd  %xmm2,0x18(%rsp)
movapd %xmm1,0x20(%rsp)
movapd %xmm0,(%rsp)
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    (%rdi),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    (%r14),%edi
test   %ebx,%ebx
je     1237 <purge_bad+0xd7>
test   %edi,%edi
jle    1221 <purge_bad+0xc1>
movapd (%rsp),%xmm2
xorpd  0xe49(%rip),%xmm2
xor    %ebx,%ebx
xorpd  %xmm3,%xmm3
movapd 0x20(%rsp),%xmm1
movapd %xmm2,(%rsp)
jmp    11fd <purge_bad+0x9d>
nopw   0x0(%rax,%rax,1)
call   1080 <sqrt@plt>
xorpd  %xmm3,%xmm3
movapd (%rsp),%xmm2
movapd 0x20(%rsp),%xmm1
divsd  0x0(%r13,%rbx,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
movslq (%r14),%rdi
cmp    %rdi,%rbx
jge    1221 <purge_bad+0xc1>
movsd  (%r12,%rbx,8),%xmm0
mulsd  %xmm2,%xmm0
addsd  (%r15,%rbx,8),%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jb     11d0 <purge_bad+0x70>
sqrtsd %xmm0,%xmm0
jmp    11e4 <purge_bad+0x84>
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1040 <mysort4@plt>
jmp    1424 <purge_bad+0x2c4>
test   %edi,%edi
movapd 0x20(%rsp),%xmm6
movapd (%rsp),%xmm7
jle    1397 <purge_bad+0x237>
xorpd  0xdae(%rip),%xmm7
cmp    $0x4,%edi
jae    125e <purge_bad+0xfe>
xor    %eax,%eax
jmp    1318 <purge_bad+0x1b8>
lea    0x0(,%rdi,8),%rax
add    %rbp,%rax
lea    (%r15,%rdi,8),%rcx
cmp    %rcx,%rbp
setb   %bl
cmp    %r15,%rax
seta   %dl
lea    (%r12,%rdi,8),%rcx
cmp    %rcx,%rbp
setb   %cl
cmp    %r12,%rax
seta   %sil
xor    %eax,%eax
test   %dl,%bl
jne    1318 <purge_bad+0x1b8>
and    %sil,%cl
jne    1318 <purge_bad+0x1b8>
mov    %edi,%eax
and    $0xfffffffc,%eax
movapd %xmm7,%xmm0
unpcklpd %xmm7,%xmm0
movapd %xmm6,%xmm1
unpcklpd %xmm6,%xmm1
lea    0x0(,%rdi,8),%rcx
and    $0xffffffffffffffe0,%rcx
xor    %edx,%edx
movupd (%r15,%rdx,1),%xmm2
movupd 0x10(%r15,%rdx,1),%xmm3
movupd (%r12,%rdx,1),%xmm4
movupd 0x10(%r12,%rdx,1),%xmm5
mulpd  %xmm0,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm0,%xmm5
addpd  %xmm3,%xmm5
subpd  %xmm1,%xmm4
subpd  %xmm1,%xmm5
mulpd  %xmm4,%xmm4
mulpd  %xmm5,%xmm5
movupd %xmm4,0x0(%rbp,%rdx,1)
movupd %xmm5,0x10(%rbp,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%rcx
jne    12c0 <purge_bad+0x160>
cmp    %rdi,%rax
je     1397 <purge_bad+0x237>
mov    %rax,%rcx
not    %rcx
test   $0x1,%dil
je     1346 <purge_bad+0x1e6>
movsd  (%r12,%rax,8),%xmm0
mulsd  %xmm7,%xmm0
addsd  (%r15,%rax,8),%xmm0
subsd  %xmm6,%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x0(%rbp,%rax,8)
or     $0x1,%rax
add    %rdi,%rcx
je     1397 <purge_bad+0x237>
nopl   0x0(%rax,%rax,1)
movsd  (%r12,%rax,8),%xmm0
mulsd  %xmm7,%xmm0
addsd  (%r15,%rax,8),%xmm0
subsd  %xmm6,%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x0(%rbp,%rax,8)
movsd  0x8(%r12,%rax,8),%xmm0
mulsd  %xmm7,%xmm0
addsd  0x8(%r15,%rax,8),%xmm0
subsd  %xmm6,%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rbp,%rax,8)
add    $0x2,%rax
cmp    %rax,%rdi
jne    1350 <purge_bad+0x1f0>
mov    %rbp,%rsi
mov    %r13,%rdx
call   1070 <mean@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     13b5 <purge_bad+0x255>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    13be <purge_bad+0x25e>
call   1080 <sqrt@plt>
movapd %xmm0,%xmm1
mov    (%r14),%edi
test   %edi,%edi
jle    1416 <purge_bad+0x2b6>
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
movsd  %xmm1,(%rsp)
jmp    1404 <purge_bad+0x2a4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1080 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  (%rsp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
movslq (%r14),%rdi
cmp    %rdi,%rbx
jge    1416 <purge_bad+0x2b6>
movsd  0x0(%rbp,%rbx,8),%xmm0
ucomisd %xmm2,%xmm0
jb     13e0 <purge_bad+0x280>
sqrtsd %xmm0,%xmm0
jmp    13ee <purge_bad+0x28e>
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1050 <mysort3@plt>
movsd  0x18(%rsp),%xmm0
xor    %eax,%eax
nopl   0x0(%rax)
ucomisd 0x0(%rbp,%rax,8),%xmm0
jbe    1446 <purge_bad+0x2e6>
add    $0x1,%rax
mov    (%r14),%ebx
cmp    %rbx,%rax
jne    1430 <purge_bad+0x2d0>
jmp    1449 <purge_bad+0x2e9>
mov    (%r14),%ebx
sub    %eax,%ebx
mov    %eax,(%r14)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @purge_bad(i32* %0, double* %1, double* %2, double* %3, double %4, double %5, double %6, i32 %7) {
%9 = alloca i32*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double*
store i32* %0, i32** %9
store double* %1, double** %10
store double* %2, double** %11
store double* %3, double** %12
store double %4, double* %13
store double %5, double* %14
store double %6, double* %15
store i32 %7, i32* %16
store i32 0, i32* %19
store double 0.000000e+00, double* %20
%22 = load i32*, i32** %9
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to double*
store double* %28, double** %21
%29 = load i32, i32* %16
%30 = icmp ne i32 %29, 0
br i1 %30, label %111, label %31
31: ; preds = %8
store i32 0, i32* %17
br label %32
32: ; preds = %73, %31
%33 = load i32, i32* %17
%34 = load i32*, i32** %9
%35 = load i32, i32* %34
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %76
37: ; preds = %32
%38 = load double*, double** %11
%39 = load i32, i32* %17
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double, double* %13
%44 = load double*, double** %10
%45 = load i32, i32* %17
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = fneg double %43
%50 = call double @llvm.fmuladd.f64(double %49, double %48, double %42)
%51 = load double, double* %14
%52 = fsub double %50, %51
%53 = load double*, double** %11
%54 = load i32, i32* %17
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = load double, double* %13
%59 = load double*, double** %10
%60 = load i32, i32* %17
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = fneg double %58
%65 = call double @llvm.fmuladd.f64(double %64, double %63, double %57)
%66 = load double, double* %14
%67 = fsub double %65, %66
%68 = fmul double %52, %67
%69 = load double*, double** %21
%70 = load i32, i32* %17
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
store double %68, double* %72
br label %73
73: ; preds = %37
%74 = load i32, i32* %17
%75 = add nsw i32 %74, 1
store i32 %75, i32* %17
br label %32
76: ; preds = %32
%77 = load i32*, i32** %9
%78 = load i32, i32* %77
%79 = load double*, double** %21
%80 = load double*, double** %12
%81 = call double @mean(i32 %78, double* %79, double* %80)
%82 = call double @sqrt(double %81)
store double %82, double* %20
store i32 0, i32* %17
br label %83
83: ; preds = %101, %76
%84 = load i32, i32* %17
%85 = load i32*, i32** %9
%86 = load i32, i32* %85
%87 = icmp slt i32 %84, %86
br i1 %87, label %88, label %104
88: ; preds = %83
%89 = load double*, double** %21
%90 = load i32, i32* %17
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds double, double* %89, i64 %91
%93 = load double, double* %92
%94 = call double @sqrt(double %93)
%95 = load double, double* %20
%96 = fdiv double %94, %95
%97 = load double*, double** %21
%98 = load i32, i32* %17
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %97, i64 %99
store double %96, double* %100
br label %101
101: ; preds = %88
%102 = load i32, i32* %17
%103 = add nsw i32 %102, 1
store i32 %103, i32* %17
br label %83
104: ; preds = %83
%105 = load i32*, i32** %9
%106 = load i32, i32* %105
%107 = load double*, double** %21
%108 = load double*, double** %10
%109 = load double*, double** %11
%110 = call i32 @mysort3(i32 %106, double* %107, double* %108, double* %109)
br label %171
111: ; preds = %8
store i32 0, i32* %17
br label %112
112: ; preds = %160, %111
%113 = load i32, i32* %17
%114 = load i32*, i32** %9
%115 = load i32, i32* %114
%116 = icmp slt i32 %113, %115
br i1 %116, label %117, label %163
117: ; preds = %112
%118 = load double*, double** %11
%119 = load i32, i32* %17
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds double, double* %118, i64 %120
%122 = load double, double* %121
%123 = load double, double* %13
%124 = load double*, double** %10
%125 = load i32, i32* %17
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds double, double* %124, i64 %126
%128 = load double, double* %127
%129 = fneg double %123
%130 = call double @llvm.fmuladd.f64(double %129, double %128, double %122)
%131 = load double, double* %14
%132 = fsub double %130, %131
%133 = load double*, double** %11
%134 = load i32, i32* %17
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds double, double* %133, i64 %135
%137 = load double, double* %136
%138 = load double, double* %13
%139 = load double*, double** %10
%140 = load i32, i32* %17
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double, double* %139, i64 %141
%143 = load double, double* %142
%144 = fneg double %138
%145 = call double @llvm.fmuladd.f64(double %144, double %143, double %137)
%146 = load double, double* %14
%147 = fsub double %145, %146
%148 = fmul double %132, %147
%149 = call double @sqrt(double %148)
%150 = load double*, double** %12
%151 = load i32, i32* %17
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds double, double* %150, i64 %152
%154 = load double, double* %153
%155 = fdiv double %149, %154
%156 = load double*, double** %21
%157 = load i32, i32* %17
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds double, double* %156, i64 %158
store double %155, double* %159
br label %160
160: ; preds = %117
%161 = load i32, i32* %17
%162 = add nsw i32 %161, 1
store i32 %162, i32* %17
br label %112
163: ; preds = %112
%164 = load i32*, i32** %9
%165 = load i32, i32* %164
%166 = load double*, double** %21
%167 = load double*, double** %10
%168 = load double*, double** %11
%169 = load double*, double** %12
%170 = call i32 @mysort4(i32 %165, double* %166, double* %167, double* %168, double* %169)
br label %171
171: ; preds = %163, %104
store i32 0, i32* %18
br label %172
172: ; preds = %188, %171
%173 = load double*, double** %21
%174 = load i32, i32* %18
%175 = sext i32 %174 to i64
%176 = getelementptr inbounds double, double* %173, i64 %175
%177 = load double, double* %176
%178 = load double, double* %15
%179 = fcmp olt double %177, %178
br i1 %179, label %180, label %189
180: ; preds = %172
%181 = load i32, i32* %18
%182 = add nsw i32 %181, 1
store i32 %182, i32* %18
%183 = load i32, i32* %18
%184 = load i32*, i32** %9
%185 = load i32, i32* %184
%186 = icmp eq i32 %183, %185
br i1 %186, label %187, label %188
187: ; preds = %180
br label %189
188: ; preds = %180
br label %172
189: ; preds = %187, %172
%190 = load i32*, i32** %9
%191 = load i32, i32* %190
%192 = load i32, i32* %18
%193 = sub nsw i32 %191, %192
store i32 %193, i32* %19
%194 = load i32, i32* %18
%195 = load i32*, i32** %9
store i32 %194, i32* %195
%196 = load double*, double** %21
%197 = call i32 @free(double* %196)
%198 = load i32, i32* %19
ret i32 %198
}

LLVM IR (-O2):
define i32 @purge_bad(i32* nocapture %0, double* %1, double* %2, double* %3, double %4, double %5, double %6, i32 %7) {
%9 = load i32, i32* %0
%10 = shl i32 %9, 3
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to double*
%13 = inttoptr i64 %11 to i8*
%14 = icmp eq i32 %7, 0
%15 = load i32, i32* %0
%16 = icmp sgt i32 %15, 0
br i1 %14, label %20, label %17
17: ; preds = %8
br i1 %16, label %18, label %152
18: ; preds = %17
%19 = fneg double %4
br label %134
20: ; preds = %8
br i1 %16, label %21, label %116
21: ; preds = %20
%22 = fneg double %4
%23 = zext i32 %15 to i64
%24 = icmp ult i32 %15, 4
br i1 %24, label %76, label %25
25: ; preds = %21
%26 = getelementptr double, double* %12, i64 %23
%27 = getelementptr double, double* %2, i64 %23
%28 = bitcast double* %27 to i8*
%29 = getelementptr double, double* %1, i64 %23
%30 = bitcast double* %29 to i8*
%31 = icmp ult i8* %13, %28
%32 = icmp ugt double* %26, %2
%33 = and i1 %31, %32
%34 = icmp ult i8* %13, %30
%35 = icmp ugt double* %26, %1
%36 = and i1 %34, %35
%37 = or i1 %33, %36
br i1 %37, label %76, label %38
38: ; preds = %25
%39 = and i64 %23, 4294967292
%40 = insertelement <2 x double> poison, double %22, i64 0
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
%42 = insertelement <2 x double> poison, double %22, i64 0
%43 = shufflevector <2 x double> %42, <2 x double> poison, <2 x i32> zeroinitializer
%44 = insertelement <2 x double> poison, double %5, i64 0
%45 = shufflevector <2 x double> %44, <2 x double> poison, <2 x i32> zeroinitializer
%46 = insertelement <2 x double> poison, double %5, i64 0
%47 = shufflevector <2 x double> %46, <2 x double> poison, <2 x i32> zeroinitializer
br label %48
48: ; preds = %48, %38
%49 = phi i64 [ 0, %38 ], [ %72, %48 ]
%50 = getelementptr inbounds double, double* %2, i64 %49
%51 = bitcast double* %50 to <2 x double>*
%52 = load <2 x double>, <2 x double>* %51
%53 = getelementptr inbounds double, double* %50, i64 2
%54 = bitcast double* %53 to <2 x double>*
%55 = load <2 x double>, <2 x double>* %54
%56 = getelementptr inbounds double, double* %1, i64 %49
%57 = bitcast double* %56 to <2 x double>*
%58 = load <2 x double>, <2 x double>* %57
%59 = getelementptr inbounds double, double* %56, i64 2
%60 = bitcast double* %59 to <2 x double>*
%61 = load <2 x double>, <2 x double>* %60
%62 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %41, <2 x double> %58, <2 x double> %52)
%63 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %43, <2 x double> %61, <2 x double> %55)
%64 = fsub <2 x double> %62, %45
%65 = fsub <2 x double> %63, %47
%66 = fmul <2 x double> %64, %64
%67 = fmul <2 x double> %65, %65
%68 = getelementptr inbounds double, double* %12, i64 %49
%69 = bitcast double* %68 to <2 x double>*
store <2 x double> %66, <2 x double>* %69
%70 = getelementptr inbounds double, double* %68, i64 2
%71 = bitcast double* %70 to <2 x double>*
store <2 x double> %67, <2 x double>* %71
%72 = add nuw i64 %49, 4
%73 = icmp eq i64 %72, %39
br i1 %73, label %74, label %48
74: ; preds = %48
%75 = icmp eq i64 %39, %23
br i1 %75, label %116, label %76
76: ; preds = %25, %21, %74
%77 = phi i64 [ 0, %25 ], [ 0, %21 ], [ %39, %74 ]
%78 = xor i64 %77, -1
%79 = and i64 %23, 1
%80 = icmp eq i64 %79, 0
br i1 %80, label %91, label %81
81: ; preds = %76
%82 = getelementptr inbounds double, double* %2, i64 %77
%83 = load double, double* %82
%84 = getelementptr inbounds double, double* %1, i64 %77
%85 = load double, double* %84
%86 = tail call double @llvm.fmuladd.f64(double %22, double %85, double %83)
%87 = fsub double %86, %5
%88 = fmul double %87, %87
%89 = getelementptr inbounds double, double* %12, i64 %77
store double %88, double* %89
%90 = or i64 %77, 1
br label %91
91: ; preds = %81, %76
%92 = phi i64 [ %77, %76 ], [ %90, %81 ]
%93 = sub nsw i64 0, %23
%94 = icmp eq i64 %78, %93
br i1 %94, label %116, label %95
95: ; preds = %91, %95
%96 = phi i64 [ %114, %95 ], [ %92, %91 ]
%97 = getelementptr inbounds double, double* %2, i64 %96
%98 = load double, double* %97
%99 = getelementptr inbounds double, double* %1, i64 %96
%100 = load double, double* %99
%101 = tail call double @llvm.fmuladd.f64(double %22, double %100, double %98)
%102 = fsub double %101, %5
%103 = fmul double %102, %102
%104 = getelementptr inbounds double, double* %12, i64 %96
store double %103, double* %104
%105 = add nuw nsw i64 %96, 1
%106 = getelementptr inbounds double, double* %2, i64 %105
%107 = load double, double* %106
%108 = getelementptr inbounds double, double* %1, i64 %105
%109 = load double, double* %108
%110 = tail call double @llvm.fmuladd.f64(double %22, double %109, double %107)
%111 = fsub double %110, %5
%112 = fmul double %111, %111
%113 = getelementptr inbounds double, double* %12, i64 %105
store double %112, double* %113
%114 = add nuw nsw i64 %96, 2
%115 = icmp eq i64 %114, %23
br i1 %115, label %116, label %95
116: ; preds = %91, %95, %74, %20
%117 = tail call double @mean(i32 %15, double* %12, double* %3)
%118 = tail call double @sqrt(double %117)
%119 = load i32, i32* %0
%120 = icmp sgt i32 %119, 0
br i1 %120, label %121, label %131
121: ; preds = %116, %121
%122 = phi i64 [ %127, %121 ], [ 0, %116 ]
%123 = getelementptr inbounds double, double* %12, i64 %122
%124 = load double, double* %123
%125 = tail call double @sqrt(double %124)
%126 = fdiv double %125, %118
store double %126, double* %123
%127 = add nuw nsw i64 %122, 1
%128 = load i32, i32* %0
%129 = sext i32 %128 to i64
%130 = icmp slt i64 %127, %129
br i1 %130, label %121, label %131
131: ; preds = %121, %116
%132 = phi i32 [ %119, %116 ], [ %128, %121 ]
%133 = tail call i32 @mysort3(i32 %132, double* %12, double* %1, double* %2)
br label %155
134: ; preds = %18, %134
%135 = phi i64 [ 0, %18 ], [ %148, %134 ]
%136 = getelementptr inbounds double, double* %2, i64 %135
%137 = load double, double* %136
%138 = getelementptr inbounds double, double* %1, i64 %135
%139 = load double, double* %138
%140 = tail call double @llvm.fmuladd.f64(double %19, double %139, double %137)
%141 = fsub double %140, %5
%142 = fmul double %141, %141
%143 = tail call double @sqrt(double %142)
%144 = getelementptr inbounds double, double* %3, i64 %135
%145 = load double, double* %144
%146 = fdiv double %143, %145
%147 = getelementptr inbounds double, double* %12, i64 %135
store double %146, double* %147
%148 = add nuw nsw i64 %135, 1
%149 = load i32, i32* %0
%150 = sext i32 %149 to i64
%151 = icmp slt i64 %148, %150
br i1 %151, label %134, label %152
152: ; preds = %134, %17
%153 = phi i32 [ %15, %17 ], [ %149, %134 ]
%154 = tail call i32 @mysort4(i32 %153, double* %12, double* %1, double* %2, double* %3)
br label %155
155: ; preds = %152, %131
br label %156
156: ; preds = %155, %163
%157 = phi i64 [ %164, %163 ], [ 0, %155 ]
%158 = getelementptr inbounds double, double* %12, i64 %157
%159 = load double, double* %158
%160 = fcmp olt double %159, %6
br i1 %160, label %163, label %161
161: ; preds = %156
%162 = load i32, i32* %0
br label %168
163: ; preds = %156
%164 = add nuw i64 %157, 1
%165 = load i32, i32* %0
%166 = zext i32 %165 to i64
%167 = icmp eq i64 %164, %166
br i1 %167, label %168, label %156
168: ; preds = %163, %161
%169 = phi i32 [ %162, %161 ], [ %165, %163 ]
%170 = phi i64 [ %157, %161 ], [ %164, %163 ]
%171 = trunc i64 %170 to i32
%172 = sub nsw i32 %169, %171
store i32 %171, i32* %0
%173 = tail call i32 @free(double* %12)
ret i32 %172
}