#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_FAILURE;
scalar_t__ create_array(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
void **create_grid(int r, int c, int size) {
  void **grid;
  int i;
  if (r == 0 || c == 0 || size == 0) {
    fprintf(stderr, "can't create grid with 0 dimenson/size [%d][%d](%d).\n", r,
            c, size);
    return NULL;
  }
  grid = (void **)malloc(r * sizeof(void *));
  if (grid == NULL) {
    fprintf(stderr, "fatal error: can't malloc space for grid rows.\n");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < r; i++)
    grid[i] = (void *)create_array(c, size);
  return grid;
}


x86 assembly (clang, -O0):
<create_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     116f <create_grid+0x2f>
cmpl   $0x0,-0x10(%rbp)
je     116f <create_grid+0x2f>
cmpl   $0x0,-0x14(%rbp)
jne    119d <create_grid+0x5d>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1223 <create_grid+0xe3>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e0 <create_grid+0xa0>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121b <create_grid+0xdb>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <create_array@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e7 <create_grid+0xa7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
test   %edi,%edi
je     11ab <create_grid+0x6b>
test   %r12d,%r12d
je     11ab <create_grid+0x6b>
test   %r14d,%r14d
je     11ab <create_grid+0x6b>
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11e0 <create_grid+0xa0>
mov    %rax,%r13
test   %r15d,%r15d
jle    11ce <create_grid+0x8e>
mov    %r15d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r14d,%esi
call   1060 <create_array@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <create_grid+0x50>
jmp    11ce <create_grid+0x8e>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
xor    %r13d,%r13d
mov    %r15d,%edx
mov    %r12d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"can't create grid with 0 dimenson/size [%d][%d](%d).\0A\00"
@.str.1 = [48 x i8] c"fatal error: can't malloc space for grid rows.\0A\00"
@EXIT_FAILURE = global i32 0
define i8** @create_grid(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15, %12, %3
%19 = load i32, i32* @stderr
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21, i32 %22)
store i8** null, i8*** %4
br label %57
24: ; preds = %15
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 8
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8**
store i8** %30, i8*** %8
%31 = load i8**, i8*** %8
%32 = icmp eq i8** %31, null
br i1 %32, label %33, label %38
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %24
store i32 0, i32* %9
br label %39
39: ; preds = %52, %38
%40 = load i32, i32* %9
%41 = load i32, i32* %5
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = call i64 @create_array(i32 %44, i32 %45)
%47 = inttoptr i64 %46 to i8*
%48 = load i8**, i8*** %8
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* %47, i8** %51
br label %52
52: ; preds = %43
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %39
55: ; preds = %39
%56 = load i8**, i8*** %8
store i8** %56, i8*** %4
br label %57
57: ; preds = %55, %18
%58 = load i8**, i8*** %4
ret i8** %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"can't create grid with 0 dimenson/size [%d][%d](%d).\0A\00"
@.str.1 = [48 x i8] c"fatal error: can't malloc space for grid rows.\0A\00"
@EXIT_FAILURE = global i32 0
define i8** @create_grid(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %0, 0
%5 = icmp eq i32 %1, 0
%6 = or i1 %4, %5
%7 = icmp eq i32 %2, 0
%8 = or i1 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
br label %33
12: ; preds = %3
%13 = shl i32 %0, 3
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8**
%16 = icmp eq i64 %14, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = icmp sgt i32 %0, 0
br i1 %18, label %19, label %33
19: ; preds = %17
%20 = zext i32 %0 to i64
br label %26
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %19, %26
%27 = phi i64 [ 0, %19 ], [ %31, %26 ]
%28 = tail call i64 @create_array(i32 %1, i32 %2)
%29 = inttoptr i64 %28 to i8*
%30 = getelementptr inbounds i8*, i8** %15, i64 %27
store i8* %29, i8** %30
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %20
br i1 %32, label %33, label %26
33: ; preds = %26, %17, %9
%34 = phi i8** [ null, %9 ], [ %15, %17 ], [ %15, %26 ]
ret i8** %34
}