#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 */
double **allocateDoubleMatrix(int, int);
double **trasposeMatrix(double **A, int n, int m) {
  int i, j;
  double **AT;
  AT = allocateDoubleMatrix(n, m);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      AT[i][j] = A[j][i];
  return AT;
}


x86 assembly (clang, -O0):
<trasposeMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <trasposeMatrix+0x92>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118f <trasposeMatrix+0x7f>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <trasposeMatrix+0x3b>
jmp    1194 <trasposeMatrix+0x84>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <trasposeMatrix+0x28>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trasposeMatrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%edi
mov    %edx,%esi
call   1030 <allocateDoubleMatrix@plt>
test   %r14d,%r14d
jle    11ed <trasposeMatrix+0xdd>
mov    %r14d,%r9d
mov    %r15d,%r10d
lea    -0x1(%r10),%r8
mov    %r10d,%r11d
and    $0x3,%r11d
and    $0xfffffffc,%r10d
xor    %esi,%esi
jmp    115d <trasposeMatrix+0x4d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rsi
cmp    %r9,%rsi
je     11ed <trasposeMatrix+0xdd>
test   %r15d,%r15d
jle    1150 <trasposeMatrix+0x40>
mov    (%rax,%rsi,8),%rbp
xor    %ecx,%ecx
cmp    $0x3,%r8
jb     11b8 <trasposeMatrix+0xa8>
xchg   %ax,%ax
mov    (%rbx,%rcx,8),%rdx
movsd  (%rdx,%rsi,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rcx,8)
mov    0x8(%rbx,%rcx,8),%rdx
movsd  (%rdx,%rsi,8),%xmm0
movsd  %xmm0,0x8(%rbp,%rcx,8)
mov    0x10(%rbx,%rcx,8),%rdx
movsd  (%rdx,%rsi,8),%xmm0
movsd  %xmm0,0x10(%rbp,%rcx,8)
mov    0x18(%rbx,%rcx,8),%rdx
movsd  (%rdx,%rsi,8),%xmm0
movsd  %xmm0,0x18(%rbp,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%r10
jne    1170 <trasposeMatrix+0x60>
test   %r11,%r11
je     1150 <trasposeMatrix+0x40>
lea    0x0(%rbp,%rcx,8),%rbp
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
mov    (%rcx,%rdx,8),%rdi
movsd  (%rdi,%rsi,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%r11
jne    11d0 <trasposeMatrix+0xc0>
jmp    1150 <trasposeMatrix+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double** @trasposeMatrix(double** nocapture %0, i32 %1, i32 %2) {
%4 = tail call double** @allocateDoubleMatrix(i32 %1, i32 %2)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %65
6: ; preds = %3
%7 = icmp sgt i32 %2, 0
%8 = zext i32 %1 to i64
%9 = zext i32 %2 to i64
%10 = add nsw i64 %9, -1
%11 = and i64 %9, 3
%12 = icmp ult i64 %10, 3
%13 = and i64 %9, 4294967292
%14 = icmp eq i64 %11, 0
br label %15
15: ; preds = %6, %62
%16 = phi i64 [ 0, %6 ], [ %63, %62 ]
br i1 %7, label %17, label %62
17: ; preds = %15
%18 = getelementptr inbounds double*, double** %4, i64 %16
%19 = load double*, double** %18
br i1 %12, label %49, label %20
20: ; preds = %17, %20
%21 = phi i64 [ %46, %20 ], [ 0, %17 ]
%22 = phi i64 [ %47, %20 ], [ 0, %17 ]
%23 = getelementptr inbounds double*, double** %0, i64 %21
%24 = load double*, double** %23
%25 = getelementptr inbounds double, double* %24, i64 %16
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %19, i64 %21
store double %26, double* %27
%28 = or i64 %21, 1
%29 = getelementptr inbounds double*, double** %0, i64 %28
%30 = load double*, double** %29
%31 = getelementptr inbounds double, double* %30, i64 %16
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %19, i64 %28
store double %32, double* %33
%34 = or i64 %21, 2
%35 = getelementptr inbounds double*, double** %0, i64 %34
%36 = load double*, double** %35
%37 = getelementptr inbounds double, double* %36, i64 %16
%38 = load double, double* %37
%39 = getelementptr inbounds double, double* %19, i64 %34
store double %38, double* %39
%40 = or i64 %21, 3
%41 = getelementptr inbounds double*, double** %0, i64 %40
%42 = load double*, double** %41
%43 = getelementptr inbounds double, double* %42, i64 %16
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %19, i64 %40
store double %44, double* %45
%46 = add nuw nsw i64 %21, 4
%47 = add i64 %22, 4
%48 = icmp eq i64 %47, %13
br i1 %48, label %49, label %20
49: ; preds = %20, %17
%50 = phi i64 [ 0, %17 ], [ %46, %20 ]
br i1 %14, label %62, label %51
51: ; preds = %49, %51
%52 = phi i64 [ %59, %51 ], [ %50, %49 ]
%53 = phi i64 [ %60, %51 ], [ 0, %49 ]
%54 = getelementptr inbounds double*, double** %0, i64 %52
%55 = load double*, double** %54
%56 = getelementptr inbounds double, double* %55, i64 %16
%57 = load double, double* %56
%58 = getelementptr inbounds double, double* %19, i64 %52
store double %57, double* %58
%59 = add nuw nsw i64 %52, 1
%60 = add i64 %53, 1
%61 = icmp eq i64 %60, %11
br i1 %61, label %62, label %51
62: ; preds = %49, %51, %15
%63 = add nuw nsw i64 %16, 1
%64 = icmp eq i64 %63, %8
br i1 %64, label %65, label %15
65: ; preds = %62, %3
ret double** %4
}