#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__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, void *, size_t);
int FwdLockGlue_GetRandomNumber(void *pBuffer, size_t numBytes) {
  ssize_t numBytesRead = 0;
  int fileDesc = open("/dev/urandom", O_RDONLY);
  if (fileDesc >= 0) {
    numBytesRead = read(fileDesc, pBuffer, numBytes);
    (void)close(fileDesc);
  }
  return numBytesRead >= 0 && (size_t)numBytesRead == numBytes;
}


x86 assembly (clang, -O0):
<FwdLockGlue_GetRandomNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1186 <FwdLockGlue_GetRandomNumber+0x56>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <read@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jl     11a4 <FwdLockGlue_GetRandomNumber+0x74>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FwdLockGlue_GetRandomNumber>:
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     1171 <FwdLockGlue_GetRandomNumber+0x41>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <read@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <close@plt>
jmp    1173 <FwdLockGlue_GetRandomNumber+0x43>
xor    %ebx,%ebx
test   %rbx,%rbx
setns  %al
cmp    %r15,%rbx
sete   %cl
and    %al,%cl
movzbl %cl,%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 @FwdLockGlue_GetRandomNumber(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, 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 sge i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* %6
%13 = load i8*, i8** %3
%14 = load i64, i64* %4
%15 = call i64 @read(i32 %12, i8* %13, i64 %14)
store i64 %15, i64* %5
%16 = load i32, i32* %6
%17 = call i32 @close(i32 %16)
br label %18
18: ; preds = %11, %2
%19 = load i64, i64* %5
%20 = icmp sge i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i64, i64* %5
%23 = load i64, i64* %4
%24 = icmp eq i64 %22, %23
br label %25
25: ; preds = %21, %18
%26 = phi i1 [ false, %18 ], [ %24, %21 ]
%27 = zext i1 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @FwdLockGlue_GetRandomNumber(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 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 = tail call i32 @close(i32 %4)
br label %9
9: ; preds = %6, %2
%10 = phi i64 [ %7, %6 ], [ 0, %2 ]
%11 = icmp sgt i64 %10, -1
%12 = icmp eq i64 %10, %1
%13 = and i1 %11, %12
%14 = zext i1 %13 to i32
ret i32 %14
}