#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *);
void init_mem_int(int *p[], int n, int *cell_pt[]) {
  for (int k = 0; k < n; ++k) {
    p[k] = malloc(cell_pt[k][0] * sizeof(int));
    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_int>:
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    120d <init_mem_int+0xcd>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@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    11fa <init_mem_int+0xba>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f0 <init_mem_int+0xb0>
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    11b5 <init_mem_int+0x75>
mov    $0x5,%edi
call   1060 <exit@plt>
jmp    11ff <init_mem_int+0xbf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <init_mem_int+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_mem_int>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1180 <init_mem_int+0x40>
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
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     118c <init_mem_int+0x4c>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <init_mem_int+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe6d(%rip),%rdi
call   1040 <puts@plt>
test   %ebx,%ebx
je     11d5 <init_mem_int+0x95>
mov    (%r14,%rbx,8),%rdi
call   1030 <free@plt>
movq   $0x0,(%r14,%rbx,8)
cmp    $0x1,%ebx
je     11d5 <init_mem_int+0x95>
lea    -0x1(%rbx),%r15
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
call   1030 <free@plt>
add    $0xffffffff,%r15d
jne    11c0 <init_mem_int+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_int(i32** %0, i32 %1, i32** %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i32** %2, i32*** %6
store i32 0, i32* %7
br label %9
9: ; preds = %58, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %61
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 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i32* @malloc(i32 %23)
%25 = load i32**, i32*** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32*, i32** %25, i64 %27
store i32* %24, i32** %28
%29 = load i32**, i32*** %4
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32*, i32** %29, i64 %31
%33 = load i32*, i32** %32
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %57
35: ; preds = %13
%36 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %37
37: ; preds = %52, %35
%38 = load i32, i32* %8
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %55
41: ; preds = %37
%42 = load i32**, i32*** %4
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32*, i32** %42, i64 %44
%46 = load i32*, i32** %45
%47 = call i32 @free(i32* %46)
%48 = load i32**, i32*** %4
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32*, i32** %48, i64 %50
store i32* null, i32** %51
br label %52
52: ; preds = %41
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %37
55: ; preds = %37
%56 = call i32 @exit(i32 5)
unreachable
57: ; preds = %13
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %9
61: ; preds = %9
ret void
}

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