#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 MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
void *__libc_calloc(int, int);
void *calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
void *malloc(int);
void *memalign(int, int);
char *mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int posix_memalign(void **, int, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int ret;
  void *p;
  char *mm;
  void *m = malloc(16);
  void *n = malloc(1024);
  free(m);
  free(calloc(10, 120));
  m = __libc_calloc(5, 555);
  mm = mmap(0, 10 * 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
            -1, 0);
  mm[0] = 'X';
  free(m);
  munmap(mm, 10 * 1024);
  p = memalign(11, 1234);
  ret = posix_memalign(&m, 32, 500);
  free(n);
  free(m);
  free(p);
  printf("End 'test'\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0xa,%edi
mov    $0x78,%esi
call   1060 <calloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x5,%edi
mov    $0x22b,%esi
call   1080 <__libc_calloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
mov    0x2dc2(%rip),%rax
or     (%rax),%edx
mov    0x2db1(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc0(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0x2800,%esi
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x58,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2800,%esi
call   10a0 <munmap@plt>
mov    $0xb,%edi
mov    $0x4d2,%esi
call   1070 <memalign@plt>
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x20,%esi
mov    $0x1f4,%edx
call   10c0 <posix_memalign@plt>
mov    %eax,-0x8(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xd5b(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xa,%edi
mov    $0x78,%esi
call   1060 <calloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x5,%edi
mov    $0x22b,%esi
call   1080 <__libc_calloc@plt>
mov    %rax,(%rsp)
mov    0x2e01(%rip),%rax
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dbf(%rip),%rax
mov    0x2dd0(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x2800,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbx
movb   $0x58,(%rax)
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    $0x2800,%esi
call   10a0 <munmap@plt>
mov    $0xb,%edi
mov    $0x4d2,%esi
call   1070 <memalign@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x20,%esi
mov    $0x1f4,%edx
call   10c0 <posix_memalign@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd77(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [12 x i8] c"End 'test'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i8* @malloc(i32 16)
store i8* %7, i8** %5
%8 = call i8* @malloc(i32 1024)
store i8* %8, i8** %6
%9 = load i8*, i8** %5
%10 = call i32 @free(i8* %9)
%11 = call i8* @calloc(i32 10, i32 120)
%12 = call i32 @free(i8* %11)
%13 = call i8* @__libc_calloc(i32 5, i32 555)
store i8* %13, i8** %5
%14 = load i32, i32* @PROT_READ
%15 = load i32, i32* @PROT_WRITE
%16 = or i32 %14, %15
%17 = load i32, i32* @MAP_PRIVATE
%18 = load i32, i32* @MAP_ANONYMOUS
%19 = or i32 %17, %18
%20 = call i8* @mmap(i32 0, i32 10240, i32 %16, i32 %19, i32 -1, i32 0)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 88, i8* %22
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 @munmap(i8* %25, i32 10240)
%27 = call i8* @memalign(i32 11, i32 1234)
store i8* %27, i8** %3
%28 = call i32 @posix_memalign(i8** %5, i32 32, i32 500)
store i32 %28, i32* %2
%29 = load i8*, i8** %6
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %5
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@str = [11 x i8] c"End 'test'\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%5 = tail call i32 @free(i8* %3)
%6 = tail call dereferenceable_or_null(1200) i8* @calloc(i32 10, i32 120)
%7 = tail call i32 @free(i8* %6)
%8 = tail call i8* @__libc_calloc(i32 5, i32 555)
store i8* %8, i8** %1
%9 = load i32, i32* @PROT_READ
%10 = load i32, i32* @PROT_WRITE
%11 = or i32 %10, %9
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_ANONYMOUS
%14 = or i32 %13, %12
%15 = tail call i8* @mmap(i32 0, i32 10240, i32 %11, i32 %14, i32 -1, i32 0)
store i8 88, i8* %15
%16 = load i8*, i8** %1
%17 = tail call i32 @free(i8* %16)
%18 = tail call i32 @munmap(i8* %15, i32 10240)
%19 = tail call dereferenceable_or_null(1234) i8* @memalign(i32 11, i32 1234)
%20 = call i32 @posix_memalign(i8** %1, i32 32, i32 500)
%21 = call i32 @free(i8* %4)
%22 = load i8*, i8** %1
%23 = call i32 @free(i8* %22)
%24 = call i32 @free(i8* %19)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
}