void switchCol(double A[1000][1000], double sigma[1000], int index1, int index2,
               int n) {
  int i;
  double aux;
  for (i = 0; i < n; i++) {
    aux = A[i][index1];
    A[i][index1] = A[i][index2];
    A[i][index2] = aux;
  }
  aux = sigma[index1];
  sigma[index1] = sigma[index2];
  sigma[index2] = aux;
}


x86 assembly (clang, -O0):
<switchCol>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ad <switchCol+0xad>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    111d <switchCol+0x1d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<switchCol>:
movslq %edx,%r10
movslq %ecx,%rcx
test   %r8d,%r8d
jle    11a1 <switchCol+0xa1>
mov    %r8d,%r9d
cmp    $0x1,%r8d
jne    111c <switchCol+0x1c>
xor    %edx,%edx
jmp    117b <switchCol+0x7b>
mov    %r9d,%r8d
and    $0xfffffffe,%r8d
xor    %edx,%edx
mov    %rdi,%rax
nopl   0x0(%rax,%rax,1)
movsd  (%rax,%r10,8),%xmm0
movsd  (%rax,%rcx,8),%xmm1
movsd  %xmm1,(%rax,%r10,8)
movsd  %xmm0,(%rax,%rcx,8)
movsd  0x1f40(%rax,%r10,8),%xmm0
movsd  0x1f40(%rax,%rcx,8),%xmm1
movsd  %xmm1,0x1f40(%rax,%r10,8)
movsd  %xmm0,0x1f40(%rax,%rcx,8)
add    $0x2,%rdx
add    $0x3e80,%rax
cmp    %rdx,%r8
jne    1130 <switchCol+0x30>
test   $0x1,%r9b
je     11a1 <switchCol+0xa1>
imul   $0x1f40,%rdx,%rax
add    %rax,%rdi
movsd  (%rdi,%r10,8),%xmm0
movsd  (%rdi,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%r10,8)
movsd  %xmm0,(%rdi,%rcx,8)
movsd  (%rsi,%r10,8),%xmm0
movsd  (%rsi,%rcx,8),%xmm1
movsd  %xmm1,(%rsi,%r10,8)
movsd  %xmm0,(%rsi,%rcx,8)
ret

LLVM IR (-O0):
define void @switchCol([1000 x double]* %0, double* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [1000 x double]*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store [1000 x double]* %0, [1000 x double]** %6
store double* %1, double** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
br label %13
13: ; preds = %49, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %10
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %52
17: ; preds = %13
%18 = load [1000 x double]*, [1000 x double]** %6
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1000 x double], [1000 x double]* %18, i64 %20
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1000 x double], [1000 x double]* %21, i64 0, i64 %23
%25 = load double, double* %24
store double %25, double* %12
%26 = load [1000 x double]*, [1000 x double]** %6
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1000 x double], [1000 x double]* %26, i64 %28
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1000 x double], [1000 x double]* %29, i64 0, i64 %31
%33 = load double, double* %32
%34 = load [1000 x double]*, [1000 x double]** %6
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1000 x double], [1000 x double]* %34, i64 %36
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1000 x double], [1000 x double]* %37, i64 0, i64 %39
store double %33, double* %40
%41 = load double, double* %12
%42 = load [1000 x double]*, [1000 x double]** %6
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1000 x double], [1000 x double]* %42, i64 %44
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1000 x double], [1000 x double]* %45, i64 0, i64 %47
store double %41, double* %48
br label %49
49: ; preds = %17
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %13
52: ; preds = %13
%53 = load double*, double** %7
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
store double %57, double* %12
%58 = load double*, double** %7
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double*, double** %7
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %62, double* %66
%67 = load double, double* %12
%68 = load double*, double** %7
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
store double %67, double* %71
ret void
}

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