#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*/ EINVAL;
int /*<<< orphan*/ errno;
scalar_t__ randombytes_init();
int randombytes_unix(unsigned char *, size_t const);
int randombytes(unsigned char *out, const size_t nbytes) {
  if (out == NULL || nbytes == 0) {
    errno = EINVAL;
    goto error;
  }
  if (randombytes_init() != 0) {
    goto error;
  }
  return randombytes_unix(out, nbytes);
error:
  return 1;
}


x86 assembly (clang, -O0):
<randombytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <randombytes+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    115d <randombytes+0x3d>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8a(%rip),%rax
mov    %ecx,(%rax)
jmp    1188 <randombytes+0x68>
mov    $0x0,%al
call   1040 <randombytes_init@plt>
cmp    $0x0,%rax
je     1173 <randombytes+0x53>
jmp    1188 <randombytes+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <randombytes_unix@plt>
mov    %eax,-0x4(%rbp)
jmp    118f <randombytes+0x6f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randombytes>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1152 <randombytes+0x32>
mov    %rsi,%r14
test   %rsi,%rsi
je     1152 <randombytes+0x32>
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <randombytes_init@plt>
test   %rax,%rax
jne    1164 <randombytes+0x44>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <randombytes_unix@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    0x2e7e(%rip),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @randombytes(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %5
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
br label %21
13: ; preds = %8
%14 = call i64 (...) @randombytes_init()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
br label %21
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = call i32 @randombytes_unix(i8* %18, i64 %19)
store i32 %20, i32* %3
br label %22
21: ; preds = %16, %11
store i32 1, i32* %3
br label %22
22: ; preds = %21, %17
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @randombytes(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i64 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %13
8: ; preds = %2
%9 = tail call i64 (...) @randombytes_init()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @randombytes_unix(i8* %0, i64 %1)
br label %13
13: ; preds = %6, %8, %11
%14 = phi i32 [ %12, %11 ], [ 1, %8 ], [ 1, %6 ]
ret i32 %14
}