#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(int, int);
int rand();
int *buildRandomIntArray(int size, int max_val) {
  int *elems = (int *)calloc(sizeof(int), size);
  for (int i = 0; i < size; i++)
    elems[i] = rand() % max_val;
  return elems;
}


x86 assembly (clang, -O0):
<buildRandomIntArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x4,%edi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1176 <buildRandomIntArray+0x56>
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0x8(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <buildRandomIntArray+0x26>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildRandomIntArray>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x4,%edi
mov    %r14d,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    1168 <buildRandomIntArray+0x48>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %r15d
mov    %edx,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <buildRandomIntArray+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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