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


x86 assembly (clang, -O0):
<opt_med3_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_med3_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  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x10(%rax),%xmm0
jbe    1194 <opt_med3_double+0x94>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomisd 0x8(%rax),%xmm0
jbe    11d7 <opt_med3_double+0xd7>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_med3_double>:
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
ucomisd %xmm2,%xmm1
jbe    111e <opt_med3_double+0x1e>
movsd  %xmm2,(%rdi)
movsd  %xmm1,0x8(%rdi)
movapd %xmm2,%xmm0
jmp    1126 <opt_med3_double+0x26>
movapd %xmm1,%xmm0
movapd %xmm2,%xmm1
movsd  0x10(%rdi),%xmm2
ucomisd %xmm2,%xmm1
jbe    1146 <opt_med3_double+0x46>
movsd  %xmm2,0x8(%rdi)
movsd  %xmm1,0x10(%rdi)
ucomisd %xmm2,%xmm0
ja     1150 <opt_med3_double+0x50>
movapd %xmm2,%xmm0
ret
movapd %xmm1,%xmm2
ucomisd %xmm2,%xmm0
jbe    1141 <opt_med3_double+0x41>
movsd  %xmm2,(%rdi)
movsd  %xmm0,0x8(%rdi)
ret

LLVM IR (-O0):
define double @opt_med3_double(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%8 = load double*, double** %3
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = load double*, double** %3
%12 = getelementptr inbounds double, double* %11, i64 1
%13 = load double, double* %12
%14 = fcmp ogt double %10, %13
br i1 %14, label %15, label %27
15: ; preds = %2
%16 = load double*, double** %3
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
store double %18, double* %5
%19 = load double*, double** %3
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = load double*, double** %3
%23 = getelementptr inbounds double, double* %22, i64 0
store double %21, double* %23
%24 = load double, double* %5
%25 = load double*, double** %3
%26 = getelementptr inbounds double, double* %25, i64 1
store double %24, double* %26
br label %27
27: ; preds = %15, %2
%28 = load double*, double** %3
%29 = getelementptr inbounds double, double* %28, i64 1
%30 = load double, double* %29
%31 = load double*, double** %3
%32 = getelementptr inbounds double, double* %31, i64 2
%33 = load double, double* %32
%34 = fcmp ogt double %30, %33
br i1 %34, label %35, label %47
35: ; preds = %27
%36 = load double*, double** %3
%37 = getelementptr inbounds double, double* %36, i64 1
%38 = load double, double* %37
store double %38, double* %6
%39 = load double*, double** %3
%40 = getelementptr inbounds double, double* %39, i64 2
%41 = load double, double* %40
%42 = load double*, double** %3
%43 = getelementptr inbounds double, double* %42, i64 1
store double %41, double* %43
%44 = load double, double* %6
%45 = load double*, double** %3
%46 = getelementptr inbounds double, double* %45, i64 2
store double %44, double* %46
br label %47
47: ; preds = %35, %27
%48 = load double*, double** %3
%49 = getelementptr inbounds double, double* %48, i64 0
%50 = load double, double* %49
%51 = load double*, double** %3
%52 = getelementptr inbounds double, double* %51, i64 1
%53 = load double, double* %52
%54 = fcmp ogt double %50, %53
br i1 %54, label %55, label %67
55: ; preds = %47
%56 = load double*, double** %3
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
store double %58, double* %7
%59 = load double*, double** %3
%60 = getelementptr inbounds double, double* %59, i64 1
%61 = load double, double* %60
%62 = load double*, double** %3
%63 = getelementptr inbounds double, double* %62, i64 0
store double %61, double* %63
%64 = load double, double* %7
%65 = load double*, double** %3
%66 = getelementptr inbounds double, double* %65, i64 1
store double %64, double* %66
br label %67
67: ; preds = %55, %47
%68 = load double*, double** %3
%69 = getelementptr inbounds double, double* %68, i64 1
%70 = load double, double* %69
ret double %70
}

LLVM IR (-O2):
define double @opt_med3_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 [ %5, %7 ], [ %3, %2 ]
%10 = phi double [ %3, %7 ], [ %5, %2 ]
%11 = getelementptr inbounds double, double* %0, i64 2
%12 = load double, double* %11
%13 = fcmp ogt double %10, %12
br i1 %13, label %14, label %15
14: ; preds = %8
store double %12, double* %4
store double %10, double* %11
br label %15
15: ; preds = %14, %8
%16 = phi double [ %12, %14 ], [ %10, %8 ]
%17 = fcmp ogt double %9, %16
br i1 %17, label %18, label %19
18: ; preds = %15
store double %16, double* %0
store double %9, double* %4
br label %19
19: ; preds = %18, %15
%20 = phi double [ %9, %18 ], [ %16, %15 ]
ret double %20
}