#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ __vmir_heap_print();
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
void *malloc(int);
void *realloc(void *, int);
int main(void) {
  uint32_t *hej = malloc(32);
  void *vec[10];
  for (int i = 0; i < 10; i++)
    vec[i] = malloc(i * 10);
  *hej = 30;
  hej = realloc(hej, 10000);
  if (*hej != 30)
    abort();
  free(hej);
  for (int i = 9; i >= 0; i--)
    free(vec[i]);
  for (int i = 0; i < 10; i++)
    vec[i] = malloc(i * 10);
  vec[3] = realloc(vec[3], 1235);
  vec[3] = realloc(vec[3], 123);
  vec[3] = realloc(vec[3], 12300);
  free(vec[5]);
  vec[5] = NULL;
  vec[7] = realloc(vec[7], 0);
  __vmir_heap_print();
  for (int i = 9; i >= 0; i--)
    free(vec[i]);
  __vmir_heap_print();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    11b1 <main+0x51>
imul   $0xa,-0x64(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1184 <main+0x24>
mov    -0x10(%rbp),%rax
movl   $0x1e,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x2710,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1e,(%rax)
je     11e1 <main+0x81>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x9,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jl     1217 <main+0xb7>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x68(%rbp)
jmp    11f1 <main+0x91>
movl   $0x0,-0x6c(%rbp)
cmpl   $0xa,-0x6c(%rbp)
jge    124b <main+0xeb>
imul   $0xa,-0x6c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x6c(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    121e <main+0xbe>
mov    -0x48(%rbp),%rdi
mov    $0x4d3,%esi
call   1070 <realloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x7b,%esi
call   1070 <realloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x300c,%esi
call   1070 <realloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1070 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <__vmir_heap_print@plt>
movl   $0x9,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
jl     12d5 <main+0x175>
movslq -0x70(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x70(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x70(%rbp)
jmp    12af <main+0x14f>
mov    $0x0,%al
call   1050 <__vmir_heap_print@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x1e,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
mov    $0x32,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x3c,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x46,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    $0x5a,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0x1e,(%r14)
mov    %r14,%rdi
mov    $0x2710,%esi
call   1070 <realloc@plt>
cmpl   $0x1e,(%rax)
jne    13b5 <main+0x255>
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x1e,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x32,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x3c,%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
mov    $0x46,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x5a,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    $0x4d3,%esi
call   1070 <realloc@plt>
mov    %rax,%rdi
mov    $0x7b,%esi
call   1070 <realloc@plt>
mov    %rax,%rdi
mov    $0x300c,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1070 <realloc@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <__vmir_heap_print@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1050 <__vmir_heap_print@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [10 x i8*]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i8* @malloc(i32 32)
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %2
store i32 0, i32* %4
br label %10
10: ; preds = %20, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* %4
%15 = mul nsw i32 %14, 10
%16 = call i8* @malloc(i32 %15)
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %18
store i8* %16, i8** %19
br label %20
20: ; preds = %13
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %10
23: ; preds = %10
%24 = load i32*, i32** %2
store i32 30, i32* %24
%25 = load i32*, i32** %2
%26 = bitcast i32* %25 to i8*
%27 = call i8* @realloc(i8* %26, i32 10000)
%28 = bitcast i8* %27 to i32*
store i32* %28, i32** %2
%29 = load i32*, i32** %2
%30 = load i32, i32* %29
%31 = icmp ne i32 %30, 30
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %23
%35 = load i32*, i32** %2
%36 = bitcast i32* %35 to i8*
%37 = call i32 @free(i8* %36)
store i32 9, i32* %5
br label %38
38: ; preds = %47, %34
%39 = load i32, i32* %5
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %41
%48 = load i32, i32* %5
%49 = add nsw i32 %48, -1
store i32 %49, i32* %5
br label %38
50: ; preds = %38
store i32 0, i32* %6
br label %51
51: ; preds = %61, %50
%52 = load i32, i32* %6
%53 = icmp slt i32 %52, 10
br i1 %53, label %54, label %64
54: ; preds = %51
%55 = load i32, i32* %6
%56 = mul nsw i32 %55, 10
%57 = call i8* @malloc(i32 %56)
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %59
store i8* %57, i8** %60
br label %61
61: ; preds = %54
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %51
64: ; preds = %51
%65 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 3
%66 = load i8*, i8** %65
%67 = call i8* @realloc(i8* %66, i32 1235)
%68 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 3
store i8* %67, i8** %68
%69 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 3
%70 = load i8*, i8** %69
%71 = call i8* @realloc(i8* %70, i32 123)
%72 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 3
store i8* %71, i8** %72
%73 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 3
%74 = load i8*, i8** %73
%75 = call i8* @realloc(i8* %74, i32 12300)
%76 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 3
store i8* %75, i8** %76
%77 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 5
%78 = load i8*, i8** %77
%79 = call i32 @free(i8* %78)
%80 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 5
store i8* null, i8** %80
%81 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 7
%82 = load i8*, i8** %81
%83 = call i8* @realloc(i8* %82, i32 0)
%84 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 7
store i8* %83, i8** %84
%85 = call i32 (...) @__vmir_heap_print()
store i32 9, i32* %7
br label %86
86: ; preds = %95, %64
%87 = load i32, i32* %7
%88 = icmp sge i32 %87, 0
br i1 %88, label %89, label %98
89: ; preds = %86
%90 = load i32, i32* %7
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %91
%93 = load i8*, i8** %92
%94 = call i32 @free(i8* %93)
br label %95
95: ; preds = %89
%96 = load i32, i32* %7
%97 = add nsw i32 %96, -1
store i32 %97, i32* %7
br label %86
98: ; preds = %86
%99 = call i32 (...) @__vmir_heap_print()
%100 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%2 = tail call i8* @malloc(i32 0)
%3 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%4 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%5 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%6 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%7 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%8 = tail call dereferenceable_or_null(60) i8* @malloc(i32 60)
%9 = tail call dereferenceable_or_null(70) i8* @malloc(i32 70)
%10 = tail call dereferenceable_or_null(80) i8* @malloc(i32 80)
%11 = tail call dereferenceable_or_null(90) i8* @malloc(i32 90)
%12 = bitcast i8* %1 to i32*
store i32 30, i32* %12
%13 = tail call i8* @realloc(i8* %1, i32 10000)
%14 = bitcast i8* %13 to i32*
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 30
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = tail call i32 (...) @abort()
unreachable
19: ; preds = %0
%20 = tail call i32 @free(i8* %13)
%21 = tail call i32 @free(i8* %11)
%22 = tail call i32 @free(i8* %10)
%23 = tail call i32 @free(i8* %9)
%24 = tail call i32 @free(i8* %8)
%25 = tail call i32 @free(i8* %7)
%26 = tail call i32 @free(i8* %6)
%27 = tail call i32 @free(i8* %5)
%28 = tail call i32 @free(i8* %4)
%29 = tail call i32 @free(i8* %3)
%30 = tail call i32 @free(i8* %2)
%31 = tail call i8* @malloc(i32 0)
%32 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%33 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%34 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%35 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%36 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%37 = tail call dereferenceable_or_null(60) i8* @malloc(i32 60)
%38 = tail call dereferenceable_or_null(70) i8* @malloc(i32 70)
%39 = tail call dereferenceable_or_null(80) i8* @malloc(i32 80)
%40 = tail call dereferenceable_or_null(90) i8* @malloc(i32 90)
%41 = tail call i8* @realloc(i8* %34, i32 1235)
%42 = tail call i8* @realloc(i8* %41, i32 123)
%43 = tail call i8* @realloc(i8* %42, i32 12300)
%44 = tail call i32 @free(i8* %36)
%45 = tail call i8* @realloc(i8* %38, i32 0)
%46 = tail call i32 (...) @__vmir_heap_print()
%47 = tail call i32 @free(i8* %40)
%48 = tail call i32 @free(i8* %39)
%49 = tail call i32 @free(i8* %45)
%50 = tail call i32 @free(i8* %37)
%51 = tail call i32 @free(i8* null)
%52 = tail call i32 @free(i8* %35)
%53 = tail call i32 @free(i8* %43)
%54 = tail call i32 @free(i8* %33)
%55 = tail call i32 @free(i8* %32)
%56 = tail call i32 @free(i8* %31)
%57 = tail call i32 (...) @__vmir_heap_print()
%58 = tail call i32 @exit(i32 0)
unreachable
}