void array_swap2_d(register double *arr1, register double *arr2,
                   const unsigned int NIn, const unsigned int stepIn) {
  register unsigned int N, step;
  register double tmp;
  for (N = NIn, step = stepIn; N--;) {
    tmp = *arr1;
    *arr1 = *arr2;
    *arr2 = tmp;
    arr1 += step;
    arr2 += step;
  }
}


x86 assembly (clang, -O0):
<array_swap2_d>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1189 <array_swap2_d+0x89>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    111e <array_swap2_d+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_swap2_d>:
push   %r14
push   %rbx
test   %edx,%edx
je     11ec <array_swap2_d+0xec>
mov    %ecx,%r11d
lea    -0x1(%rdx),%r8d
mov    %edx,%r9d
and    $0x3,%r9d
je     1150 <array_swap2_d+0x50>
lea    0x0(,%r11,8),%r10
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rdi),%xmm0
movsd  (%rsi),%xmm1
movsd  %xmm1,(%rdi)
movsd  %xmm0,(%rsi)
add    $0x1,%ecx
add    %r10,%rdi
add    %r10,%rsi
cmp    %ecx,%r9d
jne    1130 <array_swap2_d+0x30>
sub    %ecx,%edx
cmp    $0x3,%r8d
jb     11ec <array_swap2_d+0xec>
mov    %r11,%r8
shl    $0x5,%r8
lea    0x0(,%r11,8),%r9
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
lea    (%rdi,%rcx,1),%r14
lea    (%rsi,%rcx,1),%r10
movsd  (%rdi,%rcx,1),%xmm0
movsd  (%rsi,%rcx,1),%xmm1
movsd  %xmm1,(%rdi,%rcx,1)
movsd  %xmm0,(%rsi,%rcx,1)
lea    (%r14,%r9,1),%rbx
movsd  (%r14,%r11,8),%xmm0
lea    (%r10,%r9,1),%rax
movsd  (%r10,%r11,8),%xmm1
movsd  %xmm1,(%r14,%r11,8)
movsd  %xmm0,(%r10,%r11,8)
lea    (%rbx,%r9,1),%r10
movsd  (%rbx,%r11,8),%xmm0
lea    (%rax,%r9,1),%r14
movsd  (%rax,%r11,8),%xmm1
movsd  %xmm1,(%rbx,%r11,8)
movsd  %xmm0,(%rax,%r11,8)
add    %r8,%rcx
movsd  (%r10,%r11,8),%xmm0
movsd  (%r14,%r11,8),%xmm1
movsd  %xmm1,(%r10,%r11,8)
movsd  %xmm0,(%r14,%r11,8)
add    $0xfffffffc,%edx
jne    1170 <array_swap2_d+0x70>
pop    %rbx
pop    %r14
ret

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

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