#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 */
char *dynmem_alloc(int);
scalar_t__ dynmem_avail();
int /*<<< orphan*/ dynmem_free(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcpy(char *, char *);
void test_dynmem(void) {
  printf("[ free mem: %i ]\n", (int)dynmem_avail());
  char *test1 = dynmem_alloc(64);
  printf("[ free mem: %i ]\n", (int)dynmem_avail());
  char *test2 = dynmem_alloc(64);
  printf("[ free mem: %i ]\n", (int)dynmem_avail());
  strcpy(test1, "11111111");
  strcpy(test2, "2222222222222");
  puts(test1);
  puts(test2);
  dynmem_free(test1);
  printf("[ free mem: %i ]\n", (int)dynmem_avail());
  char *test3 = dynmem_alloc(100);
  printf("[ free mem: %i ]\n", (int)dynmem_avail());
  strcpy(test3, "333");
  puts(test2);
  puts(test3);
  dynmem_free(test3);
  dynmem_free(test2);
  if ((test1 = dynmem_alloc(248))) {
    puts("success");
    dynmem_free(test1);
  }
  test1 = dynmem_alloc(60);
  test2 = dynmem_alloc(60);
  test3 = dynmem_alloc(60);
  dynmem_free(test2);
  test2 = dynmem_alloc(72);
  dynmem_free(dynmem_alloc(130));
  dynmem_free(test3);
  dynmem_free(test1);
  dynmem_free(test2);
  printf("[ free mem: %i ]\n", (int)dynmem_avail());
}


x86 assembly (clang, -O0):
<test_dynmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <dynmem_avail@plt>
mov    %eax,%esi
lea    0xe88(%rip),%rdi
call   1060 <printf@plt>
mov    $0x40,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <dynmem_avail@plt>
mov    %eax,%esi
lea    0xe65(%rip),%rdi
call   1060 <printf@plt>
mov    $0x40,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <dynmem_avail@plt>
mov    %eax,%esi
lea    0xe42(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    $0x0,%al
call   1050 <dynmem_avail@plt>
mov    %eax,%esi
lea    0xdf2(%rip),%rdi
call   1060 <printf@plt>
mov    $0x64,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <dynmem_avail@plt>
mov    %eax,%esi
lea    0xdcf(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    -0x10(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    $0xf8,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1297 <test_dynmem+0x137>
lea    0xda4(%rip),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    $0x3c,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x3c,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x3c,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    $0x48,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x82,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%rdi
call   1070 <dynmem_free@plt>
mov    -0x18(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    -0x8(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    -0x10(%rbp),%rdi
call   1070 <dynmem_free@plt>
mov    $0x0,%al
call   1050 <dynmem_avail@plt>
mov    %eax,%esi
lea    0xceb(%rip),%rdi
call   1060 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_dynmem>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <dynmem_avail@plt>
lea    0xe8d(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x40,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <dynmem_avail@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x40,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <dynmem_avail@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe4c(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <dynmem_free@plt>
xor    %eax,%eax
call   1050 <dynmem_avail@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x64,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <dynmem_avail@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
lea    0xe04(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <dynmem_free@plt>
mov    %r15,%rdi
call   1070 <dynmem_free@plt>
mov    $0xf8,%edi
call   1080 <dynmem_alloc@plt>
test   %rax,%rax
je     1273 <test_dynmem+0x113>
mov    %rax,%rbx
lea    0xdc7(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <dynmem_free@plt>
mov    $0x3c,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%r14
mov    $0x3c,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%rbx
mov    $0x3c,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <dynmem_free@plt>
mov    $0x48,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%rbx
mov    $0x82,%edi
call   1080 <dynmem_alloc@plt>
mov    %rax,%rdi
call   1070 <dynmem_free@plt>
mov    %r15,%rdi
call   1070 <dynmem_free@plt>
mov    %r14,%rdi
call   1070 <dynmem_free@plt>
mov    %rbx,%rdi
call   1070 <dynmem_free@plt>
xor    %eax,%eax
call   1050 <dynmem_avail@plt>
lea    0xd19(%rip),%rdi
mov    %eax,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"[ free mem: %i ]\0A\00"
@.str.1 = [9 x i8] c"11111111\00"
@.str.2 = [14 x i8] c"2222222222222\00"
@.str.3 = [4 x i8] c"333\00"
@.str.4 = [8 x i8] c"success\00"
define void @test_dynmem() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i64 (...) @dynmem_avail()
%5 = trunc i64 %4 to i32
%6 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i8* @dynmem_alloc(i32 64)
store i8* %7, i8** %1
%8 = call i64 (...) @dynmem_avail()
%9 = trunc i64 %8 to i32
%10 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i8* @dynmem_alloc(i32 64)
store i8* %11, i8** %2
%12 = call i64 (...) @dynmem_avail()
%13 = trunc i64 %12 to i32
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %1
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %2
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %1
%20 = call i32 @puts(i8* %19)
%21 = load i8*, i8** %2
%22 = call i32 @puts(i8* %21)
%23 = load i8*, i8** %1
%24 = call i32 @dynmem_free(i8* %23)
%25 = call i64 (...) @dynmem_avail()
%26 = trunc i64 %25 to i32
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = call i8* @dynmem_alloc(i32 100)
store i8* %28, i8** %3
%29 = call i64 (...) @dynmem_avail()
%30 = trunc i64 %29 to i32
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i8*, i8** %3
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%34 = load i8*, i8** %2
%35 = call i32 @puts(i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @puts(i8* %36)
%38 = load i8*, i8** %3
%39 = call i32 @dynmem_free(i8* %38)
%40 = load i8*, i8** %2
%41 = call i32 @dynmem_free(i8* %40)
%42 = call i8* @dynmem_alloc(i32 248)
store i8* %42, i8** %1
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %0
%45 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%46 = load i8*, i8** %1
%47 = call i32 @dynmem_free(i8* %46)
br label %48
48: ; preds = %44, %0
%49 = call i8* @dynmem_alloc(i32 60)
store i8* %49, i8** %1
%50 = call i8* @dynmem_alloc(i32 60)
store i8* %50, i8** %2
%51 = call i8* @dynmem_alloc(i32 60)
store i8* %51, i8** %3
%52 = load i8*, i8** %2
%53 = call i32 @dynmem_free(i8* %52)
%54 = call i8* @dynmem_alloc(i32 72)
store i8* %54, i8** %2
%55 = call i8* @dynmem_alloc(i32 130)
%56 = call i32 @dynmem_free(i8* %55)
%57 = load i8*, i8** %3
%58 = call i32 @dynmem_free(i8* %57)
%59 = load i8*, i8** %1
%60 = call i32 @dynmem_free(i8* %59)
%61 = load i8*, i8** %2
%62 = call i32 @dynmem_free(i8* %61)
%63 = call i64 (...) @dynmem_avail()
%64 = trunc i64 %63 to i32
%65 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %64)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"[ free mem: %i ]\0A\00"
@.str.1 = [9 x i8] c"11111111\00"
@.str.2 = [14 x i8] c"2222222222222\00"
@.str.3 = [4 x i8] c"333\00"
@.str.4 = [8 x i8] c"success\00"
define void @test_dynmem() {
%1 = tail call i64 (...) @dynmem_avail()
%2 = trunc i64 %1 to i32
%3 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i8* @dynmem_alloc(i32 64)
%5 = tail call i64 (...) @dynmem_avail()
%6 = trunc i64 %5 to i32
%7 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i8* @dynmem_alloc(i32 64)
%9 = tail call i64 (...) @dynmem_avail()
%10 = trunc i64 %9 to i32
%11 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) %4)
%15 = tail call i32 @puts(i8* dereferenceable(1) %8)
%16 = tail call i32 @dynmem_free(i8* %4)
%17 = tail call i64 (...) @dynmem_avail()
%18 = trunc i64 %17 to i32
%19 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = tail call i8* @dynmem_alloc(i32 100)
%21 = tail call i64 (...) @dynmem_avail()
%22 = trunc i64 %21 to i32
%23 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = tail call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) %8)
%26 = tail call i32 @puts(i8* dereferenceable(1) %20)
%27 = tail call i32 @dynmem_free(i8* %20)
%28 = tail call i32 @dynmem_free(i8* %8)
%29 = tail call i8* @dynmem_alloc(i32 248)
%30 = icmp eq i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %0
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%33 = tail call i32 @dynmem_free(i8* %29)
br label %34
34: ; preds = %31, %0
%35 = tail call i8* @dynmem_alloc(i32 60)
%36 = tail call i8* @dynmem_alloc(i32 60)
%37 = tail call i8* @dynmem_alloc(i32 60)
%38 = tail call i32 @dynmem_free(i8* %36)
%39 = tail call i8* @dynmem_alloc(i32 72)
%40 = tail call i8* @dynmem_alloc(i32 130)
%41 = tail call i32 @dynmem_free(i8* %40)
%42 = tail call i32 @dynmem_free(i8* %37)
%43 = tail call i32 @dynmem_free(i8* %35)
%44 = tail call i32 @dynmem_free(i8* %39)
%45 = tail call i64 (...) @dynmem_avail()
%46 = trunc i64 %45 to i32
%47 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %46)
ret void
}