#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);
double maximo(double *, int, int);
int /*<<< orphan*/ switchCol(double **, double *, int, int, int);
int permuta(double A[1000][1000], double sigma[1000], int ordem[1000],
            int index, int n, int m) {
  int k;
  double max;
  max = maximo(sigma, index, m);
  ordem[index] = index;
  if (max < 1E-5)
    return 1;
  k = maxIndex(sigma, index, m);
  if (k == index)
    return 0;
  switchCol(A, sigma, index, k, n);
  ordem[index] = k;
  return 0;
}


x86 assembly (clang, -O0):
<permuta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1040 <maximo@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movsd  0xe87(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1190 <permuta+0x60>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <permuta+0xb6>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1050 <maxIndex@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11ba <permuta+0x8a>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <permuta+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1030 <switchCol@plt>
mov    -0x30(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permuta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebx
mov    %r8d,0xc(%rsp)
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,0x10(%rsp)
mov    %rsi,%rdi
mov    %ecx,%esi
mov    %r9d,%edx
call   1040 <maximo@plt>
movslq %ebp,%r12
mov    %r12d,(%r15,%r12,4)
mov    $0x1,%r14d
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     11aa <permuta+0x7a>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <maxIndex@plt>
xor    %r14d,%r14d
cmp    %ebp,%eax
je     11aa <permuta+0x7a>
mov    %eax,%ebx
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
mov    0xc(%rsp),%r8d
call   1030 <switchCol@plt>
mov    %ebx,(%r15,%r12,4)
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @permuta([1000 x double]* %0, double* %1, i32* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca [1000 x double]*
%9 = alloca double*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
store [1000 x double]* %0, [1000 x double]** %8
store double* %1, double** %9
store i32* %2, i32** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%16 = load double*, double** %9
%17 = load i32, i32* %11
%18 = load i32, i32* %13
%19 = call double @maximo(double* %16, i32 %17, i32 %18)
store double %19, double* %15
%20 = load i32, i32* %11
%21 = load i32*, i32** %10
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
%25 = load double, double* %15
%26 = fcmp olt double %25, 1.000000e-05
br i1 %26, label %27, label %28
27: ; preds = %6
store i32 1, i32* %7
br label %50
28: ; preds = %6
%29 = load double*, double** %9
%30 = load i32, i32* %11
%31 = load i32, i32* %13
%32 = call i32 @maxIndex(double* %29, i32 %30, i32 %31)
store i32 %32, i32* %14
%33 = load i32, i32* %14
%34 = load i32, i32* %11
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %28
store i32 0, i32* %7
br label %50
37: ; preds = %28
%38 = load [1000 x double]*, [1000 x double]** %8
%39 = bitcast [1000 x double]* %38 to double**
%40 = load double*, double** %9
%41 = load i32, i32* %11
%42 = load i32, i32* %14
%43 = load i32, i32* %12
%44 = call i32 @switchCol(double** %39, double* %40, i32 %41, i32 %42, i32 %43)
%45 = load i32, i32* %14
%46 = load i32*, i32** %10
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
store i32 0, i32* %7
br label %50
50: ; preds = %37, %36, %27
%51 = load i32, i32* %7
ret i32 %51
}

LLVM IR (-O2):
define i32 @permuta([1000 x double]* %0, double* %1, i32* nocapture writeonly %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call double @maximo(double* %1, i32 %3, i32 %5)
%8 = sext i32 %3 to i64
%9 = getelementptr inbounds i32, i32* %2, i64 %8
store i32 %3, i32* %9
%10 = fcmp olt double %7, 1.000000e-05
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = tail call i32 @maxIndex(double* %1, i32 %3, i32 %5)
%13 = icmp eq i32 %12, %3
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = bitcast [1000 x double]* %0 to double**
%16 = tail call i32 @switchCol(double** %15, double* %1, i32 %3, i32 %12, i32 %4)
store i32 %12, i32* %9
br label %17
17: ; preds = %11, %6, %14
%18 = phi i32 [ 0, %14 ], [ 1, %6 ], [ 0, %11 ]
ret i32 %18
}