#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 */
void **malloc(int);
void *myalloc(scalar_t__);
int /*<<< orphan*/ myfree(void *);
scalar_t__ rand89();
void test0() {
  int Y = 100;
  void **vps = malloc(sizeof(void *) * Y);
  for (int i = 0; i < Y; i++) {
    vps[i] = myalloc(rand89() + 20000000);
    char *p = vps[i];
    for (int i = 0; i < 20; i++) {
      p[i] = 90;
    }
  }
  for (int i = 0; i < Y; i++) {
    myfree(vps[i]);
  }
}


x86 assembly (clang, -O0):
<test0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x64,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e8 <test0+0xa8>
mov    $0x0,%al
call   1030 <rand89@plt>
mov    %rax,%rdi
add    $0x1312d00,%rdi
call   1040 <myalloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x14,-0x24(%rbp)
jge    11d5 <test0+0x95>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x5a,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b1 <test0+0x71>
jmp    11da <test0+0x9a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <test0+0x29>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121a <test0+0xda>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <myfree@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ef <test0+0xaf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test0>:
push   %r14
push   %rbx
push   %rax
mov    $0x320,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <rand89@plt>
lea    0x1312d00(%rax),%rdi
call   1040 <myalloc@plt>
mov    %rax,(%r14,%rbx,8)
movaps 0xe82(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x5a5a5a5a,0x10(%rax)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1160 <test0+0x20>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,8),%rdi
call   1060 <myfree@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    11a0 <test0+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @test0() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 100, i32* %1
%7 = load i32, i32* %1
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i8** @malloc(i32 %10)
store i8** %11, i8*** %2
store i32 0, i32* %3
br label %12
12: ; preds = %41, %0
%13 = load i32, i32* %3
%14 = load i32, i32* %1
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %44
16: ; preds = %12
%17 = call i64 (...) @rand89()
%18 = add nsw i64 %17, 20000000
%19 = call i8* @myalloc(i64 %18)
%20 = load i8**, i8*** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
store i8* %19, i8** %23
%24 = load i8**, i8*** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
store i8* %28, i8** %4
store i32 0, i32* %5
br label %29
29: ; preds = %37, %16
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 20
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 90, i8* %36
br label %37
37: ; preds = %32
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %29
40: ; preds = %29
br label %41
41: ; preds = %40
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %12
44: ; preds = %12
store i32 0, i32* %6
br label %45
45: ; preds = %56, %44
%46 = load i32, i32* %6
%47 = load i32, i32* %1
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %59
49: ; preds = %45
%50 = load i8**, i8*** %2
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 @myfree(i8* %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %45
59: ; preds = %45
ret void
}

LLVM IR (-O2):
define void @test0() {
%1 = tail call i8** @malloc(i32 800)
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %8, %2 ]
%4 = tail call i64 (...) @rand89()
%5 = add nsw i64 %4, 20000000
%6 = tail call i8* @myalloc(i64 %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 %3
store i8* %6, i8** %7
%8 = add nuw nsw i64 %3, 1
%9 = icmp eq i64 %8, 100
br i1 %9, label %11, label %2
10: ; preds = %11
ret void
11: ; preds = %2, %11
%12 = phi i64 [ %16, %11 ], [ 0, %2 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @myfree(i8* %14)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, 100
br i1 %17, label %10, label %11
}