#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_matrix2(double **);
double **matrix_clone(double **, int, int);
void transpose(double **Y, double **X, int n, int m) {
  double **X2 = X;
  if (Y == X)
    X2 = matrix_clone(X, n, m);
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      Y[j][i] = X2[i][j];
  if (Y == X)
    free_matrix2(X2);
}


x86 assembly (clang, -O0):
<transpose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    115f <transpose+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <matrix_clone@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d0 <transpose+0xb0>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11bd <transpose+0x9d>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1179 <transpose+0x59>
jmp    11c2 <transpose+0xa2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1166 <transpose+0x46>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11e7 <transpose+0xc7>
mov    -0x20(%rbp),%rdi
call   1040 <free_matrix2@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transpose>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rax
cmp    %rsi,%rdi
je     1146 <transpose+0x26>
test   %r15d,%r15d
jg     115d <transpose+0x3d>
jmp    121c <transpose+0xfc>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   1030 <matrix_clone@plt>
test   %r15d,%r15d
jle    121c <transpose+0xfc>
mov    %r15d,%r9d
mov    %r12d,%r10d
lea    -0x1(%r10),%r8
mov    %r10d,%r11d
and    $0x3,%r11d
and    $0xfffffffc,%r10d
xor    %esi,%esi
jmp    118d <transpose+0x6d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rsi
cmp    %r9,%rsi
je     121c <transpose+0xfc>
test   %r12d,%r12d
jle    1180 <transpose+0x60>
mov    (%rax,%rsi,8),%rbp
xor    %ecx,%ecx
cmp    $0x3,%r8
jb     11e8 <transpose+0xc8>
xchg   %ax,%ax
movsd  0x0(%rbp,%rcx,8),%xmm0
mov    (%rbx,%rcx,8),%rdx
movsd  %xmm0,(%rdx,%rsi,8)
movsd  0x8(%rbp,%rcx,8),%xmm0
mov    0x8(%rbx,%rcx,8),%rdx
movsd  %xmm0,(%rdx,%rsi,8)
movsd  0x10(%rbp,%rcx,8),%xmm0
mov    0x10(%rbx,%rcx,8),%rdx
movsd  %xmm0,(%rdx,%rsi,8)
movsd  0x18(%rbp,%rcx,8),%xmm0
mov    0x18(%rbx,%rcx,8),%rdx
movsd  %xmm0,(%rdx,%rsi,8)
add    $0x4,%rcx
cmp    %rcx,%r10
jne    11a0 <transpose+0x80>
test   %r11,%r11
je     1180 <transpose+0x60>
lea    (%rbx,%rcx,8),%rdx
lea    0x0(,%rcx,8),%rcx
add    %rbp,%rcx
xor    %ebp,%ebp
xchg   %ax,%ax
movsd  (%rcx,%rbp,8),%xmm0
mov    (%rdx,%rbp,8),%rdi
movsd  %xmm0,(%rdi,%rsi,8)
add    $0x1,%rbp
cmp    %rbp,%r11
jne    1200 <transpose+0xe0>
jmp    1180 <transpose+0x60>
cmp    %r14,%rbx
je     122a <transpose+0x10a>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free_matrix2@plt>

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

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