#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 int /*<<< orphan*/ time_t;

/* Variables and functions */
int *malloc(int);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int *genrandarr(int size) {
  time_t t;
  srand((unsigned)time(&t));
  int *array = malloc(sizeof(int) * size);
  if (!array)
    return NULL;
  for (int i = 0; i < size; ++i)
    *(array + i) = rand();
  return array;
}


x86 assembly (clang, -O0):
<genrandarr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <genrandarr+0x46>
movq   $0x0,-0x8(%rbp)
jmp    11c3 <genrandarr+0x83>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bb <genrandarr+0x7b>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <genrandarr+0x4d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genrandarr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0xc(%rsp),%rdi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1194 <genrandarr+0x54>
test   %r14d,%r14d
jle    1194 <genrandarr+0x54>
mov    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <genrandarr+0x40>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i32* @genrandarr(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i64 @time(i32* %2)
%5 = trunc i64 %4 to i32
%6 = call i32 @srand(i32 %5)
%7 = shl i32 %0, 2
%8 = call i32* @malloc(i32 %7)
%9 = icmp ne i32* %8, null
%10 = icmp sgt i32 %0, 0
%11 = and i1 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %18, %14 ]
%16 = call i32 (...) @rand()
%17 = getelementptr inbounds i32, i32* %8, i64 %15
store i32 %16, i32* %17
%18 = add nuw nsw i64 %15, 1
%19 = icmp eq i64 %18, %13
br i1 %19, label %20, label %14
20: ; preds = %14, %1
ret i32* %8
}