#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 EXIT_SUCCESS;
int /*<<< orphan*/ free(void *);
void *malloc(int);
void *mem_alloc(int);
int /*<<< orphan*/ mem_dump(char *, int);
int /*<<< orphan*/ mem_free(void *);
void *mem_realloc(void *, int);
int /*<<< orphan*/ printf(char *, void *, void *, void *, void *);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  char *ptr1 = mem_alloc(0x10);
  mem_free(ptr1);
  void *ptr2 = mem_alloc(0x36);
  void *ptr3 = mem_alloc(0x10);
  ptr3 = mem_realloc(ptr3, 0x38);
  mem_free(ptr3);
  void *ptr4 = mem_alloc(0x10);
  mem_free(ptr4);
  void *potr1 = malloc(0x10);
  void *potr2 = malloc(0x10);
  free(potr2);
  void *potr4 = malloc(0x10);
  void *potr3 = malloc(0x100);
  printf("%p\n%p\n%p\n%p\n\n", ptr1, ptr2, ptr3, ptr4);
  printf("%p\n%p\n%p\n%p\n", potr1, potr2, potr3, potr4);
  strcpy(ptr1, "Hello, world!");
  mem_dump(ptr1, 0x10);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <mem_free@plt>
mov    $0x36,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x10,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x38,%esi
call   1070 <mem_realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <mem_free@plt>
mov    $0x10,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <mem_free@plt>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xdb4(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xda6(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xda3(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
call   1080 <mem_dump@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x10,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <mem_free@plt>
mov    $0x36,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x10,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,%rdi
mov    $0x38,%esi
call   1070 <mem_realloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <mem_free@plt>
mov    $0x10,%edi
call   10a0 <mem_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <mem_free@plt>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
lea    0xdd2(%rip),%rdi
mov    %r12,%rsi
mov    0x10(%rsp),%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1060 <printf@plt>
lea    0xdc6(%rip),%rdi
mov    0x8(%rsp),%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
mov    %r14,%r8
call   1060 <printf@plt>
lea    0xdb9(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcpy@plt>
mov    %r12,%rdi
mov    $0x10,%esi
call   1080 <mem_dump@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%p\0A%p\0A%p\0A%p\0A\0A\00"
@.str.1 = [13 x i8] c"%p\0A%p\0A%p\0A%p\0A\00"
@.str.2 = [14 x i8] c"Hello, world!\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %1
%10 = call i8* @mem_alloc(i32 16)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @mem_free(i8* %11)
%13 = call i8* @mem_alloc(i32 54)
store i8* %13, i8** %3
%14 = call i8* @mem_alloc(i32 16)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = call i8* @mem_realloc(i8* %15, i32 56)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = call i32 @mem_free(i8* %17)
%19 = call i8* @mem_alloc(i32 16)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @mem_free(i8* %20)
%22 = call i8* @malloc(i32 16)
store i8* %22, i8** %6
%23 = call i8* @malloc(i32 16)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = call i32 @free(i8* %24)
%26 = call i8* @malloc(i32 16)
store i8* %26, i8** %8
%27 = call i8* @malloc(i32 256)
store i8* %27, i8** %9
%28 = load i8*, i8** %2
%29 = load i8*, i8** %3
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29, i8* %30, i8* %31)
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = load i8*, i8** %9
%36 = load i8*, i8** %8
%37 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %34, i8* %35, i8* %36)
%38 = load i8*, i8** %2
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8*, i8** %2
%41 = call i32 @mem_dump(i8* %40, i32 16)
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}

LLVM IR (-O2):
@.str = [14 x i8] c"%p\0A%p\0A%p\0A%p\0A\0A\00"
@.str.1 = [13 x i8] c"%p\0A%p\0A%p\0A%p\0A\00"
@.str.2 = [14 x i8] c"Hello, world!\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i8* @mem_alloc(i32 16)
%2 = tail call i32 @mem_free(i8* %1)
%3 = tail call i8* @mem_alloc(i32 54)
%4 = tail call i8* @mem_alloc(i32 16)
%5 = tail call i8* @mem_realloc(i8* %4, i32 56)
%6 = tail call i32 @mem_free(i8* %5)
%7 = tail call i8* @mem_alloc(i32 16)
%8 = tail call i32 @mem_free(i8* %7)
%9 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%10 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%11 = tail call i32 @free(i8* %10)
%12 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%13 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %3, i8* %5, i8* %7)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10, i8* %13, i8* %12)
%16 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @mem_dump(i8* %1, i32 16)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}