#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*/ free(char *);
void *malloc(int);
int /*<<< orphan*/ printf(char *);
int main() {
  void *p[20];
  int i;
  char c;
  for (i = 0; i < 20; i++) {
    p[i] = malloc(20 - i);
    free(p[i]);
  }
  for (i = 0; i < 20; i++) {
    c = *(((char *)p[i]) + 3);
  }
  {
    char *x = malloc(64);
    free(x);
    *(x + 32) = 0xe;
  }
  printf("all done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xb4(%rbp)
cmpl   $0x14,-0xb4(%rbp)
jge    11a3 <main+0x73>
mov    $0x14,%edi
sub    -0xb4(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0xb4(%rbp),%rax
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
movslq -0xb4(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    114c <main+0x1c>
movl   $0x0,-0xb4(%rbp)
cmpl   $0x14,-0xb4(%rbp)
jge    11e6 <main+0xb6>
movslq -0xb4(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rax
ff
mov    0x3(%rax),%al
mov    %al,-0xb5(%rbp)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11ad <main+0x7d>
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc0(%rbp),%rax
movb   $0xe,0x20(%rax)
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x13,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x12,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x11,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0xf,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0xe,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0xd,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0xb,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x9,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x7,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x5,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
lea    0xd4e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"all done\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8*]
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %21, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 20
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sub nsw i32 20, %10
%12 = call i8* @malloc(i32 %11)
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 %14
store i8* %12, i8** %15
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @free(i8* %19)
br label %21
21: ; preds = %9
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %6
24: ; preds = %6
store i32 0, i32* %3
br label %25
25: ; preds = %35, %24
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 20
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 3
%34 = load i8, i8* %33
store i8 %34, i8* %4
br label %35
35: ; preds = %28
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %25
38: ; preds = %25
%39 = call i8* @malloc(i32 64)
store i8* %39, i8** %5
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 32
store i8 14, i8* %43
%44 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [9 x i8] c"all done\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%2 = tail call i32 @free(i8* %1)
%3 = tail call dereferenceable_or_null(19) i8* @malloc(i32 19)
%4 = tail call i32 @free(i8* %3)
%5 = tail call dereferenceable_or_null(18) i8* @malloc(i32 18)
%6 = tail call i32 @free(i8* %5)
%7 = tail call dereferenceable_or_null(17) i8* @malloc(i32 17)
%8 = tail call i32 @free(i8* %7)
%9 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%10 = tail call i32 @free(i8* %9)
%11 = tail call dereferenceable_or_null(15) i8* @malloc(i32 15)
%12 = tail call i32 @free(i8* %11)
%13 = tail call dereferenceable_or_null(14) i8* @malloc(i32 14)
%14 = tail call i32 @free(i8* %13)
%15 = tail call dereferenceable_or_null(13) i8* @malloc(i32 13)
%16 = tail call i32 @free(i8* %15)
%17 = tail call dereferenceable_or_null(12) i8* @malloc(i32 12)
%18 = tail call i32 @free(i8* %17)
%19 = tail call dereferenceable_or_null(11) i8* @malloc(i32 11)
%20 = tail call i32 @free(i8* %19)
%21 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%22 = tail call i32 @free(i8* %21)
%23 = tail call dereferenceable_or_null(9) i8* @malloc(i32 9)
%24 = tail call i32 @free(i8* %23)
%25 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%26 = tail call i32 @free(i8* %25)
%27 = tail call dereferenceable_or_null(7) i8* @malloc(i32 7)
%28 = tail call i32 @free(i8* %27)
%29 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
%30 = tail call i32 @free(i8* %29)
%31 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%32 = tail call i32 @free(i8* %31)
%33 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%34 = tail call i32 @free(i8* %33)
%35 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
%36 = tail call i32 @free(i8* %35)
%37 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
%38 = tail call i32 @free(i8* %37)
%39 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%40 = tail call i32 @free(i8* %39)
%41 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%42 = tail call i32 @free(i8* %41)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 0
}