#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 /*<<< orphan*/ free(double *);
int /*<<< orphan*/ genrank(double *, double *, int const, int const);
double *malloc(int const);
void colrank(const int method, const int m, const int n, double *x) {
  int i, j;
  double *tmp;
  tmp = malloc(m * sizeof(*tmp));
  for (j = 0; j < n; j++) {
    for (i = 0; i < m; i++)
      tmp[i] = x[i + m * j];
    genrank(x + (m * j), tmp, m, method);
    for (i = 0; i < m; i++)
      x[i + m * j] = tmp[i];
  }
  free(tmp);
}


x86 assembly (clang, -O0):
<colrank>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122d <colrank+0xfd>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b1 <colrank+0x81>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%edx
imul   -0x20(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1172 <colrank+0x42>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
call   1050 <genrank@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121a <colrank+0xea>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%edx
imul   -0x20(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11db <colrank+0xab>
jmp    121f <colrank+0xef>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115f <colrank+0x2f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colrank>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,0x18(%rsp)
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,0xc(%rsp)
lea    0x0(,%rbx,8),%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %ebp,%ebp
jle    121d <colrank+0xdd>
mov    %ebx,%eax
shl    $0x3,%rax
mov    %rax,0x28(%rsp)
movslq %ebx,%rax
mov    %ebp,%r15d
shl    $0x3,%rax
mov    %rax,0x30(%rsp)
xor    %r12d,%r12d
mov    0x18(%rsp),%rbp
mov    %rbx,0x20(%rsp)
mov    0x28(%rsp),%r13
jmp    1204 <colrank+0xc4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r12d,%rax
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%r14
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0x20(%rsp),%rdx
mov    0xc(%rsp),%ecx
call   1060 <genrank@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    0x20(%rsp),%rbx
mov    %r13,%rdx
call   1040 <memcpy@plt>
add    0x30(%rsp),%rbp
add    %ebx,%r12d
add    $0xffffffffffffffff,%r15
je     121d <colrank+0xdd>
test   %ebx,%ebx
jg     11b0 <colrank+0x70>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %ebx,%edx
mov    0xc(%rsp),%ecx
call   1060 <genrank@plt>
jmp    11f6 <colrank+0xb6>
mov    0x10(%rsp),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @colrank(i32 %0, i32 %1, i32 %2, double* %3) {
%5 = shl i32 %1, 3
%6 = tail call double* @malloc(i32 %5)
%7 = bitcast double* %6 to i8*
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %33
9: ; preds = %4
%10 = icmp sgt i32 %1, 0
%11 = zext i32 %1 to i64
%12 = shl nuw nsw i64 %11, 3
%13 = sext i32 %1 to i64
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %9, %30
%16 = phi i64 [ 0, %9 ], [ %31, %30 ]
%17 = trunc i64 %16 to i32
%18 = mul i32 %17, %1
%19 = sext i32 %18 to i64
%20 = getelementptr double, double* %3, i64 %19
%21 = bitcast double* %20 to i8*
br i1 %10, label %26, label %22
22: ; preds = %15
%23 = mul nsw i64 %16, %13
%24 = getelementptr inbounds double, double* %3, i64 %23
%25 = tail call i32 @genrank(double* %24, double* %6, i32 %1, i32 %0)
br label %30
26: ; preds = %15
%27 = mul nsw i64 %16, %13
%28 = getelementptr inbounds double, double* %3, i64 %27
%29 = tail call i32 @genrank(double* %28, double* %6, i32 %1, i32 %0)
br label %30
30: ; preds = %22, %26
%31 = add nuw nsw i64 %16, 1
%32 = icmp eq i64 %31, %14
br i1 %32, label %33, label %15
33: ; preds = %30, %4
%34 = tail call i32 @free(double* %6)
ret void
}