#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*/);
int read(int, char *, int);
int get_nonse(char *buf) {
  int n;
  int fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0)
    return fd;
  n = read(fd, buf, 16);
  if (n < 16)
    n = -1;
  close(fd);
  return n;
}


x86 assembly (clang, -O0):
<get_nonse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
lea    0xeb4(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1169 <get_nonse+0x39>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <get_nonse+0x6c>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    118e <get_nonse+0x5e>
movl   $0xffffffff,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nonse>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0xeb9(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1175 <get_nonse+0x45>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <read@plt>
cmp    $0x10,%eax
mov    $0xffffffff,%ebp
cmovge %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%ebx
mov    %ebx,%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 @get_nonse(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %5
store i32 %11, i32* %2
br label %23
12: ; preds = %1
%13 = load i32, i32* %5
%14 = load i8*, i8** %3
%15 = call i32 @read(i32 %13, i8* %14, i32 16)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 16
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 -1, i32* %4
br label %19
19: ; preds = %18, %12
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %23
23: ; preds = %19, %10
%24 = load i32, i32* %2
ret i32 %24
}

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