#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(int *);
int *malloc(int);
int main(void) {
  int i, *x1, *x2, *x3, *x4;
  for (i = 0; i < 1500; i++) {
    x1 = malloc(800 * 1000);
    x2 = malloc(1100 * 1000);
    free(x1);
    x3 = malloc(1200 * 1000);
    free(x2);
    free(x3);
    x4 = malloc(900 * 1000);
    free(x4);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5dc,-0x8(%rbp)
jge    11ad <main+0x8d>
mov    $0xc3500,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x10c8e0,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x124f80,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0xdbba0,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x5dc,%ebp
nopl   0x0(%rax)
mov    $0xc3500,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x10c8e0,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x124f80,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xdbba0,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
jne    1130 <main+0x10>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
br label %7
7: ; preds = %23, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 1500
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = call i32* @malloc(i32 800000)
store i32* %11, i32** %3
%12 = call i32* @malloc(i32 1100000)
store i32* %12, i32** %4
%13 = load i32*, i32** %3
%14 = call i32 @free(i32* %13)
%15 = call i32* @malloc(i32 1200000)
store i32* %15, i32** %5
%16 = load i32*, i32** %4
%17 = call i32 @free(i32* %16)
%18 = load i32*, i32** %5
%19 = call i32 @free(i32* %18)
%20 = call i32* @malloc(i32 900000)
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = call i32 @free(i32* %21)
br label %23
23: ; preds = %10
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %7
26: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %11, %1 ]
%3 = tail call i32* @malloc(i32 800000)
%4 = tail call i32* @malloc(i32 1100000)
%5 = tail call i32 @free(i32* %3)
%6 = tail call i32* @malloc(i32 1200000)
%7 = tail call i32 @free(i32* %4)
%8 = tail call i32 @free(i32* %6)
%9 = tail call i32* @malloc(i32 900000)
%10 = tail call i32 @free(i32* %9)
%11 = add nuw nsw i32 %2, 1
%12 = icmp eq i32 %11, 1500
br i1 %12, label %13, label %1
13: ; preds = %1
ret i32 0
}