#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 *get_transpose(const double *M) {
  int i, j;
  double *M_T;
  M_T = NULL;
  if ((M_T = (double *)malloc(sizeof(double) * 9)) == NULL) {
    ;
    return NULL;
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      M_T[i * 3 + j] = M[j * 3 + i];
    }
  }
  return M_T;
}


x86 assembly (clang, -O0):
<get_transpose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1149 <get_transpose+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11ba <get_transpose+0xaa>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11b2 <get_transpose+0xa2>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    119f <get_transpose+0x8f>
mov    -0x10(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
imul   $0x3,-0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1161 <get_transpose+0x51>
jmp    11a4 <get_transpose+0x94>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <get_transpose+0x40>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_transpose>:
push   %rbx
mov    %rdi,%rbx
mov    $0x48,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     117d <get_transpose+0x6d>
movsd  (%rbx),%xmm0
movsd  %xmm0,(%rax)
movsd  0x18(%rbx),%xmm0
movsd  %xmm0,0x8(%rax)
movsd  0x30(%rbx),%xmm0
movsd  %xmm0,0x10(%rax)
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,0x18(%rax)
movsd  0x20(%rbx),%xmm0
movsd  %xmm0,0x20(%rax)
movsd  0x38(%rbx),%xmm0
movsd  %xmm0,0x28(%rax)
movsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x30(%rax)
movsd  0x28(%rbx),%xmm0
movsd  %xmm0,0x38(%rax)
movsd  0x40(%rbx),%xmm0
movsd  %xmm0,0x40(%rax)
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define double* @get_transpose(double* nocapture %0) {
%2 = tail call i64 @malloc(i32 72)
%3 = inttoptr i64 %2 to double*
%4 = icmp eq i64 %2, 0
br i1 %4, label %31, label %5
5: ; preds = %1
%6 = load double, double* %0
store double %6, double* %3
%7 = getelementptr inbounds double, double* %0, i64 3
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %3, i64 1
store double %8, double* %9
%10 = getelementptr inbounds double, double* %0, i64 6
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %3, i64 2
store double %11, double* %12
%13 = getelementptr inbounds double, double* %0, i64 1
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %3, i64 3
store double %14, double* %15
%16 = getelementptr inbounds double, double* %0, i64 4
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %3, i64 4
store double %17, double* %18
%19 = getelementptr inbounds double, double* %0, i64 7
%20 = load double, double* %19
%21 = getelementptr inbounds double, double* %3, i64 5
store double %20, double* %21
%22 = getelementptr inbounds double, double* %0, i64 2
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %3, i64 6
store double %23, double* %24
%25 = getelementptr inbounds double, double* %0, i64 5
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %3, i64 7
store double %26, double* %27
%28 = getelementptr inbounds double, double* %0, i64 8
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %3, i64 8
store double %29, double* %30
br label %31
31: ; preds = %5, %1
%32 = phi double* [ null, %1 ], [ %3, %5 ]
ret double* %32
}