#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 */
typedef unsigned int max;

/* Variables and functions */
size_t *malloc(unsigned int);
int /*<<< orphan*/ perror(char *);
unsigned int rand();
size_t *rand_sizes(unsigned int min, unsigned int max, unsigned int n_ops) {
  size_t *rand_sizes = malloc(n_ops * sizeof(size_t));
  if (rand_sizes == NULL) {
    perror("malloc");
    return NULL;
  }
  for (size_t i = 0; i < n_ops; i++) {
    rand_sizes[i] = (rand() % ((max) - (min)) + (min));
  }
  return rand_sizes;
}


x86 assembly (clang, -O0):
<rand_sizes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1177 <rand_sizes+0x47>
lea    0xe9b(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cc <rand_sizes+0x9c>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jae    11c4 <rand_sizes+0x94>
mov    $0x0,%al
call   1050 <rand@plt>
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
xor    %edx,%edx
div    %ecx
add    -0xc(%rbp),%edx
mov    %edx,%eax
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117f <rand_sizes+0x4f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_sizes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%r14d
lea    0x0(,%r15,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     119f <rand_sizes+0x6f>
test   %r15d,%r15d
je     118d <rand_sizes+0x5d>
mov    %r15d,%ebp
sub    %r14d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
xor    %edx,%edx
div    %r12d
add    %r14d,%edx
mov    %rdx,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <rand_sizes+0x40>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5a(%rip),%rdi
call   1040 <perror@plt>
jmp    118d <rand_sizes+0x5d>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
define i64* @rand_sizes(i32 %0, i32 %1, i32 %2) {
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = zext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i64* @malloc(i32 %13)
store i64* %14, i64** %8
%15 = load i64*, i64** %8
%16 = icmp eq i64* %15, null
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i64* null, i64** %4
br label %42
19: ; preds = %3
store i64 0, i64* %9
br label %20
20: ; preds = %37, %19
%21 = load i64, i64* %9
%22 = load i32, i32* %7
%23 = zext i32 %22 to i64
%24 = icmp ult i64 %21, %23
br i1 %24, label %25, label %40
25: ; preds = %20
%26 = call i32 (...) @rand()
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = sub i32 %27, %28
%30 = urem i32 %26, %29
%31 = load i32, i32* %5
%32 = add i32 %30, %31
%33 = zext i32 %32 to i64
%34 = load i64*, i64** %8
%35 = load i64, i64* %9
%36 = getelementptr inbounds i64, i64* %34, i64 %35
store i64 %33, i64* %36
br label %37
37: ; preds = %25
%38 = load i64, i64* %9
%39 = add i64 %38, 1
store i64 %39, i64* %9
br label %20
40: ; preds = %20
%41 = load i64*, i64** %8
store i64* %41, i64** %4
br label %42
42: ; preds = %40, %17
%43 = load i64*, i64** %4
ret i64* %43
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
define noalias i64* @rand_sizes(i32 %0, i32 %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = shl i32 %2, 3
%6 = tail call i64* @malloc(i32 %5)
%7 = icmp eq i64* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = icmp eq i32 %2, 0
br i1 %9, label %23, label %10
10: ; preds = %8
%11 = sub i32 %1, %0
br label %14
12: ; preds = %3
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %23
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %21, %14 ]
%16 = tail call i32 (...) @rand()
%17 = urem i32 %16, %11
%18 = add i32 %17, %0
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* %6, i64 %15
store i64 %19, i64* %20
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %4
br i1 %22, label %23, label %14
23: ; preds = %14, %8, %12
ret i64* %6
}