#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 */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ memset(void *, int, size_t);
int open(char *, int /*<<< orphan*/);
size_t read(int, void *, size_t);
void set_random(void *area, size_t size) {
  int fd = open("/dev/random", O_RDONLY);
  if (fd >= 0) {
    if (read(fd, area, size) == size)
      return;
  }
  memset(area, 0x00, size);
}


x86 assembly (clang, -O0):
<set_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    0xeb0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1186 <set_random+0x56>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <read@plt>
cmp    -0x10(%rbp),%rax
jne    1181 <set_random+0x51>
jmp    1195 <set_random+0x65>
jmp    1186 <set_random+0x56>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_random>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
lea    0xeb6(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     116d <set_random+0x3d>
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <read@plt>
cmp    %rbx,%rax
jne    116d <set_random+0x3d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <memset@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
define void @set_random(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i32, i32* %5
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = call i64 @read(i32 %11, i8* %12, i64 %13)
%15 = load i64, i64* %4
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %10
br label %23
18: ; preds = %10
br label %19
19: ; preds = %18, %2
%20 = load i8*, i8** %3
%21 = load i64, i64* %4
%22 = call i32 @memset(i8* %20, i32 0, i64 %21)
br label %23
23: ; preds = %19, %17
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
define void @set_random(i8* %0, i64 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @read(i32 %4, i8* %0, i64 %1)
%8 = icmp eq i64 %7, %1
br i1 %8, label %11, label %9
9: ; preds = %6, %2
%10 = tail call i32 @memset(i8* %0, i32 0, i64 %1)
br label %11
11: ; preds = %6, %9
ret void
}