void sort_arcs(double *restrict arc, int n) {
  double tmp[2];
  double *end = arc + 2 * n, *arcj, *arci;
  for (arci = arc + 2; arci < end; arci += 2) {
    *tmp = *arci;
    *(tmp + 1) = *(arci + 1);
    arcj = arci;
    while (arcj > arc && *(arcj - 2) > tmp[0]) {
      *arcj = *(arcj - 2);
      *(arcj + 1) = *(arcj - 1);
      arcj -= 2;
    }
    *arcj = *tmp;
    *(arcj + 1) = *(tmp + 1);
  }
}


x86 assembly (clang, -O0):
<sort_arcs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11f7 <sort_arcs+0xf7>
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x38(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x39(%rbp)
jbe    1187 <sort_arcs+0x87>
mov    -0x30(%rbp),%rax
movsd  -0x10(%rax),%xmm0
ucomisd -0x20(%rbp),%xmm0
seta   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1197 <sort_arcs+0x97>
jmp    11cb <sort_arcs+0xcb>
mov    -0x30(%rbp),%rax
movsd  -0x10(%rax),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  -0x8(%rax),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x30(%rbp),%rax
add    $0xfffffffffffffff0,%rax
mov    %rax,-0x30(%rbp)
jmp    1160 <sort_arcs+0x60>
movsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x38(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
jmp    112f <sort_arcs+0x2f>
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_arcs>:
cmp    $0x2,%esi
jl     1167 <sort_arcs+0x67>
add    %esi,%esi
movslq %esi,%rax
lea    (%rdi,%rax,8),%rax
lea    0x10(%rdi),%rcx
jmp    1130 <sort_arcs+0x30>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rsi,%rdx
movupd %xmm0,(%rdx)
add    $0x10,%rcx
cmp    %rax,%rcx
jae    1167 <sort_arcs+0x67>
movupd (%rcx),%xmm0
mov    %rcx,%rdx
cmp    %rdi,%rcx
jbe    1123 <sort_arcs+0x23>
mov    %rcx,%rsi
nop
movsd  -0x10(%rsi),%xmm1
ucomisd %xmm0,%xmm1
jbe    1120 <sort_arcs+0x20>
lea    -0x10(%rsi),%rdx
movsd  %xmm1,(%rsi)
movsd  -0x8(%rsi),%xmm1
movsd  %xmm1,0x8(%rsi)
mov    %rdx,%rsi
cmp    %rdi,%rdx
ja     1140 <sort_arcs+0x40>
jmp    1123 <sort_arcs+0x23>
ret

LLVM IR (-O0):
define void @sort_arcs(double* noalias %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca [2 x double]
%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 = load i32, i32* %4
%11 = mul nsw i32 2, %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %9, i64 %12
store double* %13, double** %6
%14 = load double*, double** %3
%15 = getelementptr inbounds double, double* %14, i64 2
store double* %15, double** %8
br label %16
16: ; preds = %64, %2
%17 = load double*, double** %8
%18 = load double*, double** %6
%19 = icmp ult double* %17, %18
br i1 %19, label %20, label %67
20: ; preds = %16
%21 = load double*, double** %8
%22 = load double, double* %21
%23 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
store double %22, double* %23
%24 = load double*, double** %8
%25 = getelementptr inbounds double, double* %24, i64 1
%26 = load double, double* %25
%27 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%28 = getelementptr inbounds double, double* %27, i64 1
store double %26, double* %28
%29 = load double*, double** %8
store double* %29, double** %7
br label %30
30: ; preds = %43, %20
%31 = load double*, double** %7
%32 = load double*, double** %3
%33 = icmp ugt double* %31, %32
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load double*, double** %7
%36 = getelementptr inbounds double, double* %35, i64 -2
%37 = load double, double* %36
%38 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%39 = load double, double* %38
%40 = fcmp ogt double %37, %39
br label %41
41: ; preds = %34, %30
%42 = phi i1 [ false, %30 ], [ %40, %34 ]
br i1 %42, label %43, label %55
43: ; preds = %41
%44 = load double*, double** %7
%45 = getelementptr inbounds double, double* %44, i64 -2
%46 = load double, double* %45
%47 = load double*, double** %7
store double %46, double* %47
%48 = load double*, double** %7
%49 = getelementptr inbounds double, double* %48, i64 -1
%50 = load double, double* %49
%51 = load double*, double** %7
%52 = getelementptr inbounds double, double* %51, i64 1
store double %50, double* %52
%53 = load double*, double** %7
%54 = getelementptr inbounds double, double* %53, i64 -2
store double* %54, double** %7
br label %30
55: ; preds = %41
%56 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%57 = load double, double* %56
%58 = load double*, double** %7
store double %57, double* %58
%59 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%60 = getelementptr inbounds double, double* %59, i64 1
%61 = load double, double* %60
%62 = load double*, double** %7
%63 = getelementptr inbounds double, double* %62, i64 1
store double %61, double* %63
br label %64
64: ; preds = %55
%65 = load double*, double** %8
%66 = getelementptr inbounds double, double* %65, i64 2
store double* %66, double** %8
br label %16
67: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @sort_arcs(double* noalias %0, i32 %1) {
%3 = shl nsw i32 %1, 1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds double, double* %0, i64 %4
%6 = icmp sgt i32 %1, 1
br i1 %6, label %7, label %31
7: ; preds = %2
%8 = getelementptr inbounds double, double* %0, i64 2
br label %9
9: ; preds = %7, %26
%10 = phi double* [ %29, %26 ], [ %8, %7 ]
%11 = bitcast double* %10 to <2 x double>*
%12 = load <2 x double>, <2 x double>* %11
%13 = icmp ugt double* %10, %0
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = extractelement <2 x double> %12, i64 0
br label %16
16: ; preds = %14, %21
%17 = phi double* [ %18, %21 ], [ %10, %14 ]
%18 = getelementptr inbounds double, double* %17, i64 -2
%19 = load double, double* %18
%20 = fcmp ogt double %19, %15
br i1 %20, label %21, label %26
21: ; preds = %16
store double %19, double* %17
%22 = getelementptr inbounds double, double* %17, i64 -1
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %17, i64 1
store double %23, double* %24
%25 = icmp ugt double* %18, %0
br i1 %25, label %16, label %26
26: ; preds = %16, %21, %9
%27 = phi double* [ %10, %9 ], [ %18, %21 ], [ %17, %16 ]
%28 = bitcast double* %27 to <2 x double>*
store <2 x double> %12, <2 x double>* %28
%29 = getelementptr inbounds double, double* %10, i64 2
%30 = icmp ult double* %29, %5
br i1 %30, label %9, label %31
31: ; preds = %26, %2
ret void
}