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

/* Variables and functions */
int cw_rand_r(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ rand();
int /*<<< orphan*/ srand(scalar_t__);
scalar_t__ time(int /*<<< orphan*/ *);
int cw_rand(uint8_t *dst, int len) {
  static uint32_t rinit = 0;
  if (!rinit) {
    int l = cw_rand_r((uint8_t *)(&rinit), sizeof(uint32_t));
    if (l < sizeof(uint32_t)) {

      ;
      rinit = time(NULL);
    }
    srand(rinit);
  }
  int i;
  for (i = 0; i < len; i++) {
    dst[i] = rand();
  }
  return len;
}


x86 assembly (clang, -O0):
<cw_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,0x2ef1(%rip)
jne    119b <cw_rand+0x5b>
lea    0x2ee4(%rip),%rdi
mov    $0x8,%esi
call   1050 <cw_rand_r@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    $0x8,%rax
jae    118f <cw_rand+0x4f>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,0x2eb9(%rip)
mov    0x2eb2(%rip),%rdi
call   1030 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d0 <cw_rand+0x90>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a2 <cw_rand+0x62>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cw_rand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
cmpq   $0x0,0x2ef3(%rip)
je     115e <cw_rand+0x1e>
test   %r14d,%r14d
jg     1198 <cw_rand+0x58>
jmp    11b4 <cw_rand+0x74>
lea    0x2ee3(%rip),%rdi
mov    $0x8,%esi
call   1050 <cw_rand_r@plt>
cmp    $0x8,%eax
jae    1187 <cw_rand+0x47>
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,%rdi
mov    %rax,0x2ec3(%rip)
jmp    118e <cw_rand+0x4e>
mov    0x2eba(%rip),%rdi
call   1030 <srand@plt>
test   %r14d,%r14d
jle    11b4 <cw_rand+0x74>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <cw_rand+0x60>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@cw_rand.rinit = internal global i64 0
define i32 @cw_rand(i32* nocapture writeonly %0, i32 returned %1) {
%3 = load i64, i64* @cw_rand.rinit
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = tail call i32 @cw_rand_r(i32* bitcast (i64* @cw_rand.rinit to i32*), i32 8)
%7 = icmp ult i32 %6, 8
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = load i64, i64* @cw_rand.rinit
br label %12
10: ; preds = %5
%11 = tail call i64 @time(i32* null)
store i64 %11, i64* @cw_rand.rinit
br label %12
12: ; preds = %8, %10
%13 = phi i64 [ %9, %8 ], [ %11, %10 ]
%14 = tail call i32 @srand(i64 %13)
br label %15
15: ; preds = %12, %2
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %25
17: ; preds = %15
%18 = zext i32 %1 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %23, %19 ]
%21 = tail call i32 (...) @rand()
%22 = getelementptr inbounds i32, i32* %0, i64 %20
store i32 %21, i32* %22
%23 = add nuw nsw i64 %20, 1
%24 = icmp eq i64 %23, %18
br i1 %24, label %25, label %19
25: ; preds = %19, %15
ret i32 %1
}