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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, unsigned long long, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void randombytes(unsigned char *p_bytes, unsigned long long length) {
  FILE *fr = fopen("/dev/urandom", "r");
  if (fr == NULL) {
    perror("urandom");
    exit(EXIT_FAILURE);
  }
  size_t tmp = fread(p_bytes, sizeof(unsigned char), length, fr);
  fclose(fr);
  if (tmp != length) {
    assert(0);
  }
}


x86 assembly (clang, -O0):
<randombytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ac <randombytes+0x4c>
lea    0xe6c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11e4 <randombytes+0x84>
xor    %edi,%edi
call   1050 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randombytes>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe8e(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bb <randombytes+0x5b>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    %r15,%r14
jne    11af <randombytes+0x4f>
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <assert@plt>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"urandom\00"
@EXIT_FAILURE = global i32 0
define void @randombytes(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = load i32*, i32** %5
%18 = call i64 @fread(i8* %15, i32 1, i64 %16, i32* %17)
store i64 %18, i64* %6
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
%21 = load i64, i64* %6
%22 = load i64, i64* %4
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 @assert(i32 0)
br label %26
26: ; preds = %24, %14
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"urandom\00"
@EXIT_FAILURE = global i32 0
define void @randombytes(i8* nocapture %0, i64 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = tail call i64 @fread(i8* %0, i32 1, i64 %1, i32* %3)
%11 = tail call i32 @fclose(i32* %3)
%12 = icmp eq i64 %10, %1
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @assert(i32 0)
br label %15
15: ; preds = %13, %9
ret void
}