#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__ malloc(size_t);
int /*<<< orphan*/ memset(char *, int, size_t);
char **init_grid(size_t size) {
  char **grid = (char **)malloc(size * sizeof(char *));
  for (int i = 0; i < size; i++) {
    grid[i] = (char *)malloc(size * sizeof(char));
    memset(grid[i], 32, size);
  }
  return (grid);
}


x86 assembly (clang, -O0):
<init_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1196 <init_grid+0x76>
mov    -0x8(%rbp),%rdi
shl    $0x0,%rdi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x20,%esi
call   1030 <memset@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <init_grid+0x24>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_grid>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0x0(,%rdi,8),%rdi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %r15,%r15
je     1165 <init_grid+0x45>
xor    %ebx,%ebx
nop
mov    %r15,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
mov    %rax,%rdi
mov    $0x20,%esi
mov    %r15,%rdx
call   1030 <memset@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <init_grid+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @init_grid(i64 %0) {
%2 = alloca i64
%3 = alloca i8**
%4 = alloca i32
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = mul i64 %5, 8
%7 = call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8**
store i8** %8, i8*** %3
store i32 0, i32* %4
br label %9
9: ; preds = %30, %1
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = load i64, i64* %2
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %9
%15 = load i64, i64* %2
%16 = mul i64 %15, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = load i8**, i8*** %3
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
store i8* %18, i8** %22
%23 = load i8**, i8*** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = load i64, i64* %2
%29 = call i32 @memset(i8* %27, i32 32, i64 %28)
br label %30
30: ; preds = %14
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %9
33: ; preds = %9
%34 = load i8**, i8*** %3
ret i8** %34
}

LLVM IR (-O2):
define i8** @init_grid(i64 %0) {
%2 = shl i64 %0, 3
%3 = tail call i64 @malloc(i64 %2)
%4 = inttoptr i64 %3 to i8**
%5 = icmp eq i64 %0, 0
br i1 %5, label %6, label %7
6: ; preds = %7, %1
ret i8** %4
7: ; preds = %1, %7
%8 = phi i64 [ %13, %7 ], [ 0, %1 ]
%9 = tail call i64 @malloc(i64 %0)
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds i8*, i8** %4, i64 %8
store i8* %10, i8** %11
%12 = tail call i32 @memset(i8* %10, i32 32, i64 %0)
%13 = add nuw i64 %8, 1
%14 = icmp eq i64 %13, %0
br i1 %14, label %6, label %7
}