void reverseDoubles(double *a, int length) {
  int halfLen = (length >> 1);
  double *end = a + length;
  double c;
  while (--halfLen >= 0) {
    c = *a;
    *a++ = *--end;
    *end = c;
  }
}


x86 assembly (clang, -O0):
<reverseDoubles>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jl     117f <reverseDoubles+0x7f>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffff8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  -0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1127 <reverseDoubles+0x27>
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseDoubles>:
cmp    $0x2,%esi
jl     1140 <reverseDoubles+0x40>
mov    %esi,%eax
shr    %esi
lea    (%rdi,%rax,8),%rax
add    $0xfffffffffffffff8,%rax
add    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rdi),%xmm0
movsd  (%rax),%xmm1
movsd  %xmm1,(%rdi)
add    $0x8,%rdi
movsd  %xmm0,(%rax)
add    $0xfffffffffffffff8,%rax
add    $0xffffffff,%esi
cmp    $0x1,%esi
ja     1120 <reverseDoubles+0x20>
ret

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

LLVM IR (-O2):
define void @reverseDoubles(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = getelementptr inbounds double, double* %0, i64 %5
%7 = lshr i32 %1, 1
br label %8
8: ; preds = %4, %8
%9 = phi double* [ %16, %8 ], [ %0, %4 ]
%10 = phi double* [ %14, %8 ], [ %6, %4 ]
%11 = phi i32 [ %12, %8 ], [ %7, %4 ]
%12 = add nsw i32 %11, -1
%13 = load double, double* %9
%14 = getelementptr inbounds double, double* %10, i64 -1
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %9, i64 1
store double %15, double* %9
store double %13, double* %14
%17 = icmp ugt i32 %11, 1
br i1 %17, label %8, label %18
18: ; preds = %8, %2
ret void
}