#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int maxIndex(double *, int, int);
void permuta(double A[1000][1000], double sigma[1000], int index, int n,
             int m) {
  int i, j, k;
  double aux;
  double max = sigma[index];
  k = maxIndex(sigma, index, m);
  if (k == index)
    return;
  for (i = 0; i < n; i++) {
    aux = A[i][index];
    A[i][index] = A[i][k];
    A[i][k] = aux;
  }
  aux = sigma[index];
  sigma[index] = sigma[k];
  sigma[k] = aux;
}


x86 assembly (clang, -O0):
<permuta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <maxIndex@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    115f <permuta+0x4f>
jmp    1234 <permuta+0x124>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f6 <permuta+0xe6>
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,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%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  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1166 <permuta+0x56>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permuta>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %edx,%esi
mov    %r8d,%edx
call   1030 <maxIndex@plt>
cmp    %ebx,%eax
je     11eb <permuta+0xdb>
movslq %ebx,%rcx
cltq
test   %ebp,%ebp
jle    11d3 <permuta+0xc3>
mov    %ebp,%edx
cmp    $0x1,%ebp
jne    114e <permuta+0x3e>
xor    %esi,%esi
jmp    11ac <permuta+0x9c>
mov    %edx,%edi
and    $0xfffffffe,%edi
xor    %esi,%esi
mov    %r14,%rbp
nopl   0x0(%rax,%rax,1)
movsd  0x0(%rbp,%rcx,8),%xmm0
movsd  0x0(%rbp,%rax,8),%xmm1
movsd  %xmm1,0x0(%rbp,%rcx,8)
movsd  %xmm0,0x0(%rbp,%rax,8)
movsd  0x1f40(%rbp,%rcx,8),%xmm0
movsd  0x1f40(%rbp,%rax,8),%xmm1
movsd  %xmm1,0x1f40(%rbp,%rcx,8)
movsd  %xmm0,0x1f40(%rbp,%rax,8)
add    $0x2,%rsi
add    $0x3e80,%rbp
cmp    %rsi,%rdi
jne    1160 <permuta+0x50>
test   $0x1,%dl
je     11d3 <permuta+0xc3>
imul   $0x1f40,%rsi,%rdx
add    %rdx,%r14
movsd  (%r14,%rcx,8),%xmm0
movsd  (%r14,%rax,8),%xmm1
movsd  %xmm1,(%r14,%rcx,8)
movsd  %xmm0,(%r14,%rax,8)
movsd  (%r15,%rcx,8),%xmm0
movsd  (%r15,%rax,8),%xmm1
movsd  %xmm1,(%r15,%rcx,8)
movsd  %xmm0,(%r15,%rax,8)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @permuta([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 i32
%13 = alloca i32
%14 = alloca double
%15 = 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
%16 = load double*, double** %7
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
store double %20, double* %15
%21 = load double*, double** %7
%22 = load i32, i32* %8
%23 = load i32, i32* %10
%24 = call i32 @maxIndex(double* %21, i32 %22, i32 %23)
store i32 %24, i32* %13
%25 = load i32, i32* %13
%26 = load i32, i32* %8
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %5
br label %89
29: ; preds = %5
store i32 0, i32* %11
br label %30
30: ; preds = %66, %29
%31 = load i32, i32* %11
%32 = load i32, i32* %9
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %69
34: ; preds = %30
%35 = load [1000 x double]*, [1000 x double]** %6
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1000 x double], [1000 x double]* %35, i64 %37
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1000 x double], [1000 x double]* %38, i64 0, i64 %40
%42 = load double, double* %41
store double %42, double* %14
%43 = load [1000 x double]*, [1000 x double]** %6
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1000 x double], [1000 x double]* %43, i64 %45
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1000 x double], [1000 x double]* %46, i64 0, i64 %48
%50 = load double, double* %49
%51 = load [1000 x double]*, [1000 x double]** %6
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1000 x double], [1000 x double]* %51, i64 %53
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [1000 x double], [1000 x double]* %54, i64 0, i64 %56
store double %50, double* %57
%58 = load double, double* %14
%59 = load [1000 x double]*, [1000 x double]** %6
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1000 x double], [1000 x double]* %59, i64 %61
%63 = load i32, i32* %13
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1000 x double], [1000 x double]* %62, i64 0, i64 %64
store double %58, double* %65
br label %66
66: ; preds = %34
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %30
69: ; preds = %30
%70 = load double*, double** %7
%71 = load i32, i32* %8
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
store double %74, double* %14
%75 = load double*, double** %7
%76 = load i32, i32* %13
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
%80 = load double*, double** %7
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
store double %79, double* %83
%84 = load double, double* %14
%85 = load double*, double** %7
%86 = load i32, i32* %13
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %85, i64 %87
store double %84, double* %88
br label %89
89: ; preds = %69, %28
ret void
}

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