#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*/ cleanMemory(char **, char **, int);
int /*<<< orphan*/ createWall(char **, char **, int);
char getchar();
int /*<<< orphan*/ initializeManually(char **, char **, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ updatePrintMap(char **, char **, int);
int main(void) {
  char **universe = NULL;
  char **temp = NULL;
  char ch = '\0';
  int i = 0;
  int j = 0;
  int side_len = 0;
  printf("Input side length of universe: ");
  scanf("%d", &side_len);
  universe = (char **)malloc(sizeof(char *) * (side_len + 2));
  temp = (char **)malloc(sizeof(char *) * (side_len + 2));
  for (i = 0; i < side_len + 2; ++i) {
    universe[i] = (char *)malloc(sizeof(char) * (side_len + 2));
    temp[i] = (char *)malloc(sizeof(char) * (side_len + 2));
  }
  initializeManually(universe, temp, side_len);
  createWall(universe, temp, side_len);
  while ((ch = getchar()) == '\n') {
    updatePrintMap(universe, temp, side_len);
  }
  cleanMemory(universe, temp, side_len);
  universe = NULL;
  temp = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe41(%rip),%rdi
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x28(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x28(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    126c <main+0xec>
mov    -0x28(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1209 <main+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <initializeManually@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <createWall@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
jne    12b7 <main+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1090 <updatePrintMap@plt>
jmp    128c <main+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1070 <cleanMemory@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe68(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%eax
lea    0x10(,%rax,8),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    0xc(%rsp),%eax
lea    0x10(,%rax,8),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    0xc(%rsp),%edx
cmp    $0xffffffff,%edx
jl     121f <main+0x9f>
add    $0x2,%edx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %edx,%edi
call   1080 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
mov    0xc(%rsp),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
lea    0x2(%rax),%rdx
cmp    %rdx,%rbx
jl     11f0 <main+0x70>
mov    %eax,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <initializeManually@plt>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <createWall@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    125c <main+0xdc>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <updatePrintMap@plt>
jmp    1240 <main+0xc0>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <cleanMemory@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Input side length of universe: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i8**
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i8** null, i8*** %2
store i8** null, i8*** %3
store i8 0, i8* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 2
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8**
store i8** %16, i8*** %2
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 2
%19 = sext i32 %18 to i64
%20 = mul i64 8, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8**
store i8** %23, i8*** %3
store i32 0, i32* %5
br label %24
24: ; preds = %52, %0
%25 = load i32, i32* %5
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 2
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %55
29: ; preds = %24
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = mul i64 1, %32
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i8*
%37 = load i8**, i8*** %2
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
store i8* %36, i8** %40
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 2
%43 = sext i32 %42 to i64
%44 = mul i64 1, %43
%45 = trunc i64 %44 to i32
%46 = call i64 @malloc(i32 %45)
%47 = inttoptr i64 %46 to i8*
%48 = load i8**, i8*** %3
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* %47, i8** %51
br label %52
52: ; preds = %29
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %24
55: ; preds = %24
%56 = load i8**, i8*** %2
%57 = load i8**, i8*** %3
%58 = load i32, i32* %7
%59 = call i32 @initializeManually(i8** %56, i8** %57, i32 %58)
%60 = load i8**, i8*** %2
%61 = load i8**, i8*** %3
%62 = load i32, i32* %7
%63 = call i32 @createWall(i8** %60, i8** %61, i32 %62)
br label %64
64: ; preds = %68, %55
%65 = call signext i8 (...) @getchar()
store i8 %65, i8* %4
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 10
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i8**, i8*** %2
%70 = load i8**, i8*** %3
%71 = load i32, i32* %7
%72 = call i32 @updatePrintMap(i8** %69, i8** %70, i32 %71)
br label %64
73: ; preds = %64
%74 = load i8**, i8*** %2
%75 = load i8**, i8*** %3
%76 = load i32, i32* %7
%77 = call i32 @cleanMemory(i8** %74, i8** %75, i32 %76)
store i8** null, i8*** %2
store i8** null, i8*** %3
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Input side length of universe: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 3
%7 = add i32 %6, 16
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8**
%10 = load i32, i32* %1
%11 = shl i32 %10, 3
%12 = add i32 %11, 16
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8**
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, -2
br i1 %16, label %17, label %35
17: ; preds = %0
%18 = add nsw i32 %15, 2
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %30, %19 ]
%21 = phi i32 [ %18, %17 ], [ %32, %19 ]
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = getelementptr inbounds i8*, i8** %9, i64 %20
store i8* %23, i8** %24
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 2
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds i8*, i8** %14, i64 %20
store i8* %28, i8** %29
%30 = add nuw nsw i64 %20, 1
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %30, %33
br i1 %34, label %19, label %35
35: ; preds = %19, %0
%36 = phi i32 [ %15, %0 ], [ %31, %19 ]
%37 = call i32 @initializeManually(i8** %9, i8** %14, i32 %36)
%38 = load i32, i32* %1
%39 = call i32 @createWall(i8** %9, i8** %14, i32 %38)
%40 = call signext i8 (...) @getchar()
%41 = icmp eq i8 %40, 10
br i1 %41, label %42, label %47
42: ; preds = %35, %42
%43 = load i32, i32* %1
%44 = call i32 @updatePrintMap(i8** %9, i8** %14, i32 %43)
%45 = call signext i8 (...) @getchar()
%46 = icmp eq i8 %45, 10
br i1 %46, label %42, label %47
47: ; preds = %42, %35
%48 = load i32, i32* %1
%49 = call i32 @cleanMemory(i8** %9, i8** %14, i32 %48)
ret i32 0
}