#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);
void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) {
  int i;
  int size;
  *nbRowRes = 5;
  *nbColRes = 3;
  size = (*nbRowRes) * (*nbColRes);
  *resultMatrix = (double *)malloc(size * sizeof(double));
  for (i = 0; i < size; i++) {
    (*resultMatrix)[i] = i * 2;
  }
}


x86 assembly (clang, -O0):
<getDoubleMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    119c <getDoubleMatrix+0x8c>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1168 <getDoubleMatrix+0x58>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDoubleMatrix>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movl   $0x5,(%rsi)
movl   $0x3,(%rdx)
mov    (%rsi),%ebx
lea    0x0(,%rbx,8),%eax
lea    (%rax,%rax,2),%edi
call   1030 <malloc@plt>
mov    %rax,(%r14)
test   %ebx,%ebx
jle    1246 <getDoubleMatrix+0x136>
lea    (%rbx,%rbx,2),%edx
cmp    $0x2,%edx
mov    $0x1,%ecx
cmovge %edx,%ecx
cmp    $0x4,%ecx
jae    1159 <getDoubleMatrix+0x49>
xor    %edx,%edx
jmp    1226 <getDoubleMatrix+0x116>
mov    %ecx,%edx
and    $0x7ffffffc,%edx
lea    -0x4(%rdx),%rsi
mov    %rsi,%rbx
shr    $0x2,%rbx
add    $0x1,%rbx
test   %rsi,%rsi
je     124e <getDoubleMatrix+0x13e>
mov    %rbx,%rsi
and    $0xfffffffffffffffe,%rsi
movdqa 0xe88(%rip),%xmm0
xor    %edi,%edi
movdqa 0xe8e(%rip),%xmm1
movdqa 0xe96(%rip),%xmm2
movdqa 0xe9e(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm0,%xmm4
paddd  %xmm0,%xmm4
movdqa %xmm4,%xmm5
cvtdq2pd %xmm4,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm6,(%rax,%rdi,8)
movups %xmm5,0x10(%rax,%rdi,8)
movdqa %xmm4,%xmm5
paddd  %xmm2,%xmm5
cvtdq2pd %xmm5,%xmm5
paddd  %xmm3,%xmm4
cvtdq2pd %xmm4,%xmm4
movups %xmm5,0x20(%rax,%rdi,8)
movups %xmm4,0x30(%rax,%rdi,8)
add    $0x8,%rdi
paddd  %xmm2,%xmm0
add    $0xfffffffffffffffe,%rsi
jne    11b0 <getDoubleMatrix+0xa0>
paddd  %xmm0,%xmm0
test   $0x1,%bl
je     1221 <getDoubleMatrix+0x111>
cvtdq2pd %xmm0,%xmm1
paddd  0xe0e(%rip),%xmm0
cvtdq2pd %xmm0,%xmm0
movdqu %xmm1,(%rax,%rdi,8)
movdqu %xmm0,0x10(%rax,%rdi,8)
cmp    %rcx,%rdx
je     1246 <getDoubleMatrix+0x136>
sub    %rdx,%rcx
add    %rdx,%rdx
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  %xmm0,(%rax,%rdx,4)
add    $0x2,%rdx
add    $0xffffffffffffffff,%rcx
jne    1230 <getDoubleMatrix+0x120>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movdqa 0xdaa(%rip),%xmm0
xor    %edi,%edi
test   $0x1,%bl
jne    1206 <getDoubleMatrix+0xf6>
jmp    1221 <getDoubleMatrix+0x111>

LLVM IR (-O0):
define void @getDoubleMatrix(double** %0, i32* %1, i32* %2) {
%4 = alloca double**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store double** %0, double*** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = load i32*, i32** %5
store i32 5, i32* %9
%10 = load i32*, i32** %6
store i32 3, i32* %10
%11 = load i32*, i32** %5
%12 = load i32, i32* %11
%13 = load i32*, i32** %6
%14 = load i32, i32* %13
%15 = mul nsw i32 %12, %14
store i32 %15, i32* %8
%16 = load i32, i32* %8
%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*
%22 = load double**, double*** %4
store double* %21, double** %22
store i32 0, i32* %7
br label %23
23: ; preds = %36, %3
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i32, i32* %7
%29 = mul nsw i32 %28, 2
%30 = sitofp i32 %29 to double
%31 = load double**, double*** %4
%32 = load double*, double** %31
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double %30, double* %35
br label %36
36: ; preds = %27
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %23
39: ; preds = %23
ret void
}

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