#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*/ deallocateMemory(int, void **);
int /*<<< orphan*/ initializeMemoryBlocks(int, void **);
int /*<<< orphan*/ isNullPointer(void **);
int /*<<< orphan*/ printLine(char *, int, int);
int /*<<< orphan*/ printNewLineCharacter();
int /*<<< orphan*/ printf(char *, int);
int allocateMemory(int memory_amount) {
  void *memory_pointer[memory_amount];
  printf("You requested %i MegaByte(s) of memory.", memory_amount);
  printNewLineCharacter();
  printLine("Press enter to attempt allocation...", 0, 1);
  printNewLineCharacter();
  printLine("Initializing memory blocks...", 1, 0);
  if (!isNullPointer(memory_pointer)) {
    initializeMemoryBlocks(memory_amount, memory_pointer);
    printLine("Success!", 1, 0);
    printNewLineCharacter();
    deallocateMemory(memory_amount, memory_pointer);
    return 0;
  }
  printLine("Failure!", 1, 0);
  return 1;
}


x86 assembly (clang, -O0):
<allocateMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <printNewLineCharacter@plt>
lea    0xe79(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <printLine@plt>
mov    $0x0,%al
call   1080 <printNewLineCharacter@plt>
lea    0xe84(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <printLine@plt>
mov    -0x28(%rbp),%rdi
call   1050 <isNullPointer@plt>
cmp    $0x0,%eax
jne    122c <allocateMemory+0xcc>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
call   1040 <initializeMemoryBlocks@plt>
lea    0xe71(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <printLine@plt>
mov    $0x0,%al
call   1080 <printNewLineCharacter@plt>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
call   1060 <deallocateMemory@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    124d <allocateMemory+0xed>
lea    0xe41(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <printLine@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateMemory>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    %edi,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe75(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <printNewLineCharacter@plt>
lea    0xe84(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <printLine@plt>
xor    %eax,%eax
call   1080 <printNewLineCharacter@plt>
lea    0xe8f(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <printLine@plt>
mov    %rbx,%rdi
call   1050 <isNullPointer@plt>
test   %eax,%eax
je     11f1 <allocateMemory+0x91>
lea    0xe97(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <printLine@plt>
mov    $0x1,%r15d
jmp    1221 <allocateMemory+0xc1>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <initializeMemoryBlocks@plt>
lea    0xe68(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <printLine@plt>
xor    %eax,%eax
call   1080 <printNewLineCharacter@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1060 <deallocateMemory@plt>
mov    %r15d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"You requested %i MegaByte(s) of memory.\00"
@.str.1 = [37 x i8] c"Press enter to attempt allocation...\00"
@.str.2 = [30 x i8] c"Initializing memory blocks...\00"
@.str.3 = [9 x i8] c"Success!\00"
@.str.4 = [9 x i8] c"Failure!\00"
define i32 @allocateMemory(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i8*, i64 %8
store i64 %8, i64* %5
%11 = load i32, i32* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (...) @printNewLineCharacter()
%14 = call i32 @printLine(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1)
%15 = call i32 (...) @printNewLineCharacter()
%16 = call i32 @printLine(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 0)
%17 = call i32 @isNullPointer(i8** %10)
%18 = icmp ne i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %1
%20 = load i32, i32* %3
%21 = call i32 @initializeMemoryBlocks(i32 %20, i8** %10)
%22 = call i32 @printLine(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0)
%23 = call i32 (...) @printNewLineCharacter()
%24 = load i32, i32* %3
%25 = call i32 @deallocateMemory(i32 %24, i8** %10)
store i32 0, i32* %2
store i32 1, i32* %6
br label %28
26: ; preds = %1
%27 = call i32 @printLine(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 0)
store i32 1, i32* %2
store i32 1, i32* %6
br label %28
28: ; preds = %26, %19
%29 = load i8*, i8** %4
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str = [40 x i8] c"You requested %i MegaByte(s) of memory.\00"
@.str.1 = [37 x i8] c"Press enter to attempt allocation...\00"
@.str.2 = [30 x i8] c"Initializing memory blocks...\00"
@.str.3 = [9 x i8] c"Success!\00"
@.str.4 = [9 x i8] c"Failure!\00"
define i32 @allocateMemory(i32 %0) {
%2 = zext i32 %0 to i64
%3 = alloca i8*, i64 %2
%4 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = tail call i32 (...) @printNewLineCharacter()
%6 = tail call i32 @printLine(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1)
%7 = tail call i32 (...) @printNewLineCharacter()
%8 = tail call i32 @printLine(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 0)
%9 = call i32 @isNullPointer(i8** %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = call i32 @initializeMemoryBlocks(i32 %0, i8** %3)
%13 = call i32 @printLine(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0)
%14 = call i32 (...) @printNewLineCharacter()
%15 = call i32 @deallocateMemory(i32 %0, i8** %3)
br label %18
16: ; preds = %1
%17 = call i32 @printLine(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 0)
br label %18
18: ; preds = %16, %11
%19 = phi i32 [ 1, %16 ], [ 0, %11 ]
ret i32 %19
}