void dswap(unsigned int n, double *dx1, double *dx2) {
  double c;
  do {
    --n;
    c = dx1[n];
    dx1[n] = dx2[n];
    dx2[n] = c;
  } while (n);
}


x86 assembly (clang, -O0):
<dswap>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
cmpl   $0x0,-0x4(%rbp)
jne    110f <dswap+0xf>
pop    %rbp
ret

x86 assembly (clang, -O2):
<dswap>:
push   %rbx
cmp    $0x4,%edi
jb     1209 <dswap+0x109>
lea    -0x1(%rdi),%r11d
lea    (%rdx,%r11,8),%rax
add    $0x8,%rax
cmp    %rsi,%rax
jbe    112c <dswap+0x2c>
lea    (%rsi,%r11,8),%rax
add    $0x8,%rax
cmp    %rdx,%rax
ja     1209 <dswap+0x109>
mov    %edi,%r8d
and    $0xfffffffc,%r8d
lea    -0x4(%r8),%eax
mov    %eax,%r9d
shr    $0x2,%r9d
add    $0x1,%r9d
test   %eax,%eax
je     1267 <dswap+0x167>
mov    %r9d,%eax
and    $0xfffffffe,%eax
lea    -0x5(%rdi),%ecx
mov    $0x1,%r10d
nopl   0x0(%rax)
mov    %r11d,%ebx
movups -0x18(%rsi,%rbx,8),%xmm0
movups -0x8(%rsi,%rbx,8),%xmm1
movups -0x18(%rdx,%rbx,8),%xmm2
movups -0x8(%rdx,%rbx,8),%xmm3
movups %xmm3,-0x8(%rsi,%rbx,8)
movups %xmm2,-0x18(%rsi,%rbx,8)
movups %xmm1,-0x8(%rdx,%rbx,8)
movups %xmm0,-0x18(%rdx,%rbx,8)
mov    %ecx,%ebx
movups -0x18(%rsi,%rbx,8),%xmm0
movups -0x8(%rsi,%rbx,8),%xmm1
movups -0x18(%rdx,%rbx,8),%xmm2
movups -0x8(%rdx,%rbx,8),%xmm3
movups %xmm3,-0x8(%rsi,%rbx,8)
movups %xmm2,-0x18(%rsi,%rbx,8)
movups %xmm1,-0x8(%rdx,%rbx,8)
movups %xmm0,-0x18(%rdx,%rbx,8)
add    $0x8,%r10d
add    $0xfffffff8,%ecx
add    $0xfffffff8,%r11d
add    $0xfffffffe,%eax
jne    1160 <dswap+0x60>
neg    %r10d
test   $0x1,%r9b
je     1201 <dswap+0x101>
add    %edi,%r10d
movups -0x18(%rsi,%r10,8),%xmm0
movups -0x8(%rsi,%r10,8),%xmm1
movups -0x18(%rdx,%r10,8),%xmm2
movups -0x8(%rdx,%r10,8),%xmm3
movups %xmm3,-0x8(%rsi,%r10,8)
movups %xmm2,-0x18(%rsi,%r10,8)
movups %xmm1,-0x8(%rdx,%r10,8)
movups %xmm0,-0x18(%rdx,%r10,8)
cmp    %edi,%r8d
je     1265 <dswap+0x165>
and    $0x3,%edi
mov    %edi,%eax
test   $0x1,%dil
je     1228 <dswap+0x128>
lea    -0x1(%rdi),%eax
movsd  (%rsi,%rax,8),%xmm0
movsd  (%rdx,%rax,8),%xmm1
movsd  %xmm1,(%rsi,%rax,8)
movsd  %xmm0,(%rdx,%rax,8)
cmp    $0x1,%edi
je     1265 <dswap+0x165>
add    $0xffffffff,%eax
mov    %eax,%ecx
movsd  (%rsi,%rcx,8),%xmm0
movsd  (%rdx,%rcx,8),%xmm1
movsd  %xmm1,(%rsi,%rcx,8)
movsd  %xmm0,(%rdx,%rcx,8)
lea    -0x1(%rax),%ecx
movsd  (%rsi,%rcx,8),%xmm0
movsd  (%rdx,%rcx,8),%xmm1
movsd  %xmm1,(%rsi,%rcx,8)
movsd  %xmm0,(%rdx,%rcx,8)
add    $0xfffffffe,%eax
cmp    $0xffffffff,%eax
jne    1230 <dswap+0x130>
pop    %rbx
ret
mov    $0xffffffff,%r10d
test   $0x1,%r9b
jne    11ce <dswap+0xce>
jmp    1201 <dswap+0x101>

LLVM IR (-O0):
define void @dswap(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
br label %8
8: ; preds = %30, %3
%9 = load i32, i32* %4
%10 = add i32 %9, -1
store i32 %10, i32* %4
%11 = load double*, double** %5
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds double, double* %11, i64 %13
%15 = load double, double* %14
store double %15, double* %7
%16 = load double*, double** %6
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = load double*, double** %5
%22 = load i32, i32* %4
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
store double %20, double* %24
%25 = load double, double* %7
%26 = load double*, double** %6
%27 = load i32, i32* %4
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
br label %30
30: ; preds = %8
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %8, label %33
33: ; preds = %30
ret void
}

LLVM IR (-O2):
define void @dswap(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = icmp ult i32 %0, 4
br i1 %4, label %106, label %5
5: ; preds = %3
%6 = add i32 %0, -1
%7 = zext i32 %6 to i64
%8 = add nuw nsw i64 %7, 1
%9 = getelementptr double, double* %1, i64 %8
%10 = getelementptr double, double* %2, i64 %8
%11 = icmp ugt double* %10, %1
%12 = icmp ugt double* %9, %2
%13 = and i1 %11, %12
br i1 %13, label %106, label %14
14: ; preds = %5
%15 = and i32 %0, -4
%16 = and i32 %0, 3
%17 = add i32 %15, -4
%18 = lshr exact i32 %17, 2
%19 = add nuw nsw i32 %18, 1
%20 = and i32 %19, 1
%21 = icmp eq i32 %17, 0
br i1 %21, label %78, label %22
22: ; preds = %14
%23 = and i32 %19, 2147483646
br label %24
24: ; preds = %24, %22
%25 = phi i32 [ 0, %22 ], [ %73, %24 ]
%26 = phi i32 [ 0, %22 ], [ %74, %24 ]
%27 = xor i32 %25, -1
%28 = add i32 %27, %0
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds double, double* %1, i64 %29
%31 = getelementptr inbounds double, double* %30, i64 -1
%32 = bitcast double* %31 to <2 x double>*
%33 = load <2 x double>, <2 x double>* %32
%34 = getelementptr inbounds double, double* %30, i64 -2
%35 = getelementptr inbounds double, double* %34, i64 -1
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %2, i64 %29
%39 = getelementptr inbounds double, double* %38, i64 -1
%40 = bitcast double* %39 to <2 x double>*
%41 = load <2 x double>, <2 x double>* %40
%42 = getelementptr inbounds double, double* %38, i64 -2
%43 = getelementptr inbounds double, double* %42, i64 -1
%44 = bitcast double* %43 to <2 x double>*
%45 = load <2 x double>, <2 x double>* %44
%46 = bitcast double* %31 to <2 x double>*
store <2 x double> %41, <2 x double>* %46
%47 = bitcast double* %35 to <2 x double>*
store <2 x double> %45, <2 x double>* %47
%48 = bitcast double* %39 to <2 x double>*
store <2 x double> %33, <2 x double>* %48
%49 = bitcast double* %43 to <2 x double>*
store <2 x double> %37, <2 x double>* %49
%50 = sub nuw nsw i32 -5, %25
%51 = add i32 %50, %0
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds double, double* %1, i64 %52
%54 = getelementptr inbounds double, double* %53, i64 -1
%55 = bitcast double* %54 to <2 x double>*
%56 = load <2 x double>, <2 x double>* %55
%57 = getelementptr inbounds double, double* %53, i64 -2
%58 = getelementptr inbounds double, double* %57, i64 -1
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = getelementptr inbounds double, double* %2, i64 %52
%62 = getelementptr inbounds double, double* %61, i64 -1
%63 = bitcast double* %62 to <2 x double>*
%64 = load <2 x double>, <2 x double>* %63
%65 = getelementptr inbounds double, double* %61, i64 -2
%66 = getelementptr inbounds double, double* %65, i64 -1
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = bitcast double* %54 to <2 x double>*
store <2 x double> %64, <2 x double>* %69
%70 = bitcast double* %58 to <2 x double>*
store <2 x double> %68, <2 x double>* %70
%71 = bitcast double* %62 to <2 x double>*
store <2 x double> %56, <2 x double>* %71
%72 = bitcast double* %66 to <2 x double>*
store <2 x double> %60, <2 x double>* %72
%73 = add nuw i32 %25, 8
%74 = add i32 %26, 2
%75 = icmp eq i32 %74, %23
br i1 %75, label %76, label %24
76: ; preds = %24
%77 = sub i32 -9, %25
br label %78
78: ; preds = %76, %14
%79 = phi i32 [ -1, %14 ], [ %77, %76 ]
%80 = icmp eq i32 %20, 0
br i1 %80, label %104, label %81
81: ; preds = %78
%82 = add i32 %79, %0
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds double, double* %1, i64 %83
%85 = getelementptr inbounds double, double* %84, i64 -1
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = getelementptr inbounds double, double* %84, i64 -2
%89 = getelementptr inbounds double, double* %88, i64 -1
%90 = bitcast double* %89 to <2 x double>*
%91 = load <2 x double>, <2 x double>* %90
%92 = getelementptr inbounds double, double* %2, i64 %83
%93 = getelementptr inbounds double, double* %92, i64 -1
%94 = bitcast double* %93 to <2 x double>*
%95 = load <2 x double>, <2 x double>* %94
%96 = getelementptr inbounds double, double* %92, i64 -2
%97 = getelementptr inbounds double, double* %96, i64 -1
%98 = bitcast double* %97 to <2 x double>*
%99 = load <2 x double>, <2 x double>* %98
%100 = bitcast double* %85 to <2 x double>*
store <2 x double> %95, <2 x double>* %100
%101 = bitcast double* %89 to <2 x double>*
store <2 x double> %99, <2 x double>* %101
%102 = bitcast double* %93 to <2 x double>*
store <2 x double> %87, <2 x double>* %102
%103 = bitcast double* %97 to <2 x double>*
store <2 x double> %91, <2 x double>* %103
br label %104
104: ; preds = %78, %81
%105 = icmp eq i32 %15, %0
br i1 %105, label %135, label %106
106: ; preds = %5, %3, %104
%107 = phi i32 [ %0, %5 ], [ %0, %3 ], [ %16, %104 ]
%108 = and i32 %107, 1
%109 = icmp eq i32 %108, 0
br i1 %109, label %117, label %110
110: ; preds = %106
%111 = add i32 %107, -1
%112 = zext i32 %111 to i64
%113 = getelementptr inbounds double, double* %1, i64 %112
%114 = load double, double* %113
%115 = getelementptr inbounds double, double* %2, i64 %112
%116 = load double, double* %115
store double %116, double* %113
store double %114, double* %115
br label %117
117: ; preds = %110, %106
%118 = phi i32 [ %107, %106 ], [ %111, %110 ]
%119 = icmp eq i32 %107, 1
br i1 %119, label %135, label %120
120: ; preds = %117, %120
%121 = phi i32 [ %128, %120 ], [ %118, %117 ]
%122 = add i32 %121, -1
%123 = zext i32 %122 to i64
%124 = getelementptr inbounds double, double* %1, i64 %123
%125 = load double, double* %124
%126 = getelementptr inbounds double, double* %2, i64 %123
%127 = load double, double* %126
store double %127, double* %124
store double %125, double* %126
%128 = add i32 %121, -2
%129 = zext i32 %128 to i64
%130 = getelementptr inbounds double, double* %1, i64 %129
%131 = load double, double* %130
%132 = getelementptr inbounds double, double* %2, i64 %129
%133 = load double, double* %132
store double %133, double* %130
store double %131, double* %132
%134 = icmp eq i32 %128, 0
br i1 %134, label %135, label %120
135: ; preds = %117, %120, %104
ret void
}