#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, void *, int);
int fill_urandom_buff(char in[256]) {
  int crypto_fd = open("/dev/urandom", O_RDONLY);
  int ret = -1;
  if (crypto_fd < 0)
    return crypto_fd;
  ret = read(crypto_fd, (void *)in, 256);
  close(crypto_fd);
  return ret;
}


x86 assembly (clang, -O0):
<fill_urandom_buff>:
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,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1170 <fill_urandom_buff+0x40>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <fill_urandom_buff+0x62>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_urandom_buff>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116d <fill_urandom_buff+0x3d>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
jmp    116f <fill_urandom_buff+0x3f>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @fill_urandom_buff(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* %4
store i32 -1, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %4
store i32 %11, i32* %2
br label %19
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i8*, i8** %3
%15 = call i32 @read(i32 %13, i8* %14, i32 256)
store i32 %15, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %5
store i32 %18, i32* %2
br label %19
19: ; preds = %12, %10
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @fill_urandom_buff(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 %8, label %5
5: ; preds = %1
%6 = tail call i32 @read(i32 %3, i8* %0, i32 256)
%7 = tail call i32 @close(i32 %3)
br label %8
8: ; preds = %1, %5
%9 = phi i32 [ %6, %5 ], [ %3, %1 ]
ret i32 %9
}