#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*/ cmalloc_free(void *);
void *cmalloc_malloc(int);
void *cmalloc_memalign(int, int);
void *cmalloc_realloc(void *, int);
int /*<<< orphan*/ printf(char *, void *);
int main(int argc, char *argv[]) {
  void *large_mem = cmalloc_malloc(1 * (size_t)1024 * (size_t)1024);
  printf("large mem: %p\n", large_mem);
  cmalloc_free(large_mem);
  void *small_ptr = cmalloc_malloc(17);
  printf("small mem: %p", small_ptr);
  printf(" -> %p\n", cmalloc_realloc(small_ptr, 1));
  cmalloc_free(small_ptr);
  void *aligned_mem = cmalloc_memalign(256, 78);
  printf("aligned mem: %p", aligned_mem);
  cmalloc_free(aligned_mem);
  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    $0x100000,%edi
call   1060 <cmalloc_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <cmalloc_free@plt>
mov    $0x11,%edi
call   1060 <cmalloc_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1050 <cmalloc_realloc@plt>
mov    %rax,%rsi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <cmalloc_free@plt>
mov    $0x100,%edi
mov    $0x4e,%esi
call   1040 <cmalloc_memalign@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <cmalloc_free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x100000,%edi
call   1060 <cmalloc_malloc@plt>
mov    %rax,%rbx
lea    0xe9b(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1070 <cmalloc_free@plt>
mov    $0x11,%edi
call   1060 <cmalloc_malloc@plt>
mov    %rax,%rbx
lea    0xe86(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <cmalloc_realloc@plt>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1070 <cmalloc_free@plt>
mov    $0x100,%edi
mov    $0x4e,%esi
call   1040 <cmalloc_memalign@plt>
mov    %rax,%rbx
lea    0xe57(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1070 <cmalloc_free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"large mem: %p\0A\00"
@.str.1 = [14 x i8] c"small mem: %p\00"
@.str.2 = [8 x i8] c" -> %p\0A\00"
@.str.3 = [16 x i8] c"aligned mem: %p\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @cmalloc_malloc(i32 1048576)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %6
%13 = call i32 @cmalloc_free(i8* %12)
%14 = call i8* @cmalloc_malloc(i32 17)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %7
%18 = call i8* @cmalloc_realloc(i8* %17, i32 1)
%19 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %7
%21 = call i32 @cmalloc_free(i8* %20)
%22 = call i8* @cmalloc_memalign(i32 256, i32 78)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %8
%26 = call i32 @cmalloc_free(i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"large mem: %p\0A\00"
@.str.1 = [14 x i8] c"small mem: %p\00"
@.str.2 = [8 x i8] c" -> %p\0A\00"
@.str.3 = [16 x i8] c"aligned mem: %p\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @cmalloc_malloc(i32 1048576)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i32 @cmalloc_free(i8* %3)
%6 = tail call i8* @cmalloc_malloc(i32 17)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = tail call i8* @cmalloc_realloc(i8* %6, i32 1)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = tail call i32 @cmalloc_free(i8* %6)
%11 = tail call i8* @cmalloc_memalign(i32 256, i32 78)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = tail call i32 @cmalloc_free(i8* %11)
ret i32 0
}