#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*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void gfsplit_fill_rand(unsigned char *buffer, unsigned int count) {
  size_t n;
  FILE *devrandom;
  devrandom = fopen("/dev/urandom", "rb");
  if (!devrandom) {
    perror("Unable to read /dev/urandom");
    abort();
  }
  n = fread(buffer, 1, count, devrandom);
  if (n < count) {
    perror("Short read from /dev/urandom");
    abort();
  }
  fclose(devrandom);
}


x86 assembly (clang, -O0):
<gfsplit_fill_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeac(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <gfsplit_fill_rand+0x44>
lea    0xe7b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
cmp    %rcx,%rax
jae    11d0 <gfsplit_fill_rand+0x80>
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfsplit_fill_rand>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1199 <gfsplit_fill_rand+0x49>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %ebp,%ecx
cmp    %rcx,%rax
jb     11a2 <gfsplit_fill_rand+0x52>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fclose@plt>
lea    0xe63(%rip),%rdi
jmp    11a9 <gfsplit_fill_rand+0x59>
lea    0xe76(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [28 x i8] c"Unable to read /dev/urandom\00"
@.str.3 = [29 x i8] c"Short read from /dev/urandom\00"
define void @gfsplit_fill_rand(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %6
%8 = load i32*, i32** %6
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = load i32*, i32** %6
%17 = call i64 @fread(i8* %14, i32 1, i32 %15, i32* %16)
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = load i32, i32* %4
%20 = zext i32 %19 to i64
%21 = icmp ult i64 %18, %20
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %13
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [28 x i8] c"Unable to read /dev/urandom\00"
@.str.3 = [29 x i8] c"Short read from /dev/urandom\00"
define void @gfsplit_fill_rand(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %2
%9 = tail call i64 @fread(i8* %0, i32 1, i32 %1, i32* %3)
%10 = zext i32 %1 to i64
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %8
%16 = tail call i32 @fclose(i32* %3)
ret void
}