#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 **allocateMatrix(int n, double initValue) {
  int i, j;
  double **matrix;
  matrix = (double **)malloc(sizeof(double *) * n);
  for (i = 0; i < n; i++) {
    matrix[i] = (double *)malloc(sizeof(double) * n);
    for (j = 0; j < n; j++)
      matrix[i][j] = initValue;
  }
  return matrix;
}


x86 assembly (clang, -O0):
<allocateMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b2 <allocateMatrix+0xa2>
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119f <allocateMatrix+0x8f>
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116b <allocateMatrix+0x5b>
jmp    11a4 <allocateMatrix+0x94>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <allocateMatrix+0x2a>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movaps %xmm0,0x10(%rsp)
mov    %edi,%r12d
lea    0x0(,%r12,8),%edi
mov    %edi,0xc(%rsp)
call   1030 <malloc@plt>
movaps 0x10(%rsp),%xmm0
mov    %rax,%r15
test   %r12d,%r12d
jle    12c3 <allocateMatrix+0x1b3>
mov    %r12d,%ebp
mov    %ebp,%ebx
and    $0xfffffffc,%ebx
lea    -0x4(%rbx),%rax
mov    %rax,0x38(%rsp)
shr    $0x2,%rax
add    $0x1,%rax
movaps %xmm0,%xmm1
movlhps %xmm0,%xmm1
mov    %eax,%r13d
and    $0x7,%r13d
and    $0xfffffffffffffff8,%rax
mov    %rax,0x28(%rsp)
mov    %r13,0x30(%rsp)
shl    $0x5,%r13
xor    %r14d,%r14d
movaps %xmm1,0x40(%rsp)
jmp    119d <allocateMatrix+0x8d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %rbp,%r14
je     12c3 <allocateMatrix+0x1b3>
mov    0xc(%rsp),%edi
call   1030 <malloc@plt>
mov    %rax,(%r15,%r14,8)
cmp    $0x4,%r12d
jae    11c0 <allocateMatrix+0xb0>
xor    %ecx,%ecx
movaps 0x10(%rsp),%xmm0
jmp    12b0 <allocateMatrix+0x1a0>
nopl   0x0(%rax)
cmpq   $0x1c,0x38(%rsp)
jae    11e0 <allocateMatrix+0xd0>
xor    %ecx,%ecx
movaps 0x10(%rsp),%xmm0
movaps 0x40(%rsp),%xmm1
jmp    1271 <allocateMatrix+0x161>
nopl   0x0(%rax)
mov    0x28(%rsp),%rdx
xor    %ecx,%ecx
movaps 0x10(%rsp),%xmm0
movaps 0x40(%rsp),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movups %xmm1,(%rax,%rcx,8)
movups %xmm1,0x10(%rax,%rcx,8)
movups %xmm1,0x20(%rax,%rcx,8)
movups %xmm1,0x30(%rax,%rcx,8)
movups %xmm1,0x40(%rax,%rcx,8)
movups %xmm1,0x50(%rax,%rcx,8)
movups %xmm1,0x60(%rax,%rcx,8)
movups %xmm1,0x70(%rax,%rcx,8)
movups %xmm1,0x80(%rax,%rcx,8)
movups %xmm1,0x90(%rax,%rcx,8)
movups %xmm1,0xa0(%rax,%rcx,8)
movups %xmm1,0xb0(%rax,%rcx,8)
movups %xmm1,0xc0(%rax,%rcx,8)
movups %xmm1,0xd0(%rax,%rcx,8)
movups %xmm1,0xe0(%rax,%rcx,8)
movups %xmm1,0xf0(%rax,%rcx,8)
add    $0x20,%rcx
add    $0xfffffffffffffff8,%rdx
jne    1200 <allocateMatrix+0xf0>
cmpq   $0x0,0x30(%rsp)
je     12a2 <allocateMatrix+0x192>
lea    (%rax,%rcx,8),%rcx
add    $0x10,%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups %xmm1,-0x10(%rcx,%rdx,1)
movups %xmm1,(%rcx,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%r13
jne    1290 <allocateMatrix+0x180>
mov    %rbx,%rcx
cmp    %rbp,%rbx
je     1190 <allocateMatrix+0x80>
xchg   %ax,%ax
movsd  %xmm0,(%rax,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rbp
jne    12b0 <allocateMatrix+0x1a0>
jmp    1190 <allocateMatrix+0x80>
mov    %r15,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double** @allocateMatrix(i32 %0, double %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double**
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %98
7: ; preds = %2
%8 = zext i32 %0 to i64
%9 = and i64 %8, 4294967292
%10 = add nsw i64 %9, -4
%11 = lshr exact i64 %10, 2
%12 = add nuw nsw i64 %11, 1
%13 = icmp ult i32 %0, 4
%14 = and i64 %8, 4294967292
%15 = insertelement <2 x double> poison, double %1, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = insertelement <2 x double> poison, double %1, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = and i64 %12, 7
%20 = icmp ult i64 %10, 28
%21 = and i64 %12, 9223372036854775800
%22 = icmp eq i64 %19, 0
%23 = icmp eq i64 %14, %8
br label %24
24: ; preds = %95, %7
%25 = phi i64 [ 0, %7 ], [ %96, %95 ]
%26 = tail call i64 @malloc(i32 %3)
%27 = inttoptr i64 %26 to double*
%28 = getelementptr inbounds double*, double** %5, i64 %25
store double* %27, double** %28
br i1 %13, label %88, label %29
29: ; preds = %24
br i1 %20, label %75, label %30
30: ; preds = %29, %30
%31 = phi i64 [ %72, %30 ], [ 0, %29 ]
%32 = phi i64 [ %73, %30 ], [ 0, %29 ]
%33 = getelementptr inbounds double, double* %27, i64 %31
%34 = bitcast double* %33 to <2 x double>*
store <2 x double> %16, <2 x double>* %34
%35 = getelementptr inbounds double, double* %33, i64 2
%36 = bitcast double* %35 to <2 x double>*
store <2 x double> %18, <2 x double>* %36
%37 = or i64 %31, 4
%38 = getelementptr inbounds double, double* %27, i64 %37
%39 = bitcast double* %38 to <2 x double>*
store <2 x double> %16, <2 x double>* %39
%40 = getelementptr inbounds double, double* %38, i64 2
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> %18, <2 x double>* %41
%42 = or i64 %31, 8
%43 = getelementptr inbounds double, double* %27, i64 %42
%44 = bitcast double* %43 to <2 x double>*
store <2 x double> %16, <2 x double>* %44
%45 = getelementptr inbounds double, double* %43, i64 2
%46 = bitcast double* %45 to <2 x double>*
store <2 x double> %18, <2 x double>* %46
%47 = or i64 %31, 12
%48 = getelementptr inbounds double, double* %27, i64 %47
%49 = bitcast double* %48 to <2 x double>*
store <2 x double> %16, <2 x double>* %49
%50 = getelementptr inbounds double, double* %48, i64 2
%51 = bitcast double* %50 to <2 x double>*
store <2 x double> %18, <2 x double>* %51
%52 = or i64 %31, 16
%53 = getelementptr inbounds double, double* %27, i64 %52
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %16, <2 x double>* %54
%55 = getelementptr inbounds double, double* %53, i64 2
%56 = bitcast double* %55 to <2 x double>*
store <2 x double> %18, <2 x double>* %56
%57 = or i64 %31, 20
%58 = getelementptr inbounds double, double* %27, i64 %57
%59 = bitcast double* %58 to <2 x double>*
store <2 x double> %16, <2 x double>* %59
%60 = getelementptr inbounds double, double* %58, i64 2
%61 = bitcast double* %60 to <2 x double>*
store <2 x double> %18, <2 x double>* %61
%62 = or i64 %31, 24
%63 = getelementptr inbounds double, double* %27, i64 %62
%64 = bitcast double* %63 to <2 x double>*
store <2 x double> %16, <2 x double>* %64
%65 = getelementptr inbounds double, double* %63, i64 2
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %18, <2 x double>* %66
%67 = or i64 %31, 28
%68 = getelementptr inbounds double, double* %27, i64 %67
%69 = bitcast double* %68 to <2 x double>*
store <2 x double> %16, <2 x double>* %69
%70 = getelementptr inbounds double, double* %68, i64 2
%71 = bitcast double* %70 to <2 x double>*
store <2 x double> %18, <2 x double>* %71
%72 = add nuw i64 %31, 32
%73 = add i64 %32, 8
%74 = icmp eq i64 %73, %21
br i1 %74, label %75, label %30
75: ; preds = %30, %29
%76 = phi i64 [ 0, %29 ], [ %72, %30 ]
br i1 %22, label %87, label %77
77: ; preds = %75, %77
%78 = phi i64 [ %84, %77 ], [ %76, %75 ]
%79 = phi i64 [ %85, %77 ], [ 0, %75 ]
%80 = getelementptr inbounds double, double* %27, i64 %78
%81 = bitcast double* %80 to <2 x double>*
store <2 x double> %16, <2 x double>* %81
%82 = getelementptr inbounds double, double* %80, i64 2
%83 = bitcast double* %82 to <2 x double>*
store <2 x double> %18, <2 x double>* %83
%84 = add nuw i64 %78, 4
%85 = add i64 %79, 1
%86 = icmp eq i64 %85, %19
br i1 %86, label %87, label %77
87: ; preds = %77, %75
br i1 %23, label %95, label %88
88: ; preds = %24, %87
%89 = phi i64 [ 0, %24 ], [ %14, %87 ]
br label %90
90: ; preds = %88, %90
%91 = phi i64 [ %93, %90 ], [ %89, %88 ]
%92 = getelementptr inbounds double, double* %27, i64 %91
store double %1, double* %92
%93 = add nuw nsw i64 %91, 1
%94 = icmp eq i64 %93, %8
br i1 %94, label %95, label %90
95: ; preds = %90, %87
%96 = add nuw nsw i64 %25, 1
%97 = icmp eq i64 %96, %8
br i1 %97, label %98, label %24
98: ; preds = %95, %2
ret double** %5
}