#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 */
long long rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
void generate(int *array, int n) {
  srand((unsigned int)(time(NULL)));
  while (n--)
    array[n] = rand() % ((1ll << 31) - 1);
}


x86 assembly (clang, -O0):
<generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1184 <generate+0x54>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x7fffffff,%ecx
cqto
idiv   %rcx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    114f <generate+0x1f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r15d,%r15d
je     11a3 <generate+0x73>
movslq %r15d,%rax
lea    (%r14,%rax,4),%r12
add    $0xfffffffffffffffc,%r12
neg    %r15d
movabs $0x8000000100000003,%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %rax,%rcx
imul   %r14
add    %rcx,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x1e,%rdx
add    %eax,%edx
mov    %edx,%eax
shl    $0x1f,%eax
sub    %eax,%edx
add    %edx,%ecx
mov    %ecx,(%r12,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r15d
jne    1170 <generate+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @generate(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = call i32 @srand(i32 %6)
br label %8
8: ; preds = %12, %2
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = call i64 (...) @rand()
%14 = srem i64 %13, 2147483647
%15 = trunc i64 %14 to i32
%16 = load i32*, i32** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 %15, i32* %19
br label %8
20: ; preds = %8
ret void
}

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