#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*/ swap(double *, double *);
void sort_median(double *begin, double *end) {
  double *ptr;
  double *split;
  if (end - begin <= 1)
    return;
  ptr = begin;
  split = begin + 1;
  while (++ptr != end) {
    if (*ptr < *begin) {
      swap(ptr, split);
      ++split;
    }
  }
  swap(begin, split - 1);
  sort_median(begin, split - 1);
  sort_median(split, end);
}


x86 assembly (clang, -O0):
<sort_median>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
cmp    $0x1,%rax
jg     114e <sort_median+0x2e>
jmp    11df <sort_median+0xbf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
cmp    -0x10(%rbp),%rax
je     11b0 <sort_median+0x90>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ab <sort_median+0x8b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <swap@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <sort_median+0x42>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0xfffffffffffffff8,%rsi
call   1040 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0xfffffffffffffff8,%rsi
call   1030 <sort_median@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <sort_median@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_median>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
sub    %rdi,%rax
cmp    $0x10,%rax
jge    1140 <sort_median+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rsi,%r14
mov    %rdi,%r15
jmp    117d <sort_median+0x5d>
nopl   0x0(%rax,%rax,1)
mov    %r14,%r12
lea    -0x8(%r12),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <swap@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <sort_median@plt>
mov    %r14,%rax
sub    %r12,%rax
mov    %r12,%r15
cmp    $0xf,%rax
jle    1134 <sort_median+0x14>
lea    0x8(%r15),%rbx
cmp    %r14,%rbx
je     1150 <sort_median+0x30>
mov    %rbx,%r12
jmp    1199 <sort_median+0x79>
nopl   0x0(%rax,%rax,1)
add    $0x8,%rbx
cmp    %r14,%rbx
je     1153 <sort_median+0x33>
movsd  (%r15),%xmm0
ucomisd (%rbx),%xmm0
jbe    1190 <sort_median+0x70>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <swap@plt>
add    $0x8,%r12
jmp    1190 <sort_median+0x70>

LLVM IR (-O0):
define void @sort_median(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
store double* %0, double** %3
store double* %1, double** %4
%7 = load double*, double** %4
%8 = load double*, double** %3
%9 = ptrtoint double* %7 to i64
%10 = ptrtoint double* %8 to i64
%11 = sub i64 %9, %10
%12 = sdiv exact i64 %11, 8
%13 = icmp sle i64 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %2
br label %47
15: ; preds = %2
%16 = load double*, double** %3
store double* %16, double** %5
%17 = load double*, double** %3
%18 = getelementptr inbounds double, double* %17, i64 1
store double* %18, double** %6
br label %19
19: ; preds = %36, %15
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i32 1
store double* %21, double** %5
%22 = load double*, double** %4
%23 = icmp ne double* %21, %22
br i1 %23, label %24, label %37
24: ; preds = %19
%25 = load double*, double** %5
%26 = load double, double* %25
%27 = load double*, double** %3
%28 = load double, double* %27
%29 = fcmp olt double %26, %28
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = load double*, double** %5
%32 = load double*, double** %6
%33 = call i32 @swap(double* %31, double* %32)
%34 = load double*, double** %6
%35 = getelementptr inbounds double, double* %34, i32 1
store double* %35, double** %6
br label %36
36: ; preds = %30, %24
br label %19
37: ; preds = %19
%38 = load double*, double** %3
%39 = load double*, double** %6
%40 = getelementptr inbounds double, double* %39, i64 -1
%41 = call i32 @swap(double* %38, double* %40)
%42 = load double*, double** %3
%43 = load double*, double** %6
%44 = getelementptr inbounds double, double* %43, i64 -1
%45 = load double*, double** %6
%46 = load double*, double** %4
br label %47
47: ; preds = %37, %14
ret void
}

LLVM IR (-O2):
define void @sort_median(double* %0, double* %1) {
%3 = ptrtoint double* %1 to i64
%4 = ptrtoint double* %0 to i64
%5 = sub i64 %3, %4
%6 = icmp slt i64 %5, 16
br i1 %6, label %33, label %7
7: ; preds = %2, %26
%8 = phi double* [ %28, %26 ], [ %0, %2 ]
%9 = getelementptr inbounds double, double* %8, i64 1
%10 = icmp eq double* %9, %1
br i1 %10, label %26, label %11
11: ; preds = %7, %20
%12 = phi double* [ %22, %20 ], [ %9, %7 ]
%13 = phi double* [ %21, %20 ], [ %9, %7 ]
%14 = load double, double* %12
%15 = load double, double* %8
%16 = fcmp olt double %14, %15
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = tail call i32 @swap(double* %12, double* %13)
%19 = getelementptr inbounds double, double* %13, i64 1
br label %20
20: ; preds = %17, %11
%21 = phi double* [ %19, %17 ], [ %13, %11 ]
%22 = getelementptr inbounds double, double* %12, i64 1
%23 = icmp eq double* %22, %1
br i1 %23, label %24, label %11
24: ; preds = %20
%25 = ptrtoint double* %21 to i64
br label %26
26: ; preds = %24, %7
%27 = phi i64 [ %25, %24 ], [ %3, %7 ]
%28 = phi double* [ %21, %24 ], [ %1, %7 ]
%29 = getelementptr inbounds double, double* %28, i64 -1
%30 = tail call i32 @swap(double* %8, double* %29)
tail call void @sort_median(double* %8, double* %29)
%31 = sub i64 %3, %27
%32 = icmp slt i64 %31, 16
br i1 %32, label %33, label %7
33: ; preds = %26, %2
ret void
}