#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int main(int argc, char **argv) {
  char *stack[10000];
  char *blob;
  int i, j;
  for (j = 0; j < 20000; j++) {
    for (i = 0; i < 10000; i++) {
      blob = malloc(1024);
      if (blob == NULL) {
        exit(EXIT_FAILURE);
      }
      stack[i] = blob;
      free(blob);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x138a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x138a0(%rbp)
cmpl   $0x4e20,-0x138a0(%rbp)
jge    11f9 <main+0xc9>
movl   $0x0,-0x1389c(%rbp)
cmpl   $0x2710,-0x1389c(%rbp)
jge    11e0 <main+0xb0>
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x13898(%rbp)
cmpq   $0x0,-0x13898(%rbp)
jne    11aa <main+0x7a>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x13898(%rbp),%rcx
movslq -0x1389c(%rbp),%rax
mov    %rcx,-0x13890(%rbp,%rax,8)
ff
mov    -0x13898(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1389c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1389c(%rbp)
jmp    116d <main+0x3d>
jmp    11e5 <main+0xb5>
mov    -0x138a0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138a0(%rbp)
jmp    1153 <main+0x23>
mov    -0x4(%rbp),%eax
add    $0x138a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2710,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x400,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1180 <main+0x50>
mov    %rax,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
jne    1150 <main+0x20>
add    $0x1,%ebx
cmp    $0x4e20,%ebx
jne    1140 <main+0x10>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %16
%4 = phi i32 [ 0, %2 ], [ %17, %16 ]
br label %5
5: ; preds = %3, %12
%6 = phi i32 [ 0, %3 ], [ %14, %12 ]
%7 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %5
%13 = tail call i32 @free(i8* %7)
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, 10000
br i1 %15, label %16, label %5
16: ; preds = %12
%17 = add nuw nsw i32 %4, 1
%18 = icmp eq i32 %17, 20000
br i1 %18, label %19, label %3
19: ; preds = %16
ret i32 0
}