#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 /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned int *, int);
unsigned int devrand(void) {
  int fn;
  unsigned int r;
  fn = open("/dev/urandom", O_RDONLY);
  if (fn == -1) {
    exit(-1);
  }
  if (read(fn, &r, 4) != 4) {
    exit(-1);
  }
  close(fn);
  return r;
}


x86 assembly (clang, -O0):
<devrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1174 <devrand+0x34>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
je     1198 <devrand+0x58>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devrand>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1188 <devrand+0x48>
mov    %eax,%ebx
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    1188 <devrand+0x48>
mov    %ebx,%edi
call   1030 <close@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0xffffffff,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @devrand() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%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 eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %0
%9 = call i32 @read(i32 %4, i32* %1, i32 4)
%10 = icmp eq i32 %9, 4
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %8
%14 = tail call i32 @close(i32 %4)
%15 = load i32, i32* %1
ret i32 %15
}