#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 **make2Darray_continuousMem(int a1, int a2) {
  double *tmp_vec = (double *)malloc(a1 * a2 * sizeof(double));
  double **tmp;
  tmp = (double **)malloc(a1 * sizeof(double *));
  for (int i = 0; i < a1; i++) {
    tmp[i] = &(tmp_vec[i * a2]);
  }
  return tmp;
}


x86 assembly (clang, -O0):
<make2Darray_continuousMem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x4(%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    -0x4(%rbp),%eax
jge    118a <make2Darray_continuousMem+0x7a>
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
add    %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    1150 <make2Darray_continuousMem+0x40>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make2Darray_continuousMem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r12d
lea    0x0(,%r12,8),%ebp
mov    %ebp,%edi
imul   %esi,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1030 <malloc@plt>
test   %r12d,%r12d
jle    11f0 <make2Darray_continuousMem+0xe0>
movslq %r15d,%r8
mov    %r12d,%r10d
lea    -0x1(%r10),%rcx
mov    %r10d,%r9d
and    $0x3,%r9d
cmp    $0x3,%rcx
jae    115e <make2Darray_continuousMem+0x4e>
xor    %edi,%edi
jmp    11bb <make2Darray_continuousMem+0xab>
and    $0xfffffffc,%r10d
mov    %r8,%r11
shl    $0x4,%r11
mov    %r8,%rbp
shl    $0x5,%rbp
lea    0x0(,%r8,8),%rbx
lea    (%rbx,%rbx,2),%rdx
xor    %edi,%edi
mov    %r14,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rsi,(%rax,%rdi,8)
lea    (%rsi,%rbx,1),%rcx
mov    %rcx,0x8(%rax,%rdi,8)
lea    (%rsi,%r11,1),%rcx
mov    %rcx,0x10(%rax,%rdi,8)
lea    (%rsi,%rdx,1),%rcx
mov    %rcx,0x18(%rax,%rdi,8)
add    $0x4,%rdi
add    %rbp,%rsi
cmp    %rdi,%r10
jne    1190 <make2Darray_continuousMem+0x80>
test   %r9,%r9
je     11f0 <make2Darray_continuousMem+0xe0>
lea    (%rax,%rdi,8),%rcx
imul   %r8,%rdi
lea    (%r14,%rdi,8),%rdx
shl    $0x3,%r8
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rdx,(%rcx,%rsi,8)
add    $0x1,%rsi
add    %r8,%rdx
cmp    %rsi,%r9
jne    11e0 <make2Darray_continuousMem+0xd0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @make2Darray_continuousMem(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
%6 = alloca double**
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = mul nsw i32 %8, %9
%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** %5
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 8
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to double**
store double** %21, double*** %6
store i32 0, i32* %7
br label %22
22: ; preds = %37, %2
%23 = load i32, i32* %7
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = load double*, double** %5
%28 = load i32, i32* %7
%29 = load i32, i32* %4
%30 = mul nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %27, i64 %31
%33 = load double**, double*** %6
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double*, double** %33, i64 %35
store double* %32, double** %36
br label %37
37: ; preds = %26
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %22
40: ; preds = %22
%41 = load double**, double*** %6
ret double** %41
}

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