#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 /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
size_t b_malloc_bubble(void *dummy) {
  void *p[10000];
  size_t i;
  for (i = 0; i < sizeof p / sizeof *p; i++) {
    p[i] = malloc(4000);
    memset(p[i], 0, 4000);
  }
  for (i = 0; i < sizeof p / sizeof *p - 1; i++)
    free(p[i]);
  return 0;
}


x86 assembly (clang, -O0):
<b_malloc_bubble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x138a0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x13898(%rbp)
cmpq   $0x2710,-0x13898(%rbp)
jae    11a9 <b_malloc_bubble+0x79>
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x13898(%rbp),%rax
mov    %rcx,-0x13890(%rbp,%rax,8)
ff
mov    -0x13898(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rdi
ff
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
mov    -0x13898(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x13898(%rbp)
jmp    114a <b_malloc_bubble+0x1a>
movq   $0x0,-0x13898(%rbp)
cmpq   $0x270f,-0x13898(%rbp)
jae    11f0 <b_malloc_bubble+0xc0>
mov    -0x13898(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x13898(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x13898(%rbp)
jmp    11b4 <b_malloc_bubble+0x84>
xor    %eax,%eax
add    $0x138a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_malloc_bubble>:
push   %rbx
sub    $0x13880,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp,%rbx,8)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1140 <b_malloc_bubble+0x10>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x270f,%rbx
jne    1170 <b_malloc_bubble+0x40>
xor    %eax,%eax
add    $0x13880,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @b_malloc_bubble(i8* %0) {
%2 = alloca i8*
%3 = alloca [10000 x i8*]
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %4
br label %5
5: ; preds = %16, %1
%6 = load i64, i64* %4
%7 = icmp ult i64 %6, 10000
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = call i8* @malloc(i32 4000)
%10 = load i64, i64* %4
%11 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %3, i64 0, i64 %10
store i8* %9, i8** %11
%12 = load i64, i64* %4
%13 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %3, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @memset(i8* %14, i32 0, i32 4000)
br label %16
16: ; preds = %8
%17 = load i64, i64* %4
%18 = add i64 %17, 1
store i64 %18, i64* %4
br label %5
19: ; preds = %5
store i64 0, i64* %4
br label %20
20: ; preds = %28, %19
%21 = load i64, i64* %4
%22 = icmp ult i64 %21, 9999
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i64, i64* %4
%25 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %3, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %23
%29 = load i64, i64* %4
%30 = add i64 %29, 1
store i64 %30, i64* %4
br label %20
31: ; preds = %20
ret i64 0
}

LLVM IR (-O2):
define i64 @b_malloc_bubble(i8* nocapture readnone %0) {
%2 = alloca [10000 x i8*]
%3 = bitcast [10000 x i8*]* %2 to i8*
br label %4
4: ; preds = %1, %4
%5 = phi i64 [ 0, %1 ], [ %9, %4 ]
%6 = tail call dereferenceable_or_null(4000) i8* @malloc(i32 4000)
%7 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %2, i64 0, i64 %5
store i8* %6, i8** %7
%8 = tail call i32 @memset(i8* %6, i32 0, i32 4000)
%9 = add nuw nsw i64 %5, 1
%10 = icmp eq i64 %9, 10000
br i1 %10, label %11, label %4
11: ; preds = %4, %11
%12 = phi i64 [ %16, %11 ], [ 0, %4 ]
%13 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %2, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @free(i8* %14)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, 9999
br i1 %17, label %18, label %11
18: ; preds = %11
ret i64 0
}