#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__ calloc(int, int);
scalar_t__ malloc(int);
double **initialize_matrix(int row, int col, int zero_flag) {
  double **matrix = (double **)calloc(row, sizeof(double *));
  for (int i = 0; i < row; i++)
    if (zero_flag)
      matrix[i] = (double *)calloc(col, sizeof(double));
    else
      matrix[i] = (double *)malloc(col * sizeof(double));
  return matrix;
}


x86 assembly (clang, -O0):
<initialize_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b1 <initialize_matrix+0x91>
cmpl   $0x0,-0xc(%rbp)
je     1180 <initialize_matrix+0x60>
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    119e <initialize_matrix+0x7e>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11a3 <initialize_matrix+0x83>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <initialize_matrix+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialize_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%r14d
mov    %edi,%ebx
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    1189 <initialize_matrix+0x69>
lea    0x0(,%r14,8),%r15d
mov    %ebx,%ebp
xor    %ebx,%ebx
jmp    1175 <initialize_matrix+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1189 <initialize_matrix+0x69>
test   %r13d,%r13d
je     1160 <initialize_matrix+0x40>
mov    %r14d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
jmp    1168 <initialize_matrix+0x48>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double** @initialize_matrix(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %0, i32 8)
%5 = inttoptr i64 %4 to double**
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = icmp eq i32 %2, 0
%9 = shl i32 %1, 3
%10 = zext i32 %0 to i64
br label %12
11: ; preds = %18, %3
ret double** %5
12: ; preds = %7, %18
%13 = phi i64 [ 0, %7 ], [ %22, %18 ]
br i1 %8, label %16, label %14
14: ; preds = %12
%15 = tail call i64 @calloc(i32 %1, i32 8)
br label %18
16: ; preds = %12
%17 = tail call i64 @malloc(i32 %9)
br label %18
18: ; preds = %14, %16
%19 = phi i64 [ %17, %16 ], [ %15, %14 ]
%20 = inttoptr i64 %19 to double*
%21 = getelementptr inbounds double*, double** %5, i64 %13
store double* %20, double** %21
%22 = add nuw nsw i64 %13, 1
%23 = icmp eq i64 %22, %10
br i1 %23, label %11, label %12
}