#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*/ assert(int);
int /*<<< orphan*/ dump_freechunk_content(void *, unsigned int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int const);
int /*<<< orphan*/ free(void *);
void *malloc(unsigned int const);
int /*<<< orphan*/ memcpy(void *, void const *, unsigned int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, unsigned int const);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void show_free_metadata(void) {
  const unsigned int allocsize = 4096;
  void *ptr[5];
  uintptr_t addr[5];
  unsigned int i, total_size;
  void *freechunk1 = NULL, *freechunk3 = NULL;
  for (i = 0; i < 5; i++) {
    ptr[i] = malloc(allocsize);
    if (!ptr[i]) {
      fprintf(stderr, "Error while allocating %u bytes.\n", allocsize);
      while (i > 0) {
        free(ptr[--i]);
      }
      exit(1);
    }
    memset(ptr[i], 0, allocsize);
    addr[i] = (uintptr_t)ptr[i];
  }
  printf("Allocated %u 0x%x-byte block in:\n", 5, allocsize);
  for (i = 0; i < 5; i++) {
    printf("  %p\n", ptr[i]);
  }
  for (i = 0; i < 5 - 1; i++) {
    if (addr[i] > addr[i + 1]) {
      printf("... blocks are not ordered :(\n");
      goto cleanup;
    }
    assert(addr[i] + allocsize < addr[i + 1]);
    if (addr[i] + allocsize + 1024 <= addr[i + 1]) {
      printf("... interval too large to be contiguous blocks :(\n");
      goto cleanup;
    }
    if (addr[i + 1] - addr[i] != addr[1] - addr[0]) {
      printf("... interval between blocks is variable :(\n");
      goto cleanup;
    }
  }
  total_size = (unsigned int)(addr[1] - addr[0]);
  freechunk1 = malloc(total_size);
  freechunk3 = malloc(total_size);
  if (!freechunk1 || !freechunk3) {
    fprintf(stderr, "Error while allocating 2x%u bytes.\n", total_size);
    for (i = 0; i < 5; i++) {
      free(ptr[i]);
    }
    exit(1);
  }
  free(ptr[1]);
  free(ptr[3]);
  ptr[1] = ptr[3] = NULL;
  memcpy(freechunk1, (const void *)(addr[0] + allocsize), total_size);
  memcpy(freechunk3, (const void *)(addr[2] + allocsize), total_size);
  printf("Content of the second freed block at %p:\n",
         (void *)(addr[0] + allocsize));
  dump_freechunk_content(freechunk1, total_size);
  printf("Content of the forth freed block at %p:\n",
         (void *)(addr[2] + allocsize));
  dump_freechunk_content(freechunk3, total_size);
cleanup:
  free(freechunk1);
  free(freechunk3);
  for (i = 0; i < 5; i++) {
    free(ptr[i]);
  }
}


x86 assembly (clang, -O0):
<show_free_metadata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x1000,-0x4(%rbp)
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jae    1261 <show_free_metadata+0xd1>
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    -0x64(%rbp),%eax
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
cmpq   $0x0,-0x30(%rbp,%rax,8)
jne    122f <show_free_metadata+0x9f>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    $0x1000,%edx
call   1080 <fprintf@plt>
cmpl   $0x0,-0x64(%rbp)
jbe    1225 <show_free_metadata+0x95>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
mov    %eax,%eax
mov    -0x30(%rbp,%rax,8),%rdi
call   1030 <free@plt>
jmp    1201 <show_free_metadata+0x71>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x64(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    -0x64(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rcx
mov    -0x64(%rbp),%eax
mov    %rcx,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11b9 <show_free_metadata+0x29>
lea    0xdba(%rip),%rdi
mov    $0x5,%esi
mov    $0x1000,%edx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jae    12ae <show_free_metadata+0x11e>
mov    -0x64(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1280 <show_free_metadata+0xf0>
movl   $0x0,-0x64(%rbp)
cmpl   $0x4,-0x64(%rbp)
jae    139b <show_free_metadata+0x20b>
mov    -0x64(%rbp),%eax
mov    -0x60(%rbp,%rax,8),%rax
mov    -0x64(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
cmp    -0x60(%rbp,%rcx,8),%rax
jbe    12ed <show_free_metadata+0x15d>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14bc <show_free_metadata+0x32c>
mov    -0x64(%rbp),%eax
mov    -0x60(%rbp,%rax,8),%rax
add    $0x1000,%rax
mov    -0x64(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
cmp    -0x60(%rbp,%rcx,8),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x64(%rbp),%eax
mov    -0x60(%rbp,%rax,8),%rax
add    $0x1000,%rax
add    $0x400,%rax
mov    -0x64(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
cmp    -0x60(%rbp,%rcx,8),%rax
ja     134f <show_free_metadata+0x1bf>
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14bc <show_free_metadata+0x32c>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    -0x60(%rbp,%rax,8),%rax
mov    -0x64(%rbp),%ecx
sub    -0x60(%rbp,%rcx,8),%rax
mov    -0x58(%rbp),%rcx
sub    -0x60(%rbp),%rcx
cmp    %rcx,%rax
je     1388 <show_free_metadata+0x1f8>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14bc <show_free_metadata+0x32c>
jmp    138d <show_free_metadata+0x1fd>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12b5 <show_free_metadata+0x125>
mov    -0x58(%rbp),%rax
sub    -0x60(%rbp),%rax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     13d4 <show_free_metadata+0x244>
cmpq   $0x0,-0x78(%rbp)
jne    1422 <show_free_metadata+0x292>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%edx
lea    0xce1(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jae    1418 <show_free_metadata+0x288>
mov    -0x64(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    13f3 <show_free_metadata+0x263>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x60(%rbp),%rsi
add    $0x1000,%rsi
mov    -0x68(%rbp),%edx
call   1090 <memcpy@plt>
mov    -0x78(%rbp),%rdi
mov    -0x50(%rbp),%rsi
add    $0x1000,%rsi
mov    -0x68(%rbp),%edx
call   1090 <memcpy@plt>
mov    -0x60(%rbp),%rsi
add    $0x1000,%rsi
lea    0xc68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%esi
call   1040 <dump_freechunk_content@plt>
mov    -0x50(%rbp),%rsi
add    $0x1000,%rsi
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%rdi
mov    -0x68(%rbp),%esi
call   1040 <dump_freechunk_content@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jae    14fa <show_free_metadata+0x36a>
mov    -0x64(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    14d5 <show_free_metadata+0x345>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_free_metadata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
je     14eb <show_free_metadata+0x34b>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,0x28(%rsp)
test   %rax,%rax
je     150f <show_free_metadata+0x36f>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,0x30(%rsp)
test   %rax,%rax
je     1516 <show_free_metadata+0x376>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,0x38(%rsp)
test   %rax,%rax
je     151d <show_free_metadata+0x37d>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,0x40(%rsp)
test   %rax,%rax
je     1524 <show_free_metadata+0x384>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
lea    0xd9b(%rip),%rdi
mov    $0x5,%esi
mov    $0x1000,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xda5(%rip),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rax
sub    %r13,%rax
jae    12f4 <show_free_metadata+0x154>
lea    0xe2f(%rip),%rdi
jmp    1496 <show_free_metadata+0x2f6>
mov    %rax,(%rsp)
lea    0x1000(%r13),%rax
xor    %edi,%edi
mov    %rax,0x18(%rsp)
cmp    %rbx,%rax
setb   %dil
call   1080 <assert@plt>
mov    %r13,%rax
add    $0x1400,%rax
cmp    %rbx,%rax
jbe    148f <show_free_metadata+0x2ef>
mov    %r14,%rbp
sub    %rbx,%rbp
jb     12e8 <show_free_metadata+0x148>
lea    0x1000(%rbx),%rax
xor    %edi,%edi
cmp    %r14,%rax
setb   %dil
call   1080 <assert@plt>
mov    %rbx,%rax
add    $0x1400,%rax
cmp    %r14,%rax
jbe    148f <show_free_metadata+0x2ef>
cmp    (%rsp),%rbp
jne    14e2 <show_free_metadata+0x342>
mov    %r12,%rbp
sub    %r14,%rbp
jb     12e8 <show_free_metadata+0x148>
lea    0x1000(%r14),%rax
xor    %edi,%edi
mov    %rax,0x10(%rsp)
cmp    %r12,%rax
setb   %dil
call   1080 <assert@plt>
mov    %r14,%rax
add    $0x1400,%rax
cmp    %r12,%rax
jbe    148f <show_free_metadata+0x2ef>
cmp    (%rsp),%rbp
jne    14e2 <show_free_metadata+0x342>
mov    %r15,%rbp
sub    %r12,%rbp
jb     12e8 <show_free_metadata+0x148>
lea    0x1000(%r12),%rax
xor    %edi,%edi
cmp    %r15,%rax
setb   %dil
call   1080 <assert@plt>
mov    %r12,%rax
add    $0x1400,%rax
cmp    %r15,%rax
jbe    148f <show_free_metadata+0x2ef>
mov    (%rsp),%rax
cmp    %rax,%rbp
jne    14e2 <show_free_metadata+0x342>
mov    %rax,%rbp
mov    %ebp,%edi
call   10b0 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
call   10b0 <malloc@plt>
cmpq   $0x0,0x8(%rsp)
je     156a <show_free_metadata+0x3ca>
mov    %rax,%rbp
test   %rax,%rax
je     156a <show_free_metadata+0x3ca>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
movq   $0x0,0x38(%rsp)
mov    0x8(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    (%rsp),%rbx
mov    %ebx,%edx
call   10a0 <memcpy@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %ebx,%edx
call   10a0 <memcpy@plt>
lea    0xc20(%rip),%rdi
xor    %r12d,%r12d
mov    0x18(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1040 <dump_freechunk_content@plt>
lea    0xc28(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <dump_freechunk_content@plt>
mov    0x8(%rsp),%rdi
xor    %ebx,%ebx
jmp    149f <show_free_metadata+0x2ff>
lea    0xc56(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
xor    %ebp,%ebp
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xbd8(%rip),%rdi
jmp    1496 <show_free_metadata+0x2f6>
mov    0x2aee(%rip),%rax
mov    (%rax),%edi
lea    0xb05(%rip),%rsi
mov    $0x1000,%edx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x1,%ebx
jmp    1529 <show_free_metadata+0x389>
mov    $0x2,%ebx
jmp    1529 <show_free_metadata+0x389>
mov    $0x3,%ebx
jmp    1529 <show_free_metadata+0x389>
mov    $0x4,%ebx
mov    0x2ab0(%rip),%rax
mov    (%rax),%edi
lea    0xac7(%rip),%rsi
mov    $0x1000,%edx
call   1090 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x18(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0xffffffffffffffff,%rbx
jne    1550 <show_free_metadata+0x3b0>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2a6f(%rip),%rax
mov    (%rax),%edi
lea    0xad0(%rip),%rsi
mov    (%rsp),%rdx
call   1090 <fprintf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Error while allocating %u bytes.\0A\00"
@.str.1 = [34 x i8] c"Allocated %u 0x%x-byte block in:\0A\00"
@.str.2 = [6 x i8] c" %p\0A\00"
@.str.3 = [31 x i8] c"... blocks are not ordered :(\0A\00"
@.str.4 = [51 x i8] c"... interval too large to be contiguous blocks :(\0A\00"
@.str.5 = [44 x i8] c"... interval between blocks is variable :(\0A\00"
@.str.6 = [36 x i8] c"Error while allocating 2x%u bytes.\0A\00"
@.str.7 = [42 x i8] c"Content of the second freed block at %p:\0A\00"
@.str.8 = [41 x i8] c"Content of the forth freed block at %p:\0A\00"
define void @show_free_metadata() {
%1 = alloca i32
%2 = alloca [5 x i8*]
%3 = alloca [5 x i64]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 4096, i32* %1
store i8* null, i8** %6
store i8* null, i8** %7
store i32 0, i32* %4
br label %8
8: ; preds = %50, %0
%9 = load i32, i32* %4
%10 = icmp ult i32 %9, 5
br i1 %10, label %11, label %53
11: ; preds = %8
%12 = call i8* @malloc(i32 4096)
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %14
store i8* %12, i8** %15
%16 = load i32, i32* %4
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %36, label %21
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 4096)
br label %24
24: ; preds = %27, %21
%25 = load i32, i32* %4
%26 = icmp ugt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %4
%29 = add i32 %28, -1
store i32 %29, i32* %4
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @free(i8* %32)
br label %24
34: ; preds = %24
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %11
%37 = load i32, i32* %4
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @memset(i8* %40, i32 0, i32 4096)
%42 = load i32, i32* %4
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = ptrtoint i8* %45 to i64
%47 = load i32, i32* %4
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %48
store i64 %46, i64* %49
br label %50
50: ; preds = %36
%51 = load i32, i32* %4
%52 = add i32 %51, 1
store i32 %52, i32* %4
br label %8
53: ; preds = %8
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 4096)
store i32 0, i32* %4
br label %55
55: ; preds = %64, %53
%56 = load i32, i32* %4
%57 = icmp ult i32 %56, 5
br i1 %57, label %58, label %67
58: ; preds = %55
%59 = load i32, i32* %4
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %58
%65 = load i32, i32* %4
%66 = add i32 %65, 1
store i32 %66, i32* %4
br label %55
67: ; preds = %55
store i32 0, i32* %4
br label %68
68: ; preds = %132, %67
%69 = load i32, i32* %4
%70 = icmp ult i32 %69, 4
br i1 %70, label %71, label %135
71: ; preds = %68
%72 = load i32, i32* %4
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %73
%75 = load i64, i64* %74
%76 = load i32, i32* %4
%77 = add i32 %76, 1
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %78
%80 = load i64, i64* %79
%81 = icmp ugt i64 %75, %80
br i1 %81, label %82, label %84
82: ; preds = %71
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %208
84: ; preds = %71
%85 = load i32, i32* %4
%86 = zext i32 %85 to i64
%87 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %86
%88 = load i64, i64* %87
%89 = add i64 %88, 4096
%90 = load i32, i32* %4
%91 = add i32 %90, 1
%92 = zext i32 %91 to i64
%93 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %92
%94 = load i64, i64* %93
%95 = icmp ult i64 %89, %94
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
%98 = load i32, i32* %4
%99 = zext i32 %98 to i64
%100 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %99
%101 = load i64, i64* %100
%102 = add i64 %101, 4096
%103 = add i64 %102, 1024
%104 = load i32, i32* %4
%105 = add i32 %104, 1
%106 = zext i32 %105 to i64
%107 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %106
%108 = load i64, i64* %107
%109 = icmp ule i64 %103, %108
br i1 %109, label %110, label %112
110: ; preds = %84
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
br label %208
112: ; preds = %84
%113 = load i32, i32* %4
%114 = add i32 %113, 1
%115 = zext i32 %114 to i64
%116 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %115
%117 = load i64, i64* %116
%118 = load i32, i32* %4
%119 = zext i32 %118 to i64
%120 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 %119
%121 = load i64, i64* %120
%122 = sub i64 %117, %121
%123 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 1
%124 = load i64, i64* %123
%125 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
%126 = load i64, i64* %125
%127 = sub i64 %124, %126
%128 = icmp ne i64 %122, %127
br i1 %128, label %129, label %131
129: ; preds = %112
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %208
131: ; preds = %112
br label %132
132: ; preds = %131
%133 = load i32, i32* %4
%134 = add i32 %133, 1
store i32 %134, i32* %4
br label %68
135: ; preds = %68
%136 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 1
%137 = load i64, i64* %136
%138 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
%139 = load i64, i64* %138
%140 = sub i64 %137, %139
%141 = trunc i64 %140 to i32
store i32 %141, i32* %5
%142 = load i32, i32* %5
%143 = call i8* @malloc(i32 %142)
store i8* %143, i8** %6
%144 = load i32, i32* %5
%145 = call i8* @malloc(i32 %144)
store i8* %145, i8** %7
%146 = load i8*, i8** %6
%147 = icmp ne i8* %146, null
br i1 %147, label %148, label %151
148: ; preds = %135
%149 = load i8*, i8** %7
%150 = icmp ne i8* %149, null
br i1 %150, label %169, label %151
151: ; preds = %148, %135
%152 = load i32, i32* @stderr
%153 = load i32, i32* %5
%154 = call i32 @fprintf(i32 %152, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %153)
store i32 0, i32* %4
br label %155
155: ; preds = %164, %151
%156 = load i32, i32* %4
%157 = icmp ult i32 %156, 5
br i1 %157, label %158, label %167
158: ; preds = %155
%159 = load i32, i32* %4
%160 = zext i32 %159 to i64
%161 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %160
%162 = load i8*, i8** %161
%163 = call i32 @free(i8* %162)
br label %164
164: ; preds = %158
%165 = load i32, i32* %4
%166 = add i32 %165, 1
store i32 %166, i32* %4
br label %155
167: ; preds = %155
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %148
%170 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 1
%171 = load i8*, i8** %170
%172 = call i32 @free(i8* %171)
%173 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 3
%174 = load i8*, i8** %173
%175 = call i32 @free(i8* %174)
%176 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 3
store i8* null, i8** %176
%177 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %177
%178 = load i8*, i8** %6
%179 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
%180 = load i64, i64* %179
%181 = add i64 %180, 4096
%182 = inttoptr i64 %181 to i8*
%183 = load i32, i32* %5
%184 = call i32 @memcpy(i8* %178, i8* %182, i32 %183)
%185 = load i8*, i8** %7
%186 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 2
%187 = load i64, i64* %186
%188 = add i64 %187, 4096
%189 = inttoptr i64 %188 to i8*
%190 = load i32, i32* %5
%191 = call i32 @memcpy(i8* %185, i8* %189, i32 %190)
%192 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
%193 = load i64, i64* %192
%194 = add i64 %193, 4096
%195 = inttoptr i64 %194 to i8*
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %195)
%197 = load i8*, i8** %6
%198 = load i32, i32* %5
%199 = call i32 @dump_freechunk_content(i8* %197, i32 %198)
%200 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 2
%201 = load i64, i64* %200
%202 = add i64 %201, 4096
%203 = inttoptr i64 %202 to i8*
%204 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8* %203)
%205 = load i8*, i8** %7
%206 = load i32, i32* %5
%207 = call i32 @dump_freechunk_content(i8* %205, i32 %206)
br label %208
208: ; preds = %169, %129, %110, %82
%209 = load i8*, i8** %6
%210 = call i32 @free(i8* %209)
%211 = load i8*, i8** %7
%212 = call i32 @free(i8* %211)
store i32 0, i32* %4
br label %213
213: ; preds = %222, %208
%214 = load i32, i32* %4
%215 = icmp ult i32 %214, 5
br i1 %215, label %216, label %225
216: ; preds = %213
%217 = load i32, i32* %4
%218 = zext i32 %217 to i64
%219 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %218
%220 = load i8*, i8** %219
%221 = call i32 @free(i8* %220)
br label %222
222: ; preds = %216
%223 = load i32, i32* %4
%224 = add i32 %223, 1
store i32 %224, i32* %4
br label %213
225: ; preds = %213
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Error while allocating %u bytes.\0A\00"
@.str.1 = [34 x i8] c"Allocated %u 0x%x-byte block in:\0A\00"
@.str.2 = [6 x i8] c" %p\0A\00"
@.str.6 = [36 x i8] c"Error while allocating 2x%u bytes.\0A\00"
@.str.7 = [42 x i8] c"Content of the second freed block at %p:\0A\00"
@.str.8 = [41 x i8] c"Content of the forth freed block at %p:\0A\00"
@str = [43 x i8] c"... interval between blocks is variable :(\00"
@str.9 = [50 x i8] c"... interval too large to be contiguous blocks :(\00"
@str.10 = [30 x i8] c"... blocks are not ordered :(\00"
define void @show_free_metadata() {
%1 = alloca [5 x i8*]
%2 = bitcast [5 x i8*]* %1 to i8*
%3 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%4 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 0
store i8* %3, i8** %4
%5 = icmp eq i8* %3, null
br i1 %5, label %6, label %22
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 4096)
br label %20
9: ; preds = %40, %34, %28, %22
%10 = phi i64 [ 1, %22 ], [ 2, %28 ], [ 3, %34 ], [ 4, %40 ]
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 4096)
br label %13
13: ; preds = %9, %13
%14 = phi i64 [ %10, %9 ], [ %15, %13 ]
%15 = add nsw i64 %14, -1
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i32 @free(i8* %17)
%19 = icmp eq i64 %15, 0
br i1 %19, label %20, label %13
20: ; preds = %13, %6
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = tail call i32 @memset(i8* %3, i32 0, i32 4096)
%24 = ptrtoint i8* %3 to i64
%25 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%26 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 1
store i8* %25, i8** %26
%27 = icmp eq i8* %25, null
br i1 %27, label %9, label %28
28: ; preds = %22
%29 = tail call i32 @memset(i8* %25, i32 0, i32 4096)
%30 = ptrtoint i8* %25 to i64
%31 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%32 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 2
store i8* %31, i8** %32
%33 = icmp eq i8* %31, null
br i1 %33, label %9, label %34
34: ; preds = %28
%35 = tail call i32 @memset(i8* %31, i32 0, i32 4096)
%36 = ptrtoint i8* %31 to i64
%37 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%38 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 3
store i8* %37, i8** %38
%39 = icmp eq i8* %37, null
br i1 %39, label %9, label %40
40: ; preds = %34
%41 = tail call i32 @memset(i8* %37, i32 0, i32 4096)
%42 = ptrtoint i8* %37 to i64
%43 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%44 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 4
store i8* %43, i8** %44
%45 = icmp eq i8* %43, null
br i1 %45, label %9, label %46
46: ; preds = %40
%47 = tail call i32 @memset(i8* %43, i32 0, i32 4096)
%48 = ptrtoint i8* %43 to i64
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 4096)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%55 = sub i64 %30, %24
%56 = icmp ult i8* %25, %3
br i1 %56, label %57, label %59
57: ; preds = %92, %80, %68, %46
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
br label %133
59: ; preds = %46
%60 = add i64 %24, 4096
%61 = icmp ult i64 %60, %30
%62 = zext i1 %61 to i32
%63 = tail call i32 @assert(i32 %62)
%64 = add i64 %24, 5120
%65 = icmp ugt i64 %64, %30
br i1 %65, label %68, label %66
66: ; preds = %94, %82, %70, %59
%67 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.9, i64 0, i64 0))
br label %133
68: ; preds = %59
%69 = icmp ult i8* %31, %25
br i1 %69, label %57, label %70
70: ; preds = %68
%71 = add i64 %30, 4096
%72 = icmp ult i64 %71, %36
%73 = zext i1 %72 to i32
%74 = tail call i32 @assert(i32 %73)
%75 = add i64 %30, 5120
%76 = icmp ugt i64 %75, %36
br i1 %76, label %77, label %66
77: ; preds = %70
%78 = sub i64 %36, %30
%79 = icmp eq i64 %78, %55
br i1 %79, label %80, label %104
80: ; preds = %77
%81 = icmp ult i8* %37, %31
br i1 %81, label %57, label %82
82: ; preds = %80
%83 = add i64 %36, 4096
%84 = icmp ult i64 %83, %42
%85 = zext i1 %84 to i32
%86 = tail call i32 @assert(i32 %85)
%87 = add i64 %36, 5120
%88 = icmp ugt i64 %87, %42
br i1 %88, label %89, label %66
89: ; preds = %82
%90 = sub i64 %42, %36
%91 = icmp eq i64 %90, %55
br i1 %91, label %92, label %104
92: ; preds = %89
%93 = icmp ult i8* %43, %37
br i1 %93, label %57, label %94
94: ; preds = %92
%95 = add i64 %42, 4096
%96 = icmp ult i64 %95, %48
%97 = zext i1 %96 to i32
%98 = tail call i32 @assert(i32 %97)
%99 = add i64 %42, 5120
%100 = icmp ugt i64 %99, %48
br i1 %100, label %101, label %66
101: ; preds = %94
%102 = sub i64 %48, %42
%103 = icmp eq i64 %102, %55
br i1 %103, label %106, label %104
104: ; preds = %101, %89, %77
%105 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %133
106: ; preds = %101
%107 = trunc i64 %55 to i32
%108 = tail call i8* @malloc(i32 %107)
%109 = tail call i8* @malloc(i32 %107)
%110 = icmp ne i8* %108, null
%111 = icmp ne i8* %109, null
%112 = and i1 %110, %111
br i1 %112, label %122, label %113
113: ; preds = %106
%114 = load i32, i32* @stderr
%115 = tail call i32 @fprintf(i32 %114, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %107)
%116 = tail call i32 @free(i8* %3)
%117 = tail call i32 @free(i8* %25)
%118 = tail call i32 @free(i8* %31)
%119 = tail call i32 @free(i8* %37)
%120 = tail call i32 @free(i8* %43)
%121 = tail call i32 @exit(i32 1)
unreachable
122: ; preds = %106
%123 = tail call i32 @free(i8* %25)
%124 = tail call i32 @free(i8* %37)
store i8* null, i8** %38
%125 = inttoptr i64 %60 to i8*
%126 = tail call i32 @memcpy(i8* %108, i8* %125, i32 %107)
%127 = inttoptr i64 %83 to i8*
%128 = tail call i32 @memcpy(i8* %109, i8* %127, i32 %107)
%129 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %125)
%130 = tail call i32 @dump_freechunk_content(i8* %108, i32 %107)
%131 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8* %127)
%132 = tail call i32 @dump_freechunk_content(i8* %109, i32 %107)
br label %133
133: ; preds = %122, %104, %66, %57
%134 = phi i8* [ %37, %57 ], [ %37, %66 ], [ %37, %104 ], [ null, %122 ]
%135 = phi i8* [ %25, %57 ], [ %25, %66 ], [ %25, %104 ], [ null, %122 ]
%136 = phi i8* [ null, %57 ], [ null, %66 ], [ null, %104 ], [ %108, %122 ]
%137 = phi i8* [ null, %57 ], [ null, %66 ], [ null, %104 ], [ %109, %122 ]
%138 = tail call i32 @free(i8* %136)
%139 = tail call i32 @free(i8* %137)
%140 = tail call i32 @free(i8* %3)
%141 = tail call i32 @free(i8* %135)
%142 = tail call i32 @free(i8* %31)
%143 = tail call i32 @free(i8* %134)
%144 = tail call i32 @free(i8* %43)
ret void
}