#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 */
void *Mem_Alloc(int);
int /*<<< orphan*/ Mem_Dump();
scalar_t__ Mem_Free(void *);
scalar_t__ Mem_Init(int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main() {
  assert(Mem_Init(4096) == 0);
  void *ptr[4];
  ptr[0] = Mem_Alloc(4);
  Mem_Dump();
  ptr[1] = Mem_Alloc(8);
  Mem_Dump();
  printf("\nBEFORE\n");
  assert(Mem_Free(ptr[0]) == 0);
  Mem_Dump();
  assert(Mem_Free(ptr[1]) == 0);
  Mem_Dump();
  printf("\nPASSSSSS\n");
  ptr[2] = Mem_Alloc(16);
  ptr[3] = Mem_Alloc(4);
  Mem_Dump();
  printf("\nBEFORE\n");
  assert(Mem_Free(ptr[2]) == 0);
  assert(Mem_Free(ptr[3]) == 0);
  Mem_Dump();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1000,%edi
call   1030 <Mem_Init@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x4,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <Mem_Dump@plt>
mov    $0x8,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <Mem_Dump@plt>
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <Mem_Free@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1060 <Mem_Dump@plt>
mov    -0x28(%rbp),%rdi
call   1050 <Mem_Free@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1060 <Mem_Dump@plt>
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x10,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x4,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <Mem_Dump@plt>
lea    0xdb8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <Mem_Free@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <Mem_Free@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1060 <Mem_Dump@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1000,%edi
call   1030 <Mem_Init@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    $0x4,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <Mem_Dump@plt>
mov    $0x8,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1060 <Mem_Dump@plt>
lea    0xe4e(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <Mem_Free@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1060 <Mem_Dump@plt>
mov    %r15,%rdi
call   1050 <Mem_Free@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1060 <Mem_Dump@plt>
lea    0xdfb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x10,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1080 <Mem_Alloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1060 <Mem_Dump@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <Mem_Free@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %r15,%rdi
call   1050 <Mem_Free@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1060 <Mem_Dump@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"\0ABEFORE\0A\00"
@.str.1 = [11 x i8] c"\0APASSSSSS\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8*]
store i32 0, i32* %1
%3 = call i64 @Mem_Init(i32 4096)
%4 = icmp eq i64 %3, 0
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = call i8* @Mem_Alloc(i32 4)
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
store i8* %7, i8** %8
%9 = call i32 (...) @Mem_Dump()
%10 = call i8* @Mem_Alloc(i32 8)
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 1
store i8* %10, i8** %11
%12 = call i32 (...) @Mem_Dump()
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%15 = load i8*, i8** %14
%16 = call i64 @Mem_Free(i8* %15)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 (...) @Mem_Dump()
%21 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @Mem_Free(i8* %22)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 (...) @Mem_Dump()
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%29 = call i8* @Mem_Alloc(i32 16)
%30 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 2
store i8* %29, i8** %30
%31 = call i8* @Mem_Alloc(i32 4)
%32 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 3
store i8* %31, i8** %32
%33 = call i32 (...) @Mem_Dump()
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%35 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 2
%36 = load i8*, i8** %35
%37 = call i64 @Mem_Free(i8* %36)
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 3
%42 = load i8*, i8** %41
%43 = call i64 @Mem_Free(i8* %42)
%44 = icmp eq i64 %43, 0
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = call i32 (...) @Mem_Dump()
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@str.2 = [10 x i8] c"\0APASSSSSS\00"
@str.3 = [8 x i8] c"\0ABEFORE\00"
define i32 @main() {
%1 = tail call i64 @Mem_Init(i32 4096)
%2 = icmp eq i64 %1, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i8* @Mem_Alloc(i32 4)
%6 = tail call i32 (...) @Mem_Dump()
%7 = tail call i8* @Mem_Alloc(i32 8)
%8 = tail call i32 (...) @Mem_Dump()
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.3, i64 0, i64 0))
%10 = tail call i64 @Mem_Free(i8* %5)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 (...) @Mem_Dump()
%15 = tail call i64 @Mem_Free(i8* %7)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 (...) @Mem_Dump()
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.2, i64 0, i64 0))
%21 = tail call i8* @Mem_Alloc(i32 16)
%22 = tail call i8* @Mem_Alloc(i32 4)
%23 = tail call i32 (...) @Mem_Dump()
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.3, i64 0, i64 0))
%25 = tail call i64 @Mem_Free(i8* %21)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
%29 = tail call i64 @Mem_Free(i8* %22)
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = tail call i32 (...) @Mem_Dump()
%34 = tail call i32 @exit(i32 0)
unreachable
}