void Median_Filter(double *input, double *output, int length) {
  unsigned char i = 0;
  unsigned char j = 0;
  unsigned char k = 0;
  unsigned char min = 0;
  double Temp;
  for (i = 2; i < length - 2; ++i) {
    double windows[5];
    for (j = 0; j < 5; ++j)
      windows[j] = input[i - 2 + j];
    for (j = 0; j < 3; ++j) {
      min = j;
      for (k = j + 1; k < 5; ++k)
        if (windows[k] < windows[min])
          min = k;
      Temp = windows[j];
      windows[j] = windows[min];
      windows[min] = Temp;
    }
    output[i - 2] = windows[2];
  }
}


x86 assembly (clang, -O0):
<Median_Filter>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movb   $0x0,-0x16(%rbp)
movb   $0x0,-0x17(%rbp)
movb   $0x0,-0x18(%rbp)
movb   $0x2,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    123e <Median_Filter+0x13e>
movb   $0x0,-0x16(%rbp)
movzbl -0x16(%rbp),%eax
cmp    $0x5,%eax
jge    1176 <Median_Filter+0x76>
mov    -0x8(%rbp),%rax
movzbl -0x15(%rbp),%ecx
sub    $0x2,%ecx
movzbl -0x16(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movzbl -0x16(%rbp),%eax
movsd  %xmm0,-0x50(%rbp,%rax,8)
mov    -0x16(%rbp),%al
add    $0x1,%al
mov    %al,-0x16(%rbp)
jmp    1139 <Median_Filter+0x39>
movb   $0x0,-0x16(%rbp)
movzbl -0x16(%rbp),%eax
cmp    $0x3,%eax
jge    1219 <Median_Filter+0x119>
mov    -0x16(%rbp),%al
mov    %al,-0x18(%rbp)
movzbl -0x16(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x17(%rbp)
movzbl -0x17(%rbp),%eax
cmp    $0x5,%eax
jge    11da <Median_Filter+0xda>
movzbl -0x17(%rbp),%eax
movsd  -0x50(%rbp,%rax,8),%xmm1
movzbl -0x18(%rbp),%eax
movsd  -0x50(%rbp,%rax,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c8 <Median_Filter+0xc8>
mov    -0x17(%rbp),%al
mov    %al,-0x18(%rbp)
jmp    11cd <Median_Filter+0xcd>
mov    -0x17(%rbp),%al
add    $0x1,%al
mov    %al,-0x17(%rbp)
jmp    1197 <Median_Filter+0x97>
movzbl -0x16(%rbp),%eax
movsd  -0x50(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
movzbl -0x18(%rbp),%eax
movsd  -0x50(%rbp,%rax,8),%xmm0
movzbl -0x16(%rbp),%eax
movsd  %xmm0,-0x50(%rbp,%rax,8)
movsd  -0x20(%rbp),%xmm0
movzbl -0x18(%rbp),%eax
movsd  %xmm0,-0x50(%rbp,%rax,8)
mov    -0x16(%rbp),%al
add    $0x1,%al
mov    %al,-0x16(%rbp)
jmp    117a <Median_Filter+0x7a>
movsd  -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movzbl -0x15(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x15(%rbp),%al
add    $0x1,%al
mov    %al,-0x15(%rbp)
jmp    1123 <Median_Filter+0x23>
pop    %rbp
ret

x86 assembly (clang, -O2):
<Median_Filter>:
cmp    $0x5,%edx
jl     126d <Median_Filter+0x16d>
add    $0xfffffffe,%edx
add    $0xfffffffffffffff0,%rdi
mov    $0x2,%eax
jmp    1151 <Median_Filter+0x51>
nopw   0x0(%rax,%rax,1)
movsd  -0x28(%rsp,%r9,8),%xmm1
movsd  %xmm1,-0x18(%rsp)
movsd  %xmm0,-0x28(%rsp,%r9,8)
movsd  -0x18(%rsp),%xmm0
movslq %eax,%rcx
movsd  %xmm0,-0x10(%rsi,%rcx,8)
add    $0x1,%eax
movzbl %al,%eax
cmp    %eax,%edx
jle    126d <Median_Filter+0x16d>
mov    %eax,%ecx
movups (%rdi,%rcx,8),%xmm0
movups 0x10(%rdi,%rcx,8),%xmm1
movaps %xmm0,-0x28(%rsp)
mov    0x20(%rdi,%rcx,8),%rcx
mov    %rcx,-0x8(%rsp)
movaps %xmm1,-0x18(%rsp)
movsd  -0x28(%rsp),%xmm0
xor    %ecx,%ecx
ucomisd -0x20(%rsp),%xmm0
seta   %cl
movsd  -0x28(%rsp,%rcx,8),%xmm1
ucomisd -0x18(%rsp),%xmm1
mov    $0x2,%r9d
ja     1198 <Median_Filter+0x98>
mov    %ecx,%r9d
movzbl %r9b,%ecx
movsd  -0x28(%rsp,%rcx,8),%xmm1
ucomisd -0x10(%rsp),%xmm1
mov    $0x3,%r8d
mov    $0x3,%ecx
ja     11b8 <Median_Filter+0xb8>
mov    %r9d,%ecx
movzbl %cl,%r10d
movsd  -0x28(%rsp,%r10,8),%xmm1
ucomisd -0x8(%rsp),%xmm1
mov    $0x4,%r9d
mov    $0x4,%ecx
ja     11d9 <Median_Filter+0xd9>
mov    %r10,%rcx
movsd  -0x28(%rsp,%rcx,8),%xmm1
movsd  %xmm1,-0x28(%rsp)
movsd  %xmm0,-0x28(%rsp,%rcx,8)
movsd  -0x20(%rsp),%xmm0
xor    %ecx,%ecx
ucomisd -0x18(%rsp),%xmm0
seta   %cl
movsd  -0x20(%rsp,%rcx,8),%xmm1
ucomisd -0x10(%rsp),%xmm1
ja     1211 <Median_Filter+0x111>
add    $0x1,%cl
movzbl %cl,%r8d
movzbl %r8b,%r8d
movsd  -0x28(%rsp,%r8,8),%xmm1
ucomisd -0x8(%rsp),%xmm1
mov    $0x4,%ecx
ja     122c <Median_Filter+0x12c>
mov    %r8,%rcx
movsd  -0x28(%rsp,%rcx,8),%xmm1
movsd  %xmm1,-0x20(%rsp)
movsd  %xmm0,-0x28(%rsp,%rcx,8)
movsd  -0x18(%rsp),%xmm0
xor    %ecx,%ecx
ucomisd -0x10(%rsp),%xmm0
seta   %cl
movsd  -0x18(%rsp,%rcx,8),%xmm1
ucomisd -0x8(%rsp),%xmm1
ja     1120 <Median_Filter+0x20>
or     $0x2,%rcx
mov    %rcx,%r9
jmp    1120 <Median_Filter+0x20>
ret

LLVM IR (-O0):
define void @Median_Filter(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca double
%12 = alloca [5 x double]
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i8 0, i8* %7
store i8 0, i8* %8
store i8 0, i8* %9
store i8 0, i8* %10
store i8 2, i8* %7
br label %13
13: ; preds = %100, %3
%14 = load i8, i8* %7
%15 = zext i8 %14 to i32
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 2
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %103
19: ; preds = %13
store i8 0, i8* %8
br label %20
20: ; preds = %38, %19
%21 = load i8, i8* %8
%22 = zext i8 %21 to i32
%23 = icmp slt i32 %22, 5
br i1 %23, label %24, label %41
24: ; preds = %20
%25 = load double*, double** %4
%26 = load i8, i8* %7
%27 = zext i8 %26 to i32
%28 = sub nsw i32 %27, 2
%29 = load i8, i8* %8
%30 = zext i8 %29 to i32
%31 = add nsw i32 %28, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %25, i64 %32
%34 = load double, double* %33
%35 = load i8, i8* %8
%36 = zext i8 %35 to i64
%37 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 %36
store double %34, double* %37
br label %38
38: ; preds = %24
%39 = load i8, i8* %8
%40 = add i8 %39, 1
store i8 %40, i8* %8
br label %20
41: ; preds = %20
store i8 0, i8* %8
br label %42
42: ; preds = %88, %41
%43 = load i8, i8* %8
%44 = zext i8 %43 to i32
%45 = icmp slt i32 %44, 3
br i1 %45, label %46, label %91
46: ; preds = %42
%47 = load i8, i8* %8
store i8 %47, i8* %10
%48 = load i8, i8* %8
%49 = zext i8 %48 to i32
%50 = add nsw i32 %49, 1
%51 = trunc i32 %50 to i8
store i8 %51, i8* %9
br label %52
52: ; preds = %69, %46
%53 = load i8, i8* %9
%54 = zext i8 %53 to i32
%55 = icmp slt i32 %54, 5
br i1 %55, label %56, label %72
56: ; preds = %52
%57 = load i8, i8* %9
%58 = zext i8 %57 to i64
%59 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 %58
%60 = load double, double* %59
%61 = load i8, i8* %10
%62 = zext i8 %61 to i64
%63 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 %62
%64 = load double, double* %63
%65 = fcmp olt double %60, %64
br i1 %65, label %66, label %68
66: ; preds = %56
%67 = load i8, i8* %9
store i8 %67, i8* %10
br label %68
68: ; preds = %66, %56
br label %69
69: ; preds = %68
%70 = load i8, i8* %9
%71 = add i8 %70, 1
store i8 %71, i8* %9
br label %52
72: ; preds = %52
%73 = load i8, i8* %8
%74 = zext i8 %73 to i64
%75 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 %74
%76 = load double, double* %75
store double %76, double* %11
%77 = load i8, i8* %10
%78 = zext i8 %77 to i64
%79 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 %78
%80 = load double, double* %79
%81 = load i8, i8* %8
%82 = zext i8 %81 to i64
%83 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 %82
store double %80, double* %83
%84 = load double, double* %11
%85 = load i8, i8* %10
%86 = zext i8 %85 to i64
%87 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 %86
store double %84, double* %87
br label %88
88: ; preds = %72
%89 = load i8, i8* %8
%90 = add i8 %89, 1
store i8 %90, i8* %8
br label %42
91: ; preds = %42
%92 = getelementptr inbounds [5 x double], [5 x double]* %12, i64 0, i64 2
%93 = load double, double* %92
%94 = load double*, double** %5
%95 = load i8, i8* %7
%96 = zext i8 %95 to i32
%97 = sub nsw i32 %96, 2
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %94, i64 %98
store double %93, double* %99
br label %100
100: ; preds = %91
%101 = load i8, i8* %7
%102 = add i8 %101, 1
store i8 %102, i8* %7
br label %13
103: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @Median_Filter(double* nocapture %0, double* nocapture writeonly %1, i32 %2) {
%4 = alloca [5 x double]
%5 = bitcast [5 x double]* %4 to i8*
%6 = add nsw i32 %2, -2
%7 = icmp sgt i32 %2, 4
br i1 %7, label %8, label %91
8: ; preds = %3
%9 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 2
%10 = getelementptr double, double* %0, i64 -2
%11 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 1
%12 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 0
%13 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 3
%14 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 4
%15 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 0
%16 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 1
%17 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 3
%18 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 4
%19 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 1
%20 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 3
%21 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 4
br label %22
22: ; preds = %8, %22
%23 = phi i32 [ 2, %8 ], [ %89, %22 ]
%24 = zext i32 %23 to i64
%25 = getelementptr double, double* %10, i64 %24
%26 = bitcast double* %25 to i8*
%27 = load double, double* %11
%28 = load double, double* %12
%29 = fcmp olt double %27, %28
%30 = zext i1 %29 to i8
%31 = load double, double* %9
%32 = zext i1 %29 to i64
%33 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %32
%34 = load double, double* %33
%35 = fcmp olt double %31, %34
%36 = select i1 %35, i8 2, i8 %30
%37 = load double, double* %13
%38 = zext i8 %36 to i64
%39 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %38
%40 = load double, double* %39
%41 = fcmp olt double %37, %40
%42 = select i1 %41, i8 3, i8 %36
%43 = load double, double* %14
%44 = zext i8 %42 to i64
%45 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %44
%46 = load double, double* %45
%47 = fcmp olt double %43, %46
%48 = zext i8 %42 to i64
%49 = select i1 %47, i64 4, i64 %48
%50 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %49
%51 = load double, double* %50
store double %51, double* %15
store double %28, double* %50
%52 = load double, double* %9
%53 = load double, double* %16
%54 = fcmp olt double %52, %53
%55 = select i1 %54, i8 2, i8 1
%56 = load double, double* %17
%57 = zext i8 %55 to i64
%58 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %57
%59 = load double, double* %58
%60 = fcmp olt double %56, %59
%61 = select i1 %60, i8 3, i8 %55
%62 = load double, double* %18
%63 = zext i8 %61 to i64
%64 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %63
%65 = load double, double* %64
%66 = fcmp olt double %62, %65
%67 = zext i8 %61 to i64
%68 = select i1 %66, i64 4, i64 %67
%69 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %68
%70 = load double, double* %69
store double %70, double* %19
store double %53, double* %69
%71 = load double, double* %20
%72 = load double, double* %9
%73 = fcmp olt double %71, %72
%74 = select i1 %73, i8 3, i8 2
%75 = load double, double* %21
%76 = zext i8 %74 to i64
%77 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %76
%78 = load double, double* %77
%79 = fcmp olt double %75, %78
%80 = zext i8 %74 to i64
%81 = select i1 %79, i64 4, i64 %80
%82 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 %81
%83 = load double, double* %82
store double %83, double* %9
store double %72, double* %82
%84 = load double, double* %9
%85 = add nsw i32 %23, -2
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %1, i64 %86
store double %84, double* %87
%88 = add nuw nsw i32 %23, 1
%89 = and i32 %88, 255
%90 = icmp sgt i32 %6, %89
br i1 %90, label %22, label %91
91: ; preds = %22, %3
ret void
}