#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(char *, int /*<<< orphan*/);
size_t read(int, unsigned char *, size_t);
bool get_randoms(unsigned char *randoms, size_t randoms_length) {
  int fd;
  fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0)
    return false;
  if (read(fd, randoms, randoms_length) != randoms_length) {
    close(fd);
    return false;
  }
  close(fd);
  return true;
}


x86 assembly (clang, -O0):
<get_randoms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    0xeb0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    116e <get_randoms+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11ab <get_randoms+0x7b>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <read@plt>
cmp    -0x18(%rbp),%rax
je     119c <get_randoms+0x6c>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ab <get_randoms+0x7b>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_randoms>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
lea    0xeb3(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1176 <get_randoms+0x46>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <read@plt>
xor    %ebx,%ebx
cmp    %r15,%rax
sete   %bl
mov    %ebp,%edi
call   1030 <close@plt>
jmp    1178 <get_randoms+0x48>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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