#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*/ uint32_t;

/* Variables and functions */
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
void time_rand(int *buf, int num) {
  if (buf == NULL)
    return;
  srand((uint32_t)time(NULL));
  for (; num >= 0; num--) {
    ((int *)buf)[num] = rand();
  }
  return;
}


x86 assembly (clang, -O0):
<time_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114f <time_rand+0x1f>
jmp    1190 <time_rand+0x60>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmpl   $0x0,-0xc(%rbp)
jl     118b <time_rand+0x5b>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    115f <time_rand+0x2f>
jmp    1190 <time_rand+0x60>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_rand>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1170 <time_rand+0x40>
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
js     1170 <time_rand+0x40>
mov    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0xffffffffffffffff,%rbp
jb     1160 <time_rand+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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