void swap(double *row1, double *row2, int n) {
  double tmp;
  int i;
  for (i = 0; i < n; ++i) {
    tmp = row1[i];
    row1[i] = row2[i];
    row2[i] = tmp;
  }
}


x86 assembly (clang, -O0):
<swap>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    116e <swap+0x6e>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1116 <swap+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap>:
test   %edx,%edx
jle    1259 <swap+0x159>
mov    %edx,%r9d
cmp    $0x4,%edx
jb     1126 <swap+0x26>
lea    (%rsi,%r9,8),%rax
cmp    %rdi,%rax
jbe    119a <swap+0x9a>
lea    (%rdi,%r9,8),%rax
cmp    %rsi,%rax
jbe    119a <swap+0x9a>
xor    %ecx,%ecx
mov    %rcx,%rax
not    %rax
test   $0x1,%r9b
je     114c <swap+0x4c>
movsd  (%rdi,%rcx,8),%xmm0
movsd  (%rsi,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
movsd  %xmm0,(%rsi,%rcx,8)
or     $0x1,%rcx
add    %r9,%rax
je     1259 <swap+0x159>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rdi,%rcx,8),%xmm0
movsd  (%rsi,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
movsd  %xmm0,(%rsi,%rcx,8)
movsd  0x8(%rdi,%rcx,8),%xmm0
movsd  0x8(%rsi,%rcx,8),%xmm1
movsd  %xmm1,0x8(%rdi,%rcx,8)
movsd  %xmm0,0x8(%rsi,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%r9
jne    1160 <swap+0x60>
jmp    1259 <swap+0x159>
mov    %r9d,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rax
mov    %rax,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rax,%rax
je     125a <swap+0x15a>
mov    %r8,%rax
and    $0xfffffffffffffffe,%rax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movups (%rdi,%rdx,8),%xmm0
movups 0x10(%rdi,%rdx,8),%xmm1
movups (%rsi,%rdx,8),%xmm2
movups 0x10(%rsi,%rdx,8),%xmm3
movups %xmm2,(%rdi,%rdx,8)
movups %xmm3,0x10(%rdi,%rdx,8)
movups %xmm0,(%rsi,%rdx,8)
movups %xmm1,0x10(%rsi,%rdx,8)
movups 0x20(%rdi,%rdx,8),%xmm0
movups 0x30(%rdi,%rdx,8),%xmm1
movups 0x20(%rsi,%rdx,8),%xmm2
movups 0x30(%rsi,%rdx,8),%xmm3
movups %xmm2,0x20(%rdi,%rdx,8)
movups %xmm3,0x30(%rdi,%rdx,8)
movups %xmm0,0x20(%rsi,%rdx,8)
movups %xmm1,0x30(%rsi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rax
jne    11d0 <swap+0xd0>
test   $0x1,%r8b
je     1250 <swap+0x150>
movups (%rdi,%rdx,8),%xmm0
movups 0x10(%rdi,%rdx,8),%xmm1
movups (%rsi,%rdx,8),%xmm2
movups 0x10(%rsi,%rdx,8),%xmm3
movups %xmm2,(%rdi,%rdx,8)
movups %xmm3,0x10(%rdi,%rdx,8)
movups %xmm0,(%rsi,%rdx,8)
movups %xmm1,0x10(%rsi,%rdx,8)
cmp    %r9,%rcx
jne    1128 <swap+0x28>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    122c <swap+0x12c>
jmp    1250 <swap+0x150>

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

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