#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*/ free(char *);
scalar_t__ my_malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char *buffer1;
  char *buffer2;
  char *buffer3;
  char *buffer4;
  buffer1 = (char *)my_malloc(64);
  printf("little_malloc: 0x%lx\n", buffer1);
  buffer2 = (char *)my_malloc(128);
  printf("little_malloc: 0x%lx\n", buffer2);
  buffer3 = (char *)my_malloc(256);
  printf("little_malloc: 0x%lx\n", buffer3);
  buffer4 = (char *)my_malloc(512);
  printf("little_malloc: 0x%lx\n", buffer4);
  printf("little_malloc: freeing 0x%lx\n", buffer1);
  free(buffer1);
  printf("little_malloc: freeing 0x%lx\n", buffer2);
  free(buffer2);
  printf("little_malloc: freeing 0x%lx\n", buffer3);
  free(buffer3);
  printf("little_malloc: freeing 0x%lx\n", buffer4);
  free(buffer4);
  printf(" Test passed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x40,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x80,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x100,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x200,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x40,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r14
lea    0xea3(%rip),%r13
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x80,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x100,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x200,%edi
call   1040 <my_malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe57(%rip),%r13
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe1a(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"little_malloc: 0x%lx\0A\00"
@.str.1 = [30 x i8] c"little_malloc: freeing 0x%lx\0A\00"
@.str.2 = [15 x i8] c" Test passed.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 @my_malloc(i32 64)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i64 @my_malloc(i32 128)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i64 @my_malloc(i32 256)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i64 @my_malloc(i32 512)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %7
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %8
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %9
%41 = call i32 @free(i8* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"little_malloc: 0x%lx\0A\00"
@.str.1 = [30 x i8] c"little_malloc: freeing 0x%lx\0A\00"
@str = [14 x i8] c" Test passed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @my_malloc(i32 64)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = tail call i64 @my_malloc(i32 128)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i64 @my_malloc(i32 256)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i64 @my_malloc(i32 512)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%16 = tail call i32 @free(i8* %4)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%18 = tail call i32 @free(i8* %7)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%20 = tail call i32 @free(i8* %10)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%22 = tail call i32 @free(i8* %13)
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
ret i32 0
}