#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 */
scalar_t__ calloc(size_t, int);
scalar_t__ malloc(int);
int rand();
char **myalloc_data_(size_t size) {
  int i = 0;
  char **tmp = NULL;
  char **buffer = (char **)calloc(size, sizeof(char *));
  for (i = 0, tmp = buffer; i < size; ++i, ++tmp) {
    int elem_size = 256 + rand() % 10;
    *tmp = (char *)malloc(elem_size);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<myalloc_data_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11be <myalloc_data_+0x8e>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x100,%edx
mov    %edx,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    116c <myalloc_data_+0x3c>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myalloc_data_>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %r14,%r14
je     118f <myalloc_data_+0x5f>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <myalloc_data_+0x20>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @myalloc_data_(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %3
store i8** null, i8*** %4
%7 = load i64, i64* %2
%8 = call i64 @calloc(i64 %7, i32 8)
%9 = inttoptr i64 %8 to i8**
store i8** %9, i8*** %5
store i32 0, i32* %3
%10 = load i8**, i8*** %5
store i8** %10, i8*** %4
br label %11
11: ; preds = %24, %1
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = load i64, i64* %2
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 10
%19 = add nsw i32 256, %18
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = load i8**, i8*** %4
store i8* %22, i8** %23
br label %24
24: ; preds = %16
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i32 1
store i8** %28, i8*** %4
br label %11
29: ; preds = %11
%30 = load i8**, i8*** %5
ret i8** %30
}

LLVM IR (-O2):
define i8** @myalloc_data_(i64 %0) {
%2 = tail call i64 @calloc(i64 %0, i32 8)
%3 = inttoptr i64 %2 to i8**
%4 = icmp eq i64 %0, 0
br i1 %4, label %16, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %13, %5 ], [ 0, %1 ]
%7 = phi i8** [ %14, %5 ], [ %3, %1 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 10
%10 = add nsw i32 %9, 256
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = add nuw i64 %6, 1
%14 = getelementptr inbounds i8*, i8** %7, i64 1
%15 = icmp eq i64 %13, %0
br i1 %15, label %16, label %5
16: ; preds = %5, %1
ret i8** %3
}