#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__ errChkdMalloc(int);
int /*<<< orphan*/ printf(char *, ...);
char **allocateGridMemory(int size) {
  int i;
  char **allocHelper;
  allocHelper = (char **)errChkdMalloc(4 * size);
  for (i = 0; i < size; i++) {
    allocHelper[i] = (char *)errChkdMalloc(size);
  }
  printf("assign done\n");
  printf("in allocateGridMemory allocHelper == 0x%08x\n",
         (unsigned int)allocHelper);
  return allocHelper;
}


x86 assembly (clang, -O0):
<allocateGridMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
shl    $0x2,%edi
call   1040 <errChkdMalloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1172 <allocateGridMemory+0x52>
mov    -0x4(%rbp),%edi
call   1040 <errChkdMalloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1141 <allocateGridMemory+0x21>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateGridMemory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x0(,%r15,4),%edi
call   1050 <errChkdMalloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    1175 <allocateGridMemory+0x45>
mov    %r15d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
call   1050 <errChkdMalloc@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <allocateGridMemory+0x30>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe78(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"assign done\0A\00"
@.str.1 = [45 x i8] c"in allocateGridMemory allocHelper == 0x%08x\0A\00"
define i8** @allocateGridMemory(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = mul nsw i32 4, %5
%7 = call i64 @errChkdMalloc(i32 %6)
%8 = inttoptr i64 %7 to i8**
store i8** %8, i8*** %4
store i32 0, i32* %3
br label %9
9: ; preds = %21, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i64 @errChkdMalloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = load i8**, i8*** %4
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
store i8* %16, i8** %20
br label %21
21: ; preds = %13
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %9
24: ; preds = %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%26 = load i8**, i8*** %4
%27 = ptrtoint i8** %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i8**, i8*** %4
ret i8** %29
}

LLVM IR (-O2):
@.str.1 = [45 x i8] c"in allocateGridMemory allocHelper == 0x%08x\0A\00"
@str = [12 x i8] c"assign done\00"
define i8** @allocateGridMemory(i32 %0) {
%2 = shl nsw i32 %0, 2
%3 = tail call i64 @errChkdMalloc(i32 %2)
%4 = inttoptr i64 %3 to i8**
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %13, %8 ]
%10 = tail call i64 @errChkdMalloc(i32 %0)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i8*, i8** %4, i64 %9
store i8* %11, i8** %12
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %15, label %8
15: ; preds = %8, %1
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%17 = trunc i64 %3 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %17)
ret i8** %4
}