#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*/ release_memory_block(void *);
void *request_memory_block();
int /*<<< orphan*/ rtx_dbug_outs(char *);
void mem_test2() {
  rtx_dbug_outs("Starting Memory Test 2\r\n");
  void *testArray[32];
  rtx_dbug_outs("Requesting all memory blocks\r\n");
  int i;
  for (i = 0; i < 32; i++) {
    testArray[i] = request_memory_block();
  }
  rtx_dbug_outs("All memory blocks requested\r\n");
  for (i = 0; i < 32; i++) {
    release_memory_block(testArray[i]);
  }
  rtx_dbug_outs("All blocks released\r\n");
  void *oneMore;
  oneMore = request_memory_block();
  rtx_dbug_outs("One more block given\r\n");
  release_memory_block(oneMore);
  rtx_dbug_outs("Finished Memory Test 2\r\n");
}


x86 assembly (clang, -O0):
<mem_test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xebe(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
lea    0xecb(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
movl   $0x0,-0x104(%rbp)
cmpl   $0x20,-0x104(%rbp)
jge    1197 <mem_test2+0x67>
mov    $0x0,%al
call   1040 <request_memory_block@plt>
mov    %rax,%rcx
movslq -0x104(%rbp),%rax
mov    %rcx,-0x100(%rbp,%rax,8)
ff
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x104(%rbp)
jmp    115d <mem_test2+0x2d>
lea    0xe9a(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
movl   $0x0,-0x104(%rbp)
cmpl   $0x20,-0x104(%rbp)
jge    11e2 <mem_test2+0xb2>
movslq -0x104(%rbp),%rax
mov    -0x100(%rbp,%rax,8),%rdi
ff
call   1050 <release_memory_block@plt>
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x104(%rbp)
jmp    11ad <mem_test2+0x7d>
lea    0xe6d(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
mov    $0x0,%al
call   1040 <request_memory_block@plt>
mov    %rax,-0x110(%rbp)
lea    0xe69(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
mov    -0x110(%rbp),%rdi
call   1050 <release_memory_block@plt>
lea    0xe68(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_test2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
lea    0xeb8(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
lea    0xec5(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0xd0(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0xc8(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0xc0(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0xb8(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0xb0(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0xa8(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0xa0(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x98(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x90(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x88(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x80(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x78(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x70(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x68(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x60(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x58(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x50(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x48(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x40(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x38(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x30(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x28(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x20(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x18(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,%r15
lea    0xd43(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
mov    0xd0(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0xc8(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0xc0(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0xb8(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0xb0(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0xa8(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0xa0(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x98(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x90(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x88(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x80(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x78(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x70(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x68(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x60(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x58(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x50(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x48(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x40(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x38(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x30(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x28(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x20(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x18(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x10(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    0x8(%rsp),%rdi
call   1050 <release_memory_block@plt>
mov    %r12,%rdi
call   1050 <release_memory_block@plt>
mov    %r13,%rdi
call   1050 <release_memory_block@plt>
mov    %rbx,%rdi
call   1050 <release_memory_block@plt>
mov    %rbp,%rdi
call   1050 <release_memory_block@plt>
mov    %r14,%rdi
call   1050 <release_memory_block@plt>
mov    %r15,%rdi
call   1050 <release_memory_block@plt>
lea    0xc00(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
xor    %eax,%eax
call   1040 <request_memory_block@plt>
mov    %rax,%rbx
lea    0xc00(%rip),%rdi
call   1030 <rtx_dbug_outs@plt>
mov    %rbx,%rdi
call   1050 <release_memory_block@plt>
lea    0xc03(%rip),%rdi
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <rtx_dbug_outs@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Starting Memory Test 2\0D\0A\00"
@.str.1 = [31 x i8] c"Requesting all memory blocks\0D\0A\00"
@.str.2 = [30 x i8] c"All memory blocks requested\0D\0A\00"
@.str.3 = [22 x i8] c"All blocks released\0D\0A\00"
@.str.4 = [23 x i8] c"One more block given\0D\0A\00"
@.str.5 = [25 x i8] c"Finished Memory Test 2\0D\0A\00"
define void @mem_test2() {
%1 = alloca [32 x i8*]
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 32
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = call i8* (...) @request_memory_block()
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [32 x i8*], [32 x i8*]* %1, i64 0, i64 %12
store i8* %10, i8** %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %6
17: ; preds = %6
%18 = call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %19
19: ; preds = %28, %17
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 32
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [32 x i8*], [32 x i8*]* %1, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @release_memory_block(i8* %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %19
31: ; preds = %19
%32 = call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%33 = call i8* (...) @request_memory_block()
store i8* %33, i8** %3
%34 = call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%35 = load i8*, i8** %3
%36 = call i32 @release_memory_block(i8* %35)
%37 = call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Starting Memory Test 2\0D\0A\00"
@.str.1 = [31 x i8] c"Requesting all memory blocks\0D\0A\00"
@.str.2 = [30 x i8] c"All memory blocks requested\0D\0A\00"
@.str.3 = [22 x i8] c"All blocks released\0D\0A\00"
@.str.4 = [23 x i8] c"One more block given\0D\0A\00"
@.str.5 = [25 x i8] c"Finished Memory Test 2\0D\0A\00"
define void @mem_test2() {
%1 = tail call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* (...) @request_memory_block()
%4 = tail call i8* (...) @request_memory_block()
%5 = tail call i8* (...) @request_memory_block()
%6 = tail call i8* (...) @request_memory_block()
%7 = tail call i8* (...) @request_memory_block()
%8 = tail call i8* (...) @request_memory_block()
%9 = tail call i8* (...) @request_memory_block()
%10 = tail call i8* (...) @request_memory_block()
%11 = tail call i8* (...) @request_memory_block()
%12 = tail call i8* (...) @request_memory_block()
%13 = tail call i8* (...) @request_memory_block()
%14 = tail call i8* (...) @request_memory_block()
%15 = tail call i8* (...) @request_memory_block()
%16 = tail call i8* (...) @request_memory_block()
%17 = tail call i8* (...) @request_memory_block()
%18 = tail call i8* (...) @request_memory_block()
%19 = tail call i8* (...) @request_memory_block()
%20 = tail call i8* (...) @request_memory_block()
%21 = tail call i8* (...) @request_memory_block()
%22 = tail call i8* (...) @request_memory_block()
%23 = tail call i8* (...) @request_memory_block()
%24 = tail call i8* (...) @request_memory_block()
%25 = tail call i8* (...) @request_memory_block()
%26 = tail call i8* (...) @request_memory_block()
%27 = tail call i8* (...) @request_memory_block()
%28 = tail call i8* (...) @request_memory_block()
%29 = tail call i8* (...) @request_memory_block()
%30 = tail call i8* (...) @request_memory_block()
%31 = tail call i8* (...) @request_memory_block()
%32 = tail call i8* (...) @request_memory_block()
%33 = tail call i8* (...) @request_memory_block()
%34 = tail call i8* (...) @request_memory_block()
%35 = tail call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%36 = tail call i32 @release_memory_block(i8* %3)
%37 = tail call i32 @release_memory_block(i8* %4)
%38 = tail call i32 @release_memory_block(i8* %5)
%39 = tail call i32 @release_memory_block(i8* %6)
%40 = tail call i32 @release_memory_block(i8* %7)
%41 = tail call i32 @release_memory_block(i8* %8)
%42 = tail call i32 @release_memory_block(i8* %9)
%43 = tail call i32 @release_memory_block(i8* %10)
%44 = tail call i32 @release_memory_block(i8* %11)
%45 = tail call i32 @release_memory_block(i8* %12)
%46 = tail call i32 @release_memory_block(i8* %13)
%47 = tail call i32 @release_memory_block(i8* %14)
%48 = tail call i32 @release_memory_block(i8* %15)
%49 = tail call i32 @release_memory_block(i8* %16)
%50 = tail call i32 @release_memory_block(i8* %17)
%51 = tail call i32 @release_memory_block(i8* %18)
%52 = tail call i32 @release_memory_block(i8* %19)
%53 = tail call i32 @release_memory_block(i8* %20)
%54 = tail call i32 @release_memory_block(i8* %21)
%55 = tail call i32 @release_memory_block(i8* %22)
%56 = tail call i32 @release_memory_block(i8* %23)
%57 = tail call i32 @release_memory_block(i8* %24)
%58 = tail call i32 @release_memory_block(i8* %25)
%59 = tail call i32 @release_memory_block(i8* %26)
%60 = tail call i32 @release_memory_block(i8* %27)
%61 = tail call i32 @release_memory_block(i8* %28)
%62 = tail call i32 @release_memory_block(i8* %29)
%63 = tail call i32 @release_memory_block(i8* %30)
%64 = tail call i32 @release_memory_block(i8* %31)
%65 = tail call i32 @release_memory_block(i8* %32)
%66 = tail call i32 @release_memory_block(i8* %33)
%67 = tail call i32 @release_memory_block(i8* %34)
%68 = tail call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%69 = tail call i8* (...) @request_memory_block()
%70 = tail call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%71 = tail call i32 @release_memory_block(i8* %69)
%72 = tail call i32 @rtx_dbug_outs(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
ret void
}