#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_int_array(int num) {
  int *array = (int *)malloc(num * sizeof(int));
  int seed = time(NULL);
  while (num--) {
    srand(seed);
    seed = array[num] = rand();
  }
  return array;
}


x86 assembly (clang, -O0):
<random_int_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     11a0 <random_int_array+0x60>
mov    -0x14(%rbp),%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x10(%rbp),%rcx
movslq -0x4(%rbp),%rdx
mov    %eax,(%rcx,%rdx,4)
mov    %eax,-0x14(%rbp)
jmp    116a <random_int_array+0x2a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_int_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x0(,%r15,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1040 <time@plt>
test   %r15d,%r15d
je     119b <random_int_array+0x5b>
movslq %r15d,%rcx
lea    (%r14,%rcx,4),%r12
add    $0xfffffffffffffffc,%r12
neg    %r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,(%r12,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r15d
jne    1180 <random_int_array+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @random_int_array(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 = call i32 @time(i32* null)
store i32 %11, i32* %4
br label %12
12: ; preds = %16, %1
%13 = load i32, i32* %2
%14 = add nsw i32 %13, -1
store i32 %14, i32* %2
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @srand(i32 %17)
%19 = call i32 (...) @rand()
%20 = load i32*, i32** %3
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 %19, i32* %23
store i32 %19, i32* %4
br label %12
24: ; preds = %12
%25 = load i32*, i32** %3
ret i32* %25
}

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