#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(size_t);
size_t b_malloc_big1(void *dummy) {
  void *p[2000];
  size_t i;
  for (i = 0; i < sizeof p / sizeof *p; i++) {
    p[i] = malloc((i % 4 + 1) * 16384);
  }
  for (i = 0; i < sizeof p / sizeof *p; i++) {
    free(p[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<b_malloc_big1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3ea0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x3e98(%rbp)
cmpq   $0x7d0,-0x3e98(%rbp)
jae    118c <b_malloc_big1+0x6c>
mov    -0x3e98(%rbp),%rdi
and    $0x3,%rdi
add    $0x1,%rdi
shl    $0xe,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x3e98(%rbp),%rax
mov    %rcx,-0x3e90(%rbp,%rax,8)
ff
mov    -0x3e98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x3e98(%rbp)
jmp    113a <b_malloc_big1+0x1a>
movq   $0x0,-0x3e98(%rbp)
cmpq   $0x7d0,-0x3e98(%rbp)
jae    11d3 <b_malloc_big1+0xb3>
mov    -0x3e98(%rbp),%rax
mov    -0x3e90(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x3e98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x3e98(%rbp)
jmp    1197 <b_malloc_big1+0x77>
xor    %eax,%eax
add    $0x3ea0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_malloc_big1>:
push   %r14
push   %rbx
sub    $0x3e88,%rsp
mov    %rsp,%r14
xor    %ebx,%ebx
nop
mov    %ebx,%edi
and    $0xc000,%edi
add    $0x4000,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r14)
add    $0x4000,%rbx
add    $0x8,%r14
cmp    $0x1f40000,%rbx
jne    1130 <b_malloc_big1+0x10>
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x7d0,%rbx
jne    1160 <b_malloc_big1+0x40>
xor    %eax,%eax
add    $0x3e88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @b_malloc_big1(i8* %0) {
%2 = alloca i8*
%3 = alloca [2000 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, 2000
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load i64, i64* %4
%10 = urem i64 %9, 4
%11 = add i64 %10, 1
%12 = mul i64 %11, 16384
%13 = call i8* @malloc(i64 %12)
%14 = load i64, i64* %4
%15 = getelementptr inbounds [2000 x i8*], [2000 x i8*]* %3, i64 0, i64 %14
store i8* %13, i8** %15
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, 2000
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i64, i64* %4
%25 = getelementptr inbounds [2000 x i8*], [2000 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_big1(i8* nocapture readnone %0) {
%2 = alloca [2000 x i8*]
%3 = bitcast [2000 x i8*]* %2 to i8*
br label %4
4: ; preds = %1, %4
%5 = phi i64 [ 0, %1 ], [ %11, %4 ]
%6 = shl nuw nsw i64 %5, 14
%7 = and i64 %6, 49152
%8 = add nuw nsw i64 %7, 16384
%9 = tail call i8* @malloc(i64 %8)
%10 = getelementptr inbounds [2000 x i8*], [2000 x i8*]* %2, i64 0, i64 %5
store i8* %9, i8** %10
%11 = add nuw nsw i64 %5, 1
%12 = icmp eq i64 %11, 2000
br i1 %12, label %13, label %4
13: ; preds = %4, %13
%14 = phi i64 [ %18, %13 ], [ 0, %4 ]
%15 = getelementptr inbounds [2000 x i8*], [2000 x i8*]* %2, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @free(i8* %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, 2000
br i1 %19, label %20, label %13
20: ; preds = %13
ret i64 0
}