#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;

/* Variables and functions */
int dev_urandom(void *, size_t);
int /*<<< orphan*/ initialize_srand();
int /*<<< orphan*/ rand();
void random_bytes(void *p, size_t n) {
  uint8_t *q;
  int r;
  r = dev_urandom(p, n);
  if (r >= 0)
    return;
  initialize_srand();
  for (q = p; q < (uint8_t *)p + n; q++)
    *q = rand();
}


x86 assembly (clang, -O0):
<random_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <dev_urandom@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     115f <random_bytes+0x2f>
jmp    11aa <random_bytes+0x7a>
mov    $0x0,%al
call   1040 <initialize_srand@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11aa <random_bytes+0x7a>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <random_bytes+0x3e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_bytes>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <dev_urandom@plt>
test   %eax,%eax
jns    1172 <random_bytes+0x42>
xor    %eax,%eax
call   1040 <initialize_srand@plt>
lea    (%rbx,%r14,4),%r14
cmp    %rbx,%r14
jbe    1172 <random_bytes+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,(%rbx)
add    $0x4,%rbx
cmp    %r14,%rbx
jb     1160 <random_bytes+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @random_bytes(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = load i64, i64* %4
%9 = call i32 @dev_urandom(i8* %7, i64 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
br label %30
13: ; preds = %2
%14 = call i32 (...) @initialize_srand()
%15 = load i8*, i8** %3
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %5
br label %17
17: ; preds = %27, %13
%18 = load i32*, i32** %5
%19 = load i8*, i8** %3
%20 = bitcast i8* %19 to i32*
%21 = load i64, i64* %4
%22 = getelementptr inbounds i32, i32* %20, i64 %21
%23 = icmp ult i32* %18, %22
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = call i32 (...) @rand()
%26 = load i32*, i32** %5
store i32 %25, i32* %26
br label %27
27: ; preds = %24
%28 = load i32*, i32** %5
%29 = getelementptr inbounds i32, i32* %28, i32 1
store i32* %29, i32** %5
br label %17
30: ; preds = %12, %17
ret void
}

LLVM IR (-O2):
define void @random_bytes(i8* %0, i64 %1) {
%3 = tail call i32 @dev_urandom(i8* %0, i64 %1)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call i32 (...) @initialize_srand()
%7 = bitcast i8* %0 to i32*
%8 = getelementptr inbounds i32, i32* %7, i64 %1
%9 = icmp ugt i32* %8, %7
br i1 %9, label %10, label %15
10: ; preds = %5, %10
%11 = phi i32* [ %13, %10 ], [ %7, %5 ]
%12 = tail call i32 (...) @rand()
store i32 %12, i32* %11
%13 = getelementptr inbounds i32, i32* %11, i64 1
%14 = icmp ult i32* %13, %8
br i1 %14, label %10, label %15
15: ; preds = %10, %5, %2
ret void
}