#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 scalar_t__ uint8_t;
typedef int int8_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
size_t read(int, scalar_t__ *, scalar_t__);
int8_t randLIB_get_n_bytes_random(uint8_t *data_ptr,
                                  uint8_t eight_bit_boundary) {
  if ((data_ptr == 0) || (eight_bit_boundary == 0)) {
    return -1;
  }
  int fd = open("/dev/urandom", O_RDONLY);
  if (fd != -1) {
    size_t len = read(fd, data_ptr, eight_bit_boundary);
    close(fd);
    if (len == eight_bit_boundary)
      return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<randLIB_get_n_bytes_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <randLIB_get_n_bytes_random+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1162 <randLIB_get_n_bytes_random+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <randLIB_get_n_bytes_random+0x96>
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     11bf <randLIB_get_n_bytes_random+0x8f>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <read@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11ba <randLIB_get_n_bytes_random+0x8a>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <randLIB_get_n_bytes_random+0x96>
jmp    11bf <randLIB_get_n_bytes_random+0x8f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randLIB_get_n_bytes_random>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1188 <randLIB_get_n_bytes_random+0x58>
mov    %rsi,%r14
test   %rsi,%rsi
je     1188 <randLIB_get_n_bytes_random+0x58>
mov    %rdi,%rbx
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1183 <randLIB_get_n_bytes_random+0x53>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <read@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
cmp    %r14,%rbx
je     1188 <randLIB_get_n_bytes_random+0x58>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @randLIB_get_n_bytes_random(i64* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
store i64* %0, i64** %4
store i64 %1, i64* %5
%8 = load i64*, i64** %4
%9 = icmp eq i64* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i64, i64* %5
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store i32 -1, i32* %3
br label %32
14: ; preds = %10
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = load i32, i32* %6
%21 = load i64*, i64** %4
%22 = load i64, i64* %5
%23 = call i64 @read(i32 %20, i64* %21, i64 %22)
store i64 %23, i64* %7
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = load i64, i64* %7
%27 = load i64, i64* %5
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %19
store i32 0, i32* %3
br label %32
30: ; preds = %19
br label %31
31: ; preds = %30, %14
store i32 -1, i32* %3
br label %32
32: ; preds = %31, %29, %13
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @randLIB_get_n_bytes_random(i64* %0, i64 %1) {
%3 = icmp eq i64* %0, null
%4 = icmp eq i64 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call i64 @read(i32 %8, i64* %0, i64 %1)
%12 = tail call i32 @close(i32 %8)
%13 = icmp eq i64 %11, %1
br i1 %13, label %15, label %14
14: ; preds = %10, %6
br label %15
15: ; preds = %14, %10, %2
%16 = phi i32 [ -1, %2 ], [ -1, %14 ], [ 0, %10 ]
ret i32 %16
}