#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() {
  int *ptr, i, j;
  for (i = 0; i < 1000000; i++) {
    ptr = malloc(1000 * sizeof(int));
    for (j = 0; j < 999; j++)
      ptr[j] = i;
    free(ptr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    1198 <main+0x78>
mov    $0xfa0,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e7,-0x18(%rbp)
jge    1181 <main+0x61>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1158 <main+0x38>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xfa0,%edi
call   1040 <malloc@plt>
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
mov    $0x1c,%ecx
nopl   0x0(%rax,%rax,1)
movdqu %xmm0,-0x70(%rax,%rcx,4)
movdqu %xmm0,-0x60(%rax,%rcx,4)
movdqu %xmm0,-0x50(%rax,%rcx,4)
movdqu %xmm0,-0x40(%rax,%rcx,4)
movdqu %xmm0,-0x30(%rax,%rcx,4)
movdqu %xmm0,-0x20(%rax,%rcx,4)
movdqu %xmm0,-0x10(%rax,%rcx,4)
movdqu %xmm0,(%rax,%rcx,4)
add    $0x20,%rcx
cmp    $0x3fc,%rcx
jne    1150 <main+0x30>
mov    %ebx,0xf80(%rax)
mov    %ebx,0xf84(%rax)
mov    %ebx,0xf88(%rax)
mov    %ebx,0xf8c(%rax)
mov    %ebx,0xf90(%rax)
mov    %ebx,0xf94(%rax)
mov    %ebx,0xf98(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
add    $0x1,%ebx
cmp    $0xf4240,%ebx
jne    1130 <main+0x10>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @main() {
br label %1
1: ; preds = %0, %31
%2 = phi i32 [ 0, %0 ], [ %40, %31 ]
%3 = tail call i32* @malloc(i32 4000)
%4 = insertelement <4 x i32> poison, i32 %2, i64 0
%5 = shufflevector <4 x i32> %4, <4 x i32> poison, <4 x i32> zeroinitializer
%6 = insertelement <4 x i32> poison, i32 %2, i64 0
%7 = shufflevector <4 x i32> %6, <4 x i32> poison, <4 x i32> zeroinitializer
br label %8
8: ; preds = %8, %1
%9 = phi i64 [ 0, %1 ], [ %29, %8 ]
%10 = getelementptr inbounds i32, i32* %3, i64 %9
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %11
%12 = getelementptr inbounds i32, i32* %10, i64 4
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %13
%14 = or i64 %9, 8
%15 = getelementptr inbounds i32, i32* %3, i64 %14
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %16
%17 = getelementptr inbounds i32, i32* %15, i64 4
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %18
%19 = or i64 %9, 16
%20 = getelementptr inbounds i32, i32* %3, i64 %19
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %23
%24 = or i64 %9, 24
%25 = getelementptr inbounds i32, i32* %3, i64 %24
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %26
%27 = getelementptr inbounds i32, i32* %25, i64 4
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %28
%29 = add nuw nsw i64 %9, 32
%30 = icmp eq i64 %29, 992
br i1 %30, label %31, label %8
31: ; preds = %8
%32 = getelementptr inbounds i32, i32* %3, i64 992
store i32 %2, i32* %32
%33 = getelementptr inbounds i32, i32* %3, i64 993
store i32 %2, i32* %33
%34 = getelementptr inbounds i32, i32* %3, i64 994
store i32 %2, i32* %34
%35 = getelementptr inbounds i32, i32* %3, i64 995
store i32 %2, i32* %35
%36 = getelementptr inbounds i32, i32* %3, i64 996
store i32 %2, i32* %36
%37 = getelementptr inbounds i32, i32* %3, i64 997
store i32 %2, i32* %37
%38 = getelementptr inbounds i32, i32* %3, i64 998
store i32 %2, i32* %38
%39 = tail call i32 @free(i32* %3)
%40 = add nuw nsw i32 %2, 1
%41 = icmp eq i32 %40, 1000000
br i1 %41, label %42, label %1
42: ; preds = %31
ret i32 0
}