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


x86 assembly (clang, -O0):
<b_malloc_tiny2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x138a0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x13898(%rbp)
cmpq   $0x2710,-0x13898(%rbp)
jae    118c <b_malloc_tiny2+0x6c>
mov    -0x13898(%rbp),%rdi
and    $0x3,%rdi
add    $0x1,%rdi
shl    $0x4,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x13898(%rbp),%rax
mov    %rcx,-0x13890(%rbp,%rax,8)
ff
mov    -0x13898(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x13898(%rbp)
jmp    113a <b_malloc_tiny2+0x1a>
movq   $0x1,-0x13898(%rbp)
cmpq   $0x0,-0x13898(%rbp)
je     11da <b_malloc_tiny2+0xba>
mov    -0x13898(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x13898(%rbp),%rax
add    $0x39,%rax
mov    $0x2710,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x13898(%rbp)
jmp    1197 <b_malloc_tiny2+0x77>
xor    %eax,%eax
add    $0x138a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_malloc_tiny2>:
push   %r14
push   %rbx
sub    $0x13888,%rsp
mov    %rsp,%r14
xor    %ebx,%ebx
nop
mov    %ebx,%edi
and    $0x30,%edi
add    $0x10,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r14)
add    $0x10,%rbx
add    $0x8,%r14
cmp    $0x27100,%rbx
jne    1130 <b_malloc_tiny2+0x10>
mov    $0x1,%ebx
mov    $0xd1b71759,%r14d
nopl   (%rax)
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x39,%rbx
mov    %ebx,%eax
imul   %r14,%rax
shr    $0x2d,%rax
imul   $0x2710,%eax,%eax
sub    %eax,%ebx
jne    1160 <b_malloc_tiny2+0x40>
xor    %eax,%eax
add    $0x13888,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @b_malloc_tiny2(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 = load i64, i64* %4
%10 = urem i64 %9, 4
%11 = add i64 %10, 1
%12 = mul i64 %11, 16
%13 = call i8* @malloc(i64 %12)
%14 = load i64, i64* %4
%15 = getelementptr inbounds [10000 x i8*], [10000 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 1, i64* %4
br label %20
20: ; preds = %28, %19
%21 = load i64, i64* %4
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %32
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, 57
%31 = urem i64 %30, 10000
store i64 %31, i64* %4
br label %20
32: ; preds = %20
ret i64 0
}

LLVM IR (-O2):
define i64 @b_malloc_tiny2(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 ], [ %11, %4 ]
%6 = shl nuw nsw i64 %5, 4
%7 = and i64 %6, 48
%8 = add nuw nsw i64 %7, 16
%9 = tail call i8* @malloc(i64 %8)
%10 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %2, i64 0, i64 %5
store i8* %9, i8** %10
%11 = add nuw nsw i64 %5, 1
%12 = icmp eq i64 %11, 10000
br i1 %12, label %13, label %4
13: ; preds = %4, %13
%14 = phi i64 [ %19, %13 ], [ 1, %4 ]
%15 = getelementptr inbounds [10000 x i8*], [10000 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, 57
%19 = urem i64 %18, 10000
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %13
21: ; preds = %13
ret i64 0
}