#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*/ close(int);
int open_or_die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ panic(char *);
int read_exact(int, unsigned char *, size_t, int /*<<< orphan*/);
void randombytes_strong(unsigned char *x, size_t xlen) {
  int fds, ret;
  fds = open_or_die("/dev/random", O_RDONLY);
  ret = read_exact(fds, x, xlen, 0);
  if (ret != (int)xlen)
    panic("Error reading from entropy source!\n");
  close(fds);
}


x86 assembly (clang, -O0):
<randombytes_strong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1050 <open_or_die@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <read_exact@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    %ecx,%eax
je     1198 <randombytes_strong+0x58>
lea    0xe79(%rip),%rdi
call   1030 <panic@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randombytes_strong>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1050 <open_or_die@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1060 <read_exact@plt>
cmp    %r14d,%eax
je     1182 <randombytes_strong+0x42>
lea    0xe8f(%rip),%rdi
call   1030 <panic@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.1 = [36 x i8] c"Error reading from entropy source!\0A\00"
define void @randombytes_strong(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 i32, i32* @O_RDONLY
%8 = call i32 @open_or_die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = call i32 @read_exact(i32 %9, i8* %10, i64 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = load i64, i64* %4
%15 = trunc i64 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @panic(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.1 = [36 x i8] c"Error reading from entropy source!\0A\00"
define void @randombytes_strong(i8* %0, i64 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open_or_die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @read_exact(i32 %4, i8* %0, i64 %1, i32 0)
%6 = trunc i64 %1 to i32
%7 = icmp eq i32 %5, %6
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @panic(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = tail call i32 @close(i32 %4)
ret void
}