#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__ calloc(int, int);
double **matrix_transposition(double **mat, int mat_row, int mat_col) {
  double **transpo = (double **)calloc(mat_col, sizeof(double *));
  for (int i = 0; i < mat_col; i++)
    transpo[i] = (double *)calloc(mat_row, sizeof(double));
  for (int i = 0; i < mat_col; i++)
    for (int j = 0; j < mat_row; j++)
      transpo[i][j] = mat[j][i];
  return transpo;
}


x86 assembly (clang, -O0):
<matrix_transposition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1170 <matrix_transposition+0x60>
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <matrix_transposition+0x2a>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e1 <matrix_transposition+0xd1>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ce <matrix_transposition+0xbe>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <matrix_transposition+0x7a>
jmp    11d3 <matrix_transposition+0xc3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1177 <matrix_transposition+0x67>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_transposition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
mov    %edx,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    122c <matrix_transposition+0x11c>
mov    %r15d,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%r14,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1150 <matrix_transposition+0x40>
test   %r15d,%r15d
jle    122c <matrix_transposition+0x11c>
mov    %r12d,%r9d
lea    -0x1(%r9),%r8
mov    %r9d,%edx
and    $0x3,%edx
and    $0xfffffffc,%r9d
xor    %esi,%esi
jmp    119d <matrix_transposition+0x8d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rsi
cmp    %r13,%rsi
je     122c <matrix_transposition+0x11c>
test   %r12d,%r12d
jle    1190 <matrix_transposition+0x80>
mov    (%r14,%rsi,8),%rdi
xor    %ecx,%ecx
cmp    $0x3,%r8
jb     11f7 <matrix_transposition+0xe7>
xchg   %ax,%ax
mov    (%rbx,%rcx,8),%rax
movsd  (%rax,%rsi,8),%xmm0
movsd  %xmm0,(%rdi,%rcx,8)
mov    0x8(%rbx,%rcx,8),%rax
movsd  (%rax,%rsi,8),%xmm0
movsd  %xmm0,0x8(%rdi,%rcx,8)
mov    0x10(%rbx,%rcx,8),%rax
movsd  (%rax,%rsi,8),%xmm0
movsd  %xmm0,0x10(%rdi,%rcx,8)
mov    0x18(%rbx,%rcx,8),%rax
movsd  (%rax,%rsi,8),%xmm0
movsd  %xmm0,0x18(%rdi,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%r9
jne    11b0 <matrix_transposition+0xa0>
test   %rdx,%rdx
je     1190 <matrix_transposition+0x80>
lea    (%rdi,%rcx,8),%rdi
lea    (%rbx,%rcx,8),%rcx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%rcx,%rbp,8),%rax
movsd  (%rax,%rsi,8),%xmm0
movsd  %xmm0,(%rdi,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rdx
jne    1210 <matrix_transposition+0x100>
jmp    1190 <matrix_transposition+0x80>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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