double opt_med5_double(double *p, int n) {
  {
    if ((p[0]) > (p[1])) {
      double temp = ((p[0]));
      ((p[0])) = ((p[1]));
      ((p[1])) = temp;
    };
  };
  {
    if ((p[3]) > (p[4])) {
      double temp = ((p[3]));
      ((p[3])) = ((p[4]));
      ((p[4])) = temp;
    };
  };
  {
    if ((p[0]) > (p[3])) {
      double temp = ((p[0]));
      ((p[0])) = ((p[3]));
      ((p[3])) = temp;
    };
  };
  {
    if ((p[1]) > (p[4])) {
      double temp = ((p[1]));
      ((p[1])) = ((p[4]));
      ((p[4])) = temp;
    };
  };
  {
    if ((p[1]) > (p[2])) {
      double temp = ((p[1]));
      ((p[1])) = ((p[2]));
      ((p[2])) = temp;
    };
  };
  {
    if ((p[2]) > (p[3])) {
      double temp = ((p[2]));
      ((p[2])) = ((p[3]));
      ((p[3])) = temp;
    };
  };
  {
    if ((p[1]) > (p[2])) {
      double temp = ((p[1]));
      ((p[1])) = ((p[2]));
      ((p[2])) = temp;
    };
  };
  return (p[2]);
}


x86 assembly (clang, -O0):
<opt_med5_double>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x8(%rax),%xmm0
jbe    114e <opt_med5_double+0x4e>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x20(%rax),%xmm0
jbe    1194 <opt_med5_double+0x94>
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x20(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x18(%rax),%xmm0
jbe    11d7 <opt_med5_double+0xd7>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x20(%rax),%xmm0
jbe    121d <opt_med5_double+0x11d>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x20(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x10(%rax),%xmm0
jbe    1263 <opt_med5_double+0x163>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x18(%rax),%xmm0
jbe    12a9 <opt_med5_double+0x1a9>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x10(%rax),%xmm0
jbe    12ef <opt_med5_double+0x1ef>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_med5_double>:
movsd  (%rdi),%xmm2
movsd  0x8(%rdi),%xmm1
ucomisd %xmm1,%xmm2
jbe    111e <opt_med5_double+0x1e>
movsd  %xmm1,(%rdi)
movsd  %xmm2,0x8(%rdi)
movapd %xmm2,%xmm0
jmp    1126 <opt_med5_double+0x26>
movapd %xmm1,%xmm0
movapd %xmm2,%xmm1
movsd  0x18(%rdi),%xmm4
movsd  0x20(%rdi),%xmm3
ucomisd %xmm3,%xmm4
jbe    115a <opt_med5_double+0x5a>
movsd  %xmm3,0x18(%rdi)
movsd  %xmm4,0x20(%rdi)
movapd %xmm4,%xmm2
ucomisd %xmm3,%xmm1
ja     1168 <opt_med5_double+0x68>
movapd %xmm3,%xmm1
ucomisd %xmm2,%xmm0
ja     1177 <opt_med5_double+0x77>
movapd %xmm0,%xmm2
jmp    1181 <opt_med5_double+0x81>
movapd %xmm3,%xmm2
movapd %xmm4,%xmm3
ucomisd %xmm3,%xmm1
jbe    114a <opt_med5_double+0x4a>
movsd  %xmm3,(%rdi)
movsd  %xmm1,0x18(%rdi)
ucomisd %xmm2,%xmm0
jbe    1154 <opt_med5_double+0x54>
movsd  %xmm2,0x8(%rdi)
movsd  %xmm0,0x20(%rdi)
movsd  0x10(%rdi),%xmm3
ucomisd %xmm3,%xmm2
jbe    11af <opt_med5_double+0xaf>
movsd  %xmm3,0x8(%rdi)
movsd  %xmm2,0x10(%rdi)
movapd %xmm3,%xmm0
ucomisd %xmm1,%xmm2
ja     11bd <opt_med5_double+0xbd>
movapd %xmm2,%xmm1
ucomisd %xmm1,%xmm0
ja     11cd <opt_med5_double+0xcd>
movapd %xmm1,%xmm0
ret
movapd %xmm2,%xmm0
movapd %xmm3,%xmm2
ucomisd %xmm1,%xmm2
jbe    11a0 <opt_med5_double+0xa0>
movsd  %xmm1,0x10(%rdi)
movsd  %xmm2,0x18(%rdi)
ucomisd %xmm1,%xmm0
jbe    11aa <opt_med5_double+0xaa>
movsd  %xmm1,0x8(%rdi)
movsd  %xmm0,0x10(%rdi)
ret

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

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