#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*/ end_memory();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ get_memory(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ start_memory(int);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
int main(int argc, char **argv) {
  int startMemory = 0;
  int memorySize = 0;
  int count = 0;
  char text[20];
  char allo[5] = "allo", quit[5] = "quit";
  printf("Enter the memory size:");
  scanf("%d", &startMemory);
  start_memory(startMemory);
  while (1) {
    fgets(text, sizeof text, stdin);
    strtok(text, "\n");
    if (strcmp(text, quit) == 0) {
      if (count == 1) {
        exit(0);
      }
      end_memory();
      exit(0);
    } else if (strcmp(text, allo) == 0) {
      printf("Enter the amount you want to be allocated: ");
      scanf("%d", &memorySize);
      get_memory(memorySize);
    } else {
      printf("Enter the command. 'allo' to allocate memory; 'quit' to quit the "
             "system.\n\n");
    }
    count++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0xe3f(%rip),%eax
mov    %eax,-0x35(%rbp)
mov    0xe3a(%rip),%al
mov    %al,-0x31(%rbp)
mov    0xe32(%rip),%eax
mov    %eax,-0x3a(%rbp)
mov    0xe2d(%rip),%al
mov    %al,-0x36(%rbp)
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
lea    0xe2f(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x14(%rbp),%edi
call   1030 <start_memory@plt>
lea    -0x30(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    -0x30(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   10a0 <strtok@plt>
lea    -0x30(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1260 <main+0xd0>
cmpl   $0x1,-0x1c(%rbp)
jne    1252 <main+0xc2>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1050 <end_memory@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x30(%rbp),%rdi
lea    -0x35(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12a0 <main+0x110>
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
lea    0xd97(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x18(%rbp),%edi
call   1080 <get_memory@plt>
jmp    12ac <main+0x11c>
lea    0xda9(%rip),%rdi
call   1040 <printf@plt>
jmp    12b1 <main+0x121>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1203 <main+0x73>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movb   $0x0,0x1c(%rsp)
movl   $0x6f6c6c61,0x18(%rsp)
6f
movb   $0x0,0xc(%rsp)
movl   $0x74697571,0x8(%rsp)
74
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
lea    0xe36(%rip),%rdi
lea    0x14(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0x14(%rsp),%edi
call   1040 <start_memory@plt>
mov    0x2de3(%rip),%r13
mov    0x0(%r13),%edx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1070 <fgets@plt>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strtok@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12e0 <main+0x140>
mov    $0x1,%r12d
lea    0x20(%rsp),%rbx
lea    0x18(%rsp),%r14
lea    0xe41(%rip),%rbp
lea    0x8(%rsp),%r15
jmp    129c <main+0xfc>
xchg   %ax,%ax
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <strtok@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
add    $0xffffffff,%r12d
test   %rax,%rax
je     12d4 <main+0x134>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1260 <main+0xc0>
lea    0xd71(%rip),%rdi
call   1050 <printf@plt>
lea    0xd62(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0x10(%rsp),%edi
call   1090 <get_memory@plt>
jmp    126c <main+0xcc>
test   %r12d,%r12d
jne    12e0 <main+0x140>
xor    %edi,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
call   1060 <end_memory@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.main.allo = [5 x i8] c"allo\00"
@__const.main.quit = [5 x i8] c"quit\00"
@.str = [23 x i8] c"Enter the memory size:\00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [44 x i8] c"Enter the amount you want to be allocated: \00"
@.str.4 = [75 x i8] c"Enter the command. 'allo' to allocate memory; 'quit' to quit the system.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [20 x i8]
%10 = alloca [5 x i8]
%11 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%12 = bitcast [5 x i8]* %10 to i8*
%13 = bitcast [5 x i8]* %11 to i8*
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%16 = load i32, i32* %6
%17 = call i32 @start_memory(i32 %16)
br label %18
18: ; preds = %2, %49
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %19, i32 20, i32 %20)
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%23 = call i32 @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %18
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %28
%34 = call i32 (...) @end_memory()
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %18
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%39 = call i64 @strcmp(i8* %37, i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%44 = load i32, i32* %7
%45 = call i32 @get_memory(i32 %44)
br label %48
46: ; preds = %36
%47 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %18
}

LLVM IR (-O2):
@__const.main.allo = [5 x i8] c"allo\00"
@__const.main.quit = [5 x i8] c"quit\00"
@.str = [23 x i8] c"Enter the memory size:\00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [44 x i8] c"Enter the amount you want to be allocated: \00"
@str = [74 x i8] c"Enter the command. 'allo' to allocate memory; 'quit' to quit the system.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca [5 x i8]
%7 = alloca [5 x i8]
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
%16 = call i32 @start_memory(i32 %15)
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %10, i32 20, i32 %17)
%19 = call i32 @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = call i64 @strcmp(i8* %10, i8* %12)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %29
22: ; preds = %40
%23 = icmp eq i32 %30, 0
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %2, %22
%27 = call i32 (...) @end_memory()
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %2, %40
%30 = phi i32 [ %41, %40 ], [ 0, %2 ]
%31 = call i64 @strcmp(i8* %10, i8* %11)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%36 = load i32, i32* %4
%37 = call i32 @get_memory(i32 %36)
br label %40
38: ; preds = %29
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %33, %38
%41 = add nuw nsw i32 %30, 1
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %10, i32 20, i32 %42)
%44 = call i32 @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%45 = call i64 @strcmp(i8* %10, i8* %12)
%46 = icmp eq i64 %45, 0
br i1 %46, label %22, label %29
}