#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 **new_matrix() {
  int i;
  double **M;
  M = (double **)malloc(4 * sizeof(double *));
  M[0] = (double *)malloc(16 * sizeof(double));
  for (i = 0; i < 4; i++) {
    M[i] = M[0] + 4 * i;
  }
  return M;
}


x86 assembly (clang, -O0):
<new_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x80,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    117b <new_matrix+0x6b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x4(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1141 <new_matrix+0x31>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_matrix>:
push   %rbx
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    $0x80,%edi
call   1030 <malloc@plt>
movq   %rax,%xmm0
pshufd $0x44,%xmm0,%xmm0
paddq  0xec6(%rip),%xmm0
mov    %rax,(%rbx)
movdqu %xmm0,0x8(%rbx)
add    $0x60,%rax
mov    %rax,0x18(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define double** @new_matrix() {
%1 = alloca i32
%2 = alloca double**
%3 = call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to double**
store double** %4, double*** %2
%5 = call i64 @malloc(i32 128)
%6 = inttoptr i64 %5 to double*
%7 = load double**, double*** %2
%8 = getelementptr inbounds double*, double** %7, i64 0
store double* %6, double** %8
store i32 0, i32* %1
br label %9
9: ; preds = %24, %0
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = load double**, double*** %2
%14 = getelementptr inbounds double*, double** %13, i64 0
%15 = load double*, double** %14
%16 = load i32, i32* %1
%17 = mul nsw i32 4, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %15, i64 %18
%20 = load double**, double*** %2
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double*, double** %20, i64 %22
store double* %19, double** %23
br label %24
24: ; preds = %12
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
br label %9
27: ; preds = %9
%28 = load double**, double*** %2
ret double** %28
}

LLVM IR (-O2):
define double** @new_matrix() {
%1 = tail call i64 @malloc(i32 32)
%2 = inttoptr i64 %1 to double**
%3 = tail call i64 @malloc(i32 128)
%4 = inttoptr i64 %3 to double*
store double* %4, double** %2
%5 = getelementptr inbounds double*, double** %2, i64 1
%6 = insertelement <2 x double*> poison, double* %4, i64 0
%7 = shufflevector <2 x double*> %6, <2 x double*> poison, <2 x i32> zeroinitializer
%8 = getelementptr double, <2 x double*> %7, <2 x i64> <i64 4, i64 8>
%9 = bitcast double** %5 to <2 x double*>*
store <2 x double*> %8, <2 x double*>* %9
%10 = getelementptr inbounds double, double* %4, i64 12
%11 = getelementptr inbounds double*, double** %2, i64 3
store double* %10, double** %11
ret double** %2
}