#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*/ my_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;
  int success = 0;
  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);
  if (buffer1 >= 0 && buffer2 >= 0 && buffer3 >= 0 && buffer4 >= 0)
    success = 1;
  my_free(buffer1);
  my_free(buffer2);
  my_free(buffer3);
  my_free(buffer4);
  if (success)
    printf(" Test passed.\n");
  else
    printf(" Test failed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
mov    $0x40,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x80,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x100,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x200,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
jb     1200 <main+0xd0>
cmpq   $0x0,-0x20(%rbp)
jb     1200 <main+0xd0>
cmpq   $0x0,-0x28(%rbp)
jb     1200 <main+0xd0>
cmpq   $0x0,-0x30(%rbp)
jb     1200 <main+0xd0>
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <my_free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <my_free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <my_free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <my_free@plt>
cmpl   $0x0,-0x34(%rbp)
je     1241 <main+0x111>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124f <main+0x11f>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x40,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r15
lea    0xea3(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x80,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x100,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x200,%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1060 <my_free@plt>
mov    %r12,%rdi
call   1060 <my_free@plt>
mov    %r13,%rdi
call   1060 <my_free@plt>
mov    %rbx,%rdi
call   1060 <my_free@plt>
lea    0xe37(%rip),%rdi
call   1040 <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 = [15 x i8] c" Test passed.\0A\00"
@.str.2 = [15 x i8] c" Test failed.\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*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = call i64 @my_malloc(i32 64)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i64 @my_malloc(i32 128)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i64 @my_malloc(i32 256)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i64 @my_malloc(i32 512)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %6
%28 = icmp uge i8* %27, null
br i1 %28, label %29, label %39
29: ; preds = %2
%30 = load i8*, i8** %7
%31 = icmp uge i8* %30, null
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = icmp uge i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i8*, i8** %9
%37 = icmp uge i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 1, i32* %10
br label %39
39: ; preds = %38, %35, %32, %29, %2
%40 = load i8*, i8** %6
%41 = call i32 @my_free(i8* %40)
%42 = load i8*, i8** %7
%43 = call i32 @my_free(i8* %42)
%44 = load i8*, i8** %8
%45 = call i32 @my_free(i8* %44)
%46 = load i8*, i8** %9
%47 = call i32 @my_free(i8* %46)
%48 = load i32, i32* %10
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %39
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %54
52: ; preds = %39
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"little_malloc: 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 @my_free(i8* %4)
%16 = tail call i32 @my_free(i8* %7)
%17 = tail call i32 @my_free(i8* %10)
%18 = tail call i32 @my_free(i8* %13)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
ret i32 0
}