#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 */
scalar_t__ malloc(int);
double **matrixTransposition(double **matrix, int row, int column) {
  double **result = (double **)malloc(column * sizeof(double *));
  for (int i = 0; i < column; i++) {
    result[i] = (double *)malloc(row * sizeof(double));
    for (int j = 0; j < row; j++) {
      result[i][j] = matrix[j][i];
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<matrixTransposition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c4 <matrixTransposition+0xb4>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <matrixTransposition+0xa1>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116d <matrixTransposition+0x5d>
jmp    11b6 <matrixTransposition+0xa6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <matrixTransposition+0x2c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixTransposition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,(%rsp)
mov    %rdi,%rbx
lea    0x0(,%r12,8),%edi
call   1030 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %r12d,%r12d
jle    122d <matrixTransposition+0x11d>
mov    (%rsp),%rax
lea    0x0(,%rax,8),%r13d
mov    %r12d,%r12d
mov    %eax,%r14d
lea    -0x1(%r14),%rax
mov    %rax,0x10(%rsp)
mov    %r14d,%ebp
and    $0x3,%ebp
and    $0xfffffffc,%r14d
xor    %r15d,%r15d
jmp    117d <matrixTransposition+0x6d>
nopl   (%rax)
add    $0x1,%r15
cmp    %r12,%r15
je     122d <matrixTransposition+0x11d>
mov    %r13d,%edi
call   1030 <malloc@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx,%r15,8)
cmpl   $0x0,(%rsp)
jle    1170 <matrixTransposition+0x60>
cmpq   $0x3,0x10(%rsp)
jae    11a0 <matrixTransposition+0x90>
xor    %ecx,%ecx
jmp    11fb <matrixTransposition+0xeb>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx,%rcx,8),%rdx
movsd  (%rdx,%r15,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    0x8(%rbx,%rcx,8),%rdx
movsd  (%rdx,%r15,8),%xmm0
movsd  %xmm0,0x8(%rax,%rcx,8)
mov    0x10(%rbx,%rcx,8),%rdx
movsd  (%rdx,%r15,8),%xmm0
movsd  %xmm0,0x10(%rax,%rcx,8)
mov    0x18(%rbx,%rcx,8),%rdx
movsd  (%rdx,%r15,8),%xmm0
movsd  %xmm0,0x18(%rax,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%r14
jne    11b0 <matrixTransposition+0xa0>
test   %rbp,%rbp
je     1170 <matrixTransposition+0x60>
lea    (%rax,%rcx,8),%rax
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
xchg   %ax,%ax
mov    (%rcx,%rdx,8),%rsi
movsd  (%rsi,%r15,8),%xmm0
movsd  %xmm0,(%rax,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rbp
jne    1210 <matrixTransposition+0x100>
jmp    1170 <matrixTransposition+0x60>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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