#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 /*<<< orphan*/ srand(int);
int time(int /*<<< orphan*/ *);
int *random_array(int num) {
  int seed = time(NULL);
  int i = 0;
  int *array = (int *)malloc(num * sizeof(int));
  if (!array)
    return NULL;
  for (; i < num; i++) {
    srand(seed);
    seed = array[i] = rand();
  }
  return array;
}


x86 assembly (clang, -O0):
<random_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1189 <random_array+0x49>
movq   $0x0,-0x8(%rbp)
jmp    11cd <random_array+0x8d>
jmp    118e <random_array+0x4e>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <random_array+0x85>
mov    -0x10(%rbp),%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x20(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %eax,(%rcx,%rdx,4)
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118e <random_array+0x4e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11a0 <random_array+0x60>
mov    %rax,%r12
test   %r14d,%r14d
jle    119d <random_array+0x5d>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebp
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <random_array+0x40>
mov    %r12,%r15
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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