#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__ malloc(int);
int rand();
int *generateRandomArrayOfInts(int size) {
  int *intArray = (int *)malloc(size * (sizeof(int)));
  if (intArray != NULL) {
    int i;
    for (i = 0; i < size; ++i) {
      intArray[i] = rand() % 100;
    }
  }
  return intArray;
}


x86 assembly (clang, -O0):
<generateRandomArrayOfInts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1189 <generateRandomArrayOfInts+0x69>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1184 <generateRandomArrayOfInts+0x64>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
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    1150 <generateRandomArrayOfInts+0x30>
jmp    1189 <generateRandomArrayOfInts+0x69>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateRandomArrayOfInts>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     117f <generateRandomArrayOfInts+0x5f>
test   %r14d,%r14d
jle    117f <generateRandomArrayOfInts+0x5f>
mov    %r14d,%r14d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <generateRandomArrayOfInts+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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