#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 */
double *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ printf(char *);
void init_mem(double *p[], int n, int *cell_pt[]) {
  for (int k = 0; k < n; ++k) {
    p[k] = calloc(cell_pt[k][0], sizeof(double));
    if (p[k] == NULL) {
      printf("Initialize memory fail!\n");
      for (int j = 0; j < k; j++) {
        free(p[k]);
        p[k] = NULL;
      }
      exit(5);
    }
  }
}


x86 assembly (clang, -O0):
<init_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <init_mem+0xcb>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11f8 <init_mem+0xb8>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ee <init_mem+0xae>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b3 <init_mem+0x73>
mov    $0x5,%edi
call   1060 <exit@plt>
jmp    11fd <init_mem+0xbd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <init_mem+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_mem>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1182 <init_mem+0x42>
mov    %rdx,%r15
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     118e <init_mem+0x4e>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <init_mem+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
test   %ebx,%ebx
je     11d5 <init_mem+0x95>
mov    (%r14,%rbx,8),%rdi
call   1030 <free@plt>
movq   $0x0,(%r14,%rbx,8)
cmp    $0x1,%ebx
je     11d5 <init_mem+0x95>
lea    -0x1(%rbx),%r15
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1030 <free@plt>
add    $0xffffffff,%r15d
jne    11c0 <init_mem+0x80>
movq   $0x0,(%r14,%rbx,8)
mov    $0x5,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Initialize memory fail!\0A\00"
define void @init_mem(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
store i32 0, i32* %7
br label %9
9: ; preds = %55, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %58
13: ; preds = %9
%14 = load i32**, i32*** %6
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32*, i32** %14, i64 %16
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = call double* @calloc(i32 %20, i32 8)
%22 = load double**, double*** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double*, double** %22, i64 %24
store double* %21, double** %25
%26 = load double**, double*** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double*, double** %26, i64 %28
%30 = load double*, double** %29
%31 = icmp eq double* %30, null
br i1 %31, label %32, label %54
32: ; preds = %13
%33 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %34
34: ; preds = %49, %32
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = load double**, double*** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double*, double** %39, i64 %41
%43 = load double*, double** %42
%44 = call i32 @free(double* %43)
%45 = load double**, double*** %4
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double*, double** %45, i64 %47
store double* null, double** %48
br label %49
49: ; preds = %38
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %34
52: ; preds = %34
%53 = call i32 @exit(i32 5)
unreachable
54: ; preds = %13
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %9
58: ; preds = %9
ret void
}

LLVM IR (-O2):
@str = [24 x i8] c"Initialize memory fail!\00"
define void @init_mem(double** nocapture %0, i32 %1, i32** nocapture %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %8
7: ; preds = %34, %3
ret void
8: ; preds = %5, %34
%9 = phi i64 [ 0, %5 ], [ %35, %34 ]
%10 = getelementptr inbounds i32*, i32** %2, i64 %9
%11 = load i32*, i32** %10
%12 = load i32, i32* %11
%13 = tail call double* @calloc(i32 %12, i32 8)
%14 = getelementptr inbounds double*, double** %0, i64 %9
store double* %13, double** %14
%15 = icmp eq double* %13, null
br i1 %15, label %16, label %34
16: ; preds = %8
%17 = trunc i64 %9 to i32
%18 = and i64 %9, 4294967295
%19 = getelementptr inbounds double*, double** %0, i64 %18
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%21 = icmp eq i32 %17, 0
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = load double*, double** %19
%24 = tail call i32 @free(double* %23)
store double* null, double** %19
%25 = icmp eq i32 %17, 1
br i1 %25, label %27, label %29
26: ; preds = %29
store double* null, double** %19
br label %27
27: ; preds = %22, %26, %16
%28 = tail call i32 @exit(i32 5)
unreachable
29: ; preds = %22, %29
%30 = phi i32 [ %32, %29 ], [ 1, %22 ]
%31 = tail call i32 @free(double* null)
%32 = add nuw nsw i32 %30, 1
%33 = icmp eq i32 %32, %17
br i1 %33, label %26, label %29
34: ; preds = %8
%35 = add nuw nsw i64 %9, 1
%36 = icmp eq i64 %35, %6
br i1 %36, label %7, label %8
}