#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*/ _dblrec(double *, int);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
void v_dblsort(double *vec, int n) {
  int k;
  double *l, *r;
  double t;
  assert(vec && (n >= 0));
  if (n <= 1)
    return;
  if (n < 16)
    k = n;
  else {
    _dblrec(vec, n);
    k = 16 - 1;
  }
  for (l = r = vec; --k > 0;)
    if (*++r < *l)
      l = r;
  r = vec;
  t = *l;
  *l = *r;
  *r = t;
  while (--n > 0) {
    t = *++r;
    for (l = r; *--l > t; k--)
      l[1] = *l;
    l[1] = t;
  }
}


x86 assembly (clang, -O0):
<v_dblsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x29(%rbp)
je     1149 <v_dblsort+0x29>
cmpl   $0x0,-0xc(%rbp)
setge  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x1,-0xc(%rbp)
jg     1165 <v_dblsort+0x45>
jmp    1294 <v_dblsort+0x174>
cmpl   $0x10,-0xc(%rbp)
jge    117a <v_dblsort+0x5a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    118d <v_dblsort+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <_dblrec@plt>
movl   $0xf,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    11de <v_dblsort+0xbe>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d9 <v_dblsort+0xb9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1199 <v_dblsort+0x79>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    1294 <v_dblsort+0x174>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffff8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  -0x8(%rax),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1281 <v_dblsort+0x161>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1243 <v_dblsort+0x123>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
jmp    1210 <v_dblsort+0xf0>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v_dblsort>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %esi,%esi
setns  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
cmp    $0x2,%ebp
jl     11f9 <v_dblsort+0xd9>
mov    %ebp,%eax
cmp    $0x10,%ebp
jb     115c <v_dblsort+0x3c>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <_dblrec@plt>
mov    $0xf,%eax
add    $0x1,%eax
lea    0x8(%rbx),%rcx
mov    %rbx,%rsi
jmp    117f <v_dblsort+0x5f>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
add    $0x8,%rcx
mov    %rdx,%rsi
cmp    $0x2,%eax
jbe    1191 <v_dblsort+0x71>
movsd  (%rsi),%xmm0
ucomisd (%rcx),%xmm0
mov    %rcx,%rdx
ja     1170 <v_dblsort+0x50>
mov    %rsi,%rdx
jmp    1170 <v_dblsort+0x50>
movsd  (%rdx),%xmm0
movsd  (%rbx),%xmm1
movsd  %xmm1,(%rdx)
movsd  %xmm0,(%rbx)
cmp    $0x2,%ebp
jl     11f9 <v_dblsort+0xd9>
lea    0x8(%rbx),%rax
nopw   0x0(%rax,%rax,1)
movsd  0x8(%rbx),%xmm1
add    $0x8,%rbx
ucomisd %xmm1,%xmm0
mov    %rbx,%rcx
jbe    11e3 <v_dblsort+0xc3>
mov    %rax,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,(%rcx)
movsd  -0x10(%rcx),%xmm0
add    $0xfffffffffffffff8,%rcx
ucomisd %xmm1,%xmm0
ja     11d0 <v_dblsort+0xb0>
movsd  %xmm1,(%rcx)
cmp    $0x3,%ebp
jl     11f9 <v_dblsort+0xd9>
add    $0xffffffff,%ebp
movsd  (%rbx),%xmm0
add    $0x8,%rax
jmp    11b0 <v_dblsort+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @v_dblsort(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%9 = load double*, double** %3
%10 = icmp ne double* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 0
br label %14
14: ; preds = %11, %2
%15 = phi i1 [ false, %2 ], [ %13, %11 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %4
%19 = icmp sle i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %14
br label %82
21: ; preds = %14
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 16
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* %4
store i32 %25, i32* %5
br label %30
26: ; preds = %21
%27 = load double*, double** %3
%28 = load i32, i32* %4
%29 = call i32 @_dblrec(double* %27, i32 %28)
store i32 15, i32* %5
br label %30
30: ; preds = %26, %24
%31 = load double*, double** %3
store double* %31, double** %7
store double* %31, double** %6
br label %32
32: ; preds = %45, %30
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load double*, double** %7
%38 = getelementptr inbounds double, double* %37, i32 1
store double* %38, double** %7
%39 = load double, double* %38
%40 = load double*, double** %6
%41 = load double, double* %40
%42 = fcmp olt double %39, %41
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = load double*, double** %7
store double* %44, double** %6
br label %45
45: ; preds = %43, %36
br label %32
46: ; preds = %32
%47 = load double*, double** %3
store double* %47, double** %7
%48 = load double*, double** %6
%49 = load double, double* %48
store double %49, double* %8
%50 = load double*, double** %7
%51 = load double, double* %50
%52 = load double*, double** %6
store double %51, double* %52
%53 = load double, double* %8
%54 = load double*, double** %7
store double %53, double* %54
br label %55
55: ; preds = %78, %46
%56 = load i32, i32* %4
%57 = add nsw i32 %56, -1
store i32 %57, i32* %4
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %82
59: ; preds = %55
%60 = load double*, double** %7
%61 = getelementptr inbounds double, double* %60, i32 1
store double* %61, double** %7
%62 = load double, double* %61
store double %62, double* %8
%63 = load double*, double** %7
store double* %63, double** %6
br label %64
64: ; preds = %75, %59
%65 = load double*, double** %6
%66 = getelementptr inbounds double, double* %65, i32 -1
store double* %66, double** %6
%67 = load double, double* %66
%68 = load double, double* %8
%69 = fcmp ogt double %67, %68
br i1 %69, label %70, label %78
70: ; preds = %64
%71 = load double*, double** %6
%72 = load double, double* %71
%73 = load double*, double** %6
%74 = getelementptr inbounds double, double* %73, i64 1
store double %72, double* %74
br label %75
75: ; preds = %70
%76 = load i32, i32* %5
%77 = add nsw i32 %76, -1
store i32 %77, i32* %5
br label %64
78: ; preds = %64
%79 = load double, double* %8
%80 = load double*, double** %6
%81 = getelementptr inbounds double, double* %80, i64 1
store double %79, double* %81
br label %55
82: ; preds = %20, %55
ret void
}

LLVM IR (-O2):
define void @v_dblsort(double* %0, i32 %1) {
%3 = icmp ne double* %0, null
%4 = icmp sgt i32 %1, -1
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp slt i32 %1, 2
br i1 %8, label %50, label %9
9: ; preds = %2
%10 = icmp ult i32 %1, 16
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @_dblrec(double* %0, i32 %1)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %1, %9 ], [ 15, %11 ]
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ %19, %15 ], [ %14, %13 ]
%17 = phi double* [ %20, %15 ], [ %0, %13 ]
%18 = phi double* [ %24, %15 ], [ %0, %13 ]
%19 = add nsw i32 %16, -1
%20 = getelementptr inbounds double, double* %17, i64 1
%21 = load double, double* %20
%22 = load double, double* %18
%23 = fcmp olt double %21, %22
%24 = select i1 %23, double* %20, double* %18
%25 = icmp ugt i32 %16, 2
br i1 %25, label %15, label %26
26: ; preds = %15
%27 = load double, double* %24
%28 = load double, double* %0
store double %28, double* %24
store double %27, double* %0
%29 = icmp sgt i32 %1, 1
br i1 %29, label %30, label %50
30: ; preds = %26, %48
%31 = phi double [ %49, %48 ], [ %27, %26 ]
%32 = phi i32 [ %34, %48 ], [ %1, %26 ]
%33 = phi double* [ %35, %48 ], [ %0, %26 ]
%34 = add nsw i32 %32, -1
%35 = getelementptr inbounds double, double* %33, i64 1
%36 = load double, double* %35
%37 = fcmp ogt double %31, %36
br i1 %37, label %38, label %45
38: ; preds = %30, %38
%39 = phi double [ %43, %38 ], [ %31, %30 ]
%40 = phi double* [ %42, %38 ], [ %33, %30 ]
%41 = phi double* [ %40, %38 ], [ %35, %30 ]
store double %39, double* %41
%42 = getelementptr inbounds double, double* %40, i64 -1
%43 = load double, double* %42
%44 = fcmp ogt double %43, %36
br i1 %44, label %38, label %45
45: ; preds = %38, %30
%46 = phi double* [ %35, %30 ], [ %40, %38 ]
store double %36, double* %46
%47 = icmp sgt i32 %32, 2
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load double, double* %35
br label %30
50: ; preds = %45, %26, %2
ret void
}