void swap_rows(double **A, int i, int j, int n) {
  double temp = 0;
  int k = 0;
  for (k = 0; k < n; k++) {
    temp = A[i][k];
    A[i][k] = A[j][k];
    A[j][k] = temp;
  }
}


x86 assembly (clang, -O0):
<swap_rows>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119f <swap_rows+0x9f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1127 <swap_rows+0x27>
pop    %rbp
ret

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

LLVM IR (-O0):
define void @swap_rows(double** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store double** %0, double*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %9
store i32 0, i32* %10
store i32 0, i32* %10
br label %11
11: ; preds = %51, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %54
15: ; preds = %11
%16 = load double**, double*** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double*, double** %16, i64 %18
%20 = load double*, double** %19
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
store double %24, double* %9
%25 = load double**, double*** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double*, double** %25, i64 %27
%29 = load double*, double** %28
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double**, double*** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
%38 = load double*, double** %37
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
store double %33, double* %41
%42 = load double, double* %9
%43 = load double**, double*** %5
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
%47 = load double*, double** %46
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
store double %42, double* %50
br label %51
51: ; preds = %15
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %11
54: ; preds = %11
ret void
}

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