#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(void *);
void *malloc(int);
int main(int argc, char *argv[]) {
  int i;
  const int limit = 4;
  void *ptr[limit];
  for (i = 0; i < limit; ++i) {
    ptr[i] = malloc(10000 * i);
  }
  for (i = 0; i < limit; ++i) {
    free(ptr[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x18(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    117b <main+0x5b>
imul   $0x2710,-0x14(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <main+0x2b>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11a8 <main+0x88>
movslq -0x14(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <main+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x2710,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0x4e20,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    $0x7530,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %7
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %8
%10 = alloca i8*, i64 4
store i32 0, i32* %6
br label %11
11: ; preds = %21, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i32, i32* %6
%16 = mul nsw i32 10000, %15
%17 = call i8* @malloc(i32 %16)
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %10, i64 %19
store i8* %17, i8** %20
br label %21
21: ; preds = %14
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %11
24: ; preds = %11
store i32 0, i32* %6
br label %25
25: ; preds = %34, %24
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %10, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %25
37: ; preds = %25
store i32 0, i32* %3
%38 = load i8*, i8** %8
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @malloc(i32 0)
%4 = tail call dereferenceable_or_null(10000) i8* @malloc(i32 10000)
%5 = tail call dereferenceable_or_null(20000) i8* @malloc(i32 20000)
%6 = tail call dereferenceable_or_null(30000) i8* @malloc(i32 30000)
%7 = tail call i32 @free(i8* %3)
%8 = tail call i32 @free(i8* %4)
%9 = tail call i32 @free(i8* %5)
%10 = tail call i32 @free(i8* %6)
ret i32 0
}