#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 *Fabric_memalloc(int);
int /*<<< orphan*/ Fabric_memfree(void *, int);
int Fabric_meminit();
void *Fabric_memrealloc(void *, int, int);
int Fabric_memused();
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *);
void test_memory() {
  void *ptrs[509];
  int i;
  void *ptr;
  assert(Fabric_meminit() == 0x00000000);
  assert(Fabric_memused() == 0);
  for (i = 0; i < 509; i++) {
    ptrs[i] = Fabric_memalloc(6);
    assert(ptrs[i] != NULL);
  }
  assert(Fabric_memused() == 509 * 6);
  for (i = 0; i < 509; i++) {
    ptrs[i] = Fabric_memrealloc(ptrs[i], 10, 6);
    assert(ptrs[i] != NULL);
  }
  assert(Fabric_memused() == 509 * 10);
  for (i = 0; i < 509; i++) {
    ptrs[i] = Fabric_memrealloc(ptrs[i], 6, 10);
    assert(ptrs[i] != NULL);
  }
  assert(Fabric_memused() == 509 * 6);
  for (i = 0; i < 509; i++) {
    Fabric_memfree(ptrs[i], 6);
  }
  assert(Fabric_memused() == 0);
  printf("All tests past for memory module.\n");
}


x86 assembly (clang, -O0):
<test_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1000,%rsp
mov    $0x0,%al
call   1060 <Fabric_meminit@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1040 <Fabric_memused@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movl   $0x0,-0xff4(%rbp)
cmpl   $0x1fd,-0xff4(%rbp)
jge    1210 <test_memory+0xa0>
mov    $0x6,%edi
call   1030 <Fabric_memalloc@plt>
mov    %rax,%rcx
movslq -0xff4(%rbp),%rax
mov    %rcx,-0xff0(%rbp,%rax,8)
ff
movslq -0xff4(%rbp),%rax
cmpq   $0x0,-0xff0(%rbp,%rax,8)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xff4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xff4(%rbp)
jmp    11b3 <test_memory+0x43>
mov    $0x0,%al
call   1040 <Fabric_memused@plt>
cmp    $0xbee,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movl   $0x0,-0xff4(%rbp)
cmpl   $0x1fd,-0xff4(%rbp)
jge    12a4 <test_memory+0x134>
movslq -0xff4(%rbp),%rax
mov    -0xff0(%rbp,%rax,8),%rdi
ff
mov    $0xa,%esi
mov    $0x6,%edx
call   1080 <Fabric_memrealloc@plt>
mov    %rax,%rcx
movslq -0xff4(%rbp),%rax
mov    %rcx,-0xff0(%rbp,%rax,8)
ff
movslq -0xff4(%rbp),%rax
cmpq   $0x0,-0xff0(%rbp,%rax,8)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xff4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xff4(%rbp)
jmp    1233 <test_memory+0xc3>
mov    $0x0,%al
call   1040 <Fabric_memused@plt>
cmp    $0x13e2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movl   $0x0,-0xff4(%rbp)
cmpl   $0x1fd,-0xff4(%rbp)
jge    1338 <test_memory+0x1c8>
movslq -0xff4(%rbp),%rax
mov    -0xff0(%rbp,%rax,8),%rdi
ff
mov    $0x6,%esi
mov    $0xa,%edx
call   1080 <Fabric_memrealloc@plt>
mov    %rax,%rcx
movslq -0xff4(%rbp),%rax
mov    %rcx,-0xff0(%rbp,%rax,8)
ff
movslq -0xff4(%rbp),%rax
cmpq   $0x0,-0xff0(%rbp,%rax,8)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xff4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xff4(%rbp)
jmp    12c7 <test_memory+0x157>
mov    $0x0,%al
call   1040 <Fabric_memused@plt>
cmp    $0xbee,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movl   $0x0,-0xff4(%rbp)
cmpl   $0x1fd,-0xff4(%rbp)
jge    1398 <test_memory+0x228>
movslq -0xff4(%rbp),%rax
mov    -0xff0(%rbp,%rax,8),%rdi
ff
mov    $0x6,%esi
call   1090 <Fabric_memfree@plt>
mov    -0xff4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xff4(%rbp)
jmp    135b <test_memory+0x1eb>
mov    $0x0,%al
call   1040 <Fabric_memused@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xc4a(%rip),%rdi
call   1050 <printf@plt>
add    $0x1000,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memory>:
push   %rbx
sub    $0xff0,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <Fabric_meminit@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1050 <Fabric_memused@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x6,%edi
call   1040 <Fabric_memalloc@plt>
mov    %rax,(%rsp,%rbx,8)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
add    $0x1,%rbx
cmp    $0x1fd,%rbx
jne    11b0 <test_memory+0x40>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <Fabric_memused@plt>
xor    %edi,%edi
cmp    $0xbee,%eax
sete   %dil
call   1070 <assert@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp,%rbx,8),%rdi
mov    $0xa,%esi
mov    $0x6,%edx
call   1080 <Fabric_memrealloc@plt>
mov    %rax,(%rsp,%rbx,8)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
add    $0x1,%rbx
cmp    $0x1fd,%rbx
jne    1200 <test_memory+0x90>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <Fabric_memused@plt>
xor    %edi,%edi
cmp    $0x13e2,%eax
sete   %dil
call   1070 <assert@plt>
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,8),%rdi
mov    $0x6,%esi
mov    $0xa,%edx
call   1080 <Fabric_memrealloc@plt>
mov    %rax,(%rsp,%rbx,8)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
add    $0x1,%rbx
cmp    $0x1fd,%rbx
jne    1250 <test_memory+0xe0>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <Fabric_memused@plt>
xor    %edi,%edi
cmp    $0xbee,%eax
sete   %dil
call   1070 <assert@plt>
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,8),%rdi
mov    $0x6,%esi
call   1090 <Fabric_memfree@plt>
add    $0x1,%rbx
cmp    $0x1fd,%rbx
jne    12a0 <test_memory+0x130>
xor    %eax,%eax
call   1050 <Fabric_memused@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
lea    0xd2a(%rip),%rdi
add    $0xff0,%rsp
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"All tests past for memory module.\0A\00"
define void @test_memory() {
%1 = alloca [509 x i8*]
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 (...) @Fabric_meminit()
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = call i32 (...) @Fabric_memused()
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
store i32 0, i32* %2
br label %12
12: ; preds = %27, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 509
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = call i8* @Fabric_memalloc(i32 6)
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %18
store i8* %16, i8** %19
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
br label %27
27: ; preds = %15
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %12
30: ; preds = %12
%31 = call i32 (...) @Fabric_memused()
%32 = icmp eq i32 %31, 3054
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
store i32 0, i32* %2
br label %35
35: ; preds = %54, %30
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 509
br i1 %37, label %38, label %57
38: ; preds = %35
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = call i8* @Fabric_memrealloc(i8* %42, i32 10, i32 6)
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %45
store i8* %43, i8** %46
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %48
%50 = load i8*, i8** %49
%51 = icmp ne i8* %50, null
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
br label %54
54: ; preds = %38
%55 = load i32, i32* %2
%56 = add nsw i32 %55, 1
store i32 %56, i32* %2
br label %35
57: ; preds = %35
%58 = call i32 (...) @Fabric_memused()
%59 = icmp eq i32 %58, 5090
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
store i32 0, i32* %2
br label %62
62: ; preds = %81, %57
%63 = load i32, i32* %2
%64 = icmp slt i32 %63, 509
br i1 %64, label %65, label %84
65: ; preds = %62
%66 = load i32, i32* %2
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %67
%69 = load i8*, i8** %68
%70 = call i8* @Fabric_memrealloc(i8* %69, i32 6, i32 10)
%71 = load i32, i32* %2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %72
store i8* %70, i8** %73
%74 = load i32, i32* %2
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %75
%77 = load i8*, i8** %76
%78 = icmp ne i8* %77, null
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
br label %81
81: ; preds = %65
%82 = load i32, i32* %2
%83 = add nsw i32 %82, 1
store i32 %83, i32* %2
br label %62
84: ; preds = %62
%85 = call i32 (...) @Fabric_memused()
%86 = icmp eq i32 %85, 3054
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
store i32 0, i32* %2
br label %89
89: ; preds = %98, %84
%90 = load i32, i32* %2
%91 = icmp slt i32 %90, 509
br i1 %91, label %92, label %101
92: ; preds = %89
%93 = load i32, i32* %2
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %94
%96 = load i8*, i8** %95
%97 = call i32 @Fabric_memfree(i8* %96, i32 6)
br label %98
98: ; preds = %92
%99 = load i32, i32* %2
%100 = add nsw i32 %99, 1
store i32 %100, i32* %2
br label %89
101: ; preds = %89
%102 = call i32 (...) @Fabric_memused()
%103 = icmp eq i32 %102, 0
%104 = zext i1 %103 to i32
%105 = call i32 @assert(i32 %104)
%106 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@str = [34 x i8] c"All tests past for memory module.\00"
define void @test_memory() {
%1 = alloca [509 x i8*]
%2 = bitcast [509 x i8*]* %1 to i8*
%3 = tail call i32 (...) @Fabric_meminit()
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 (...) @Fabric_memused()
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
br label %11
11: ; preds = %0, %11
%12 = phi i64 [ 0, %0 ], [ %18, %11 ]
%13 = tail call i8* @Fabric_memalloc(i32 6)
%14 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %12
store i8* %13, i8** %14
%15 = icmp ne i8* %13, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, 509
br i1 %19, label %20, label %11
20: ; preds = %11
%21 = tail call i32 (...) @Fabric_memused()
%22 = icmp eq i32 %21, 3054
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
br label %25
25: ; preds = %20, %25
%26 = phi i64 [ 0, %20 ], [ %33, %25 ]
%27 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i8* @Fabric_memrealloc(i8* %28, i32 10, i32 6)
store i8* %29, i8** %27
%30 = icmp ne i8* %29, null
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = add nuw nsw i64 %26, 1
%34 = icmp eq i64 %33, 509
br i1 %34, label %35, label %25
35: ; preds = %25
%36 = tail call i32 (...) @Fabric_memused()
%37 = icmp eq i32 %36, 5090
%38 = zext i1 %37 to i32
%39 = tail call i32 @assert(i32 %38)
br label %40
40: ; preds = %35, %40
%41 = phi i64 [ 0, %35 ], [ %48, %40 ]
%42 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %41
%43 = load i8*, i8** %42
%44 = tail call i8* @Fabric_memrealloc(i8* %43, i32 6, i32 10)
store i8* %44, i8** %42
%45 = icmp ne i8* %44, null
%46 = zext i1 %45 to i32
%47 = tail call i32 @assert(i32 %46)
%48 = add nuw nsw i64 %41, 1
%49 = icmp eq i64 %48, 509
br i1 %49, label %50, label %40
50: ; preds = %40
%51 = tail call i32 (...) @Fabric_memused()
%52 = icmp eq i32 %51, 3054
%53 = zext i1 %52 to i32
%54 = tail call i32 @assert(i32 %53)
br label %55
55: ; preds = %50, %55
%56 = phi i64 [ 0, %50 ], [ %60, %55 ]
%57 = getelementptr inbounds [509 x i8*], [509 x i8*]* %1, i64 0, i64 %56
%58 = load i8*, i8** %57
%59 = tail call i32 @Fabric_memfree(i8* %58, i32 6)
%60 = add nuw nsw i64 %56, 1
%61 = icmp eq i64 %60, 509
br i1 %61, label %62, label %55
62: ; preds = %55
%63 = tail call i32 (...) @Fabric_memused()
%64 = icmp eq i32 %63, 0
%65 = zext i1 %64 to i32
%66 = tail call i32 @assert(i32 %65)
%67 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
ret void
}