#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*/ EIO;
int /*<<< orphan*/ errno;
int getentropy_fallback(void *, size_t);
int getentropy_urandom(void *, size_t);
int getentropy(void *buf, size_t len) {
  int ret = -1;
  if (len > 256) {
    errno = EIO;
    return (-1);
  }
  ret = getentropy_urandom(buf, len);
  if (ret != -1)
    return (ret);
  ret = getentropy_fallback(buf, len);
  if (ret != -1)
    return (ret);
  errno = EIO;
  return (ret);
}


x86 assembly (clang, -O0):
<getentropy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpq   $0x100,-0x18(%rbp)
jbe    1163 <getentropy+0x43>
mov    0x2e94(%rip),%rax
mov    (%rax),%ecx
mov    0x2e83(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <getentropy+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <getentropy_urandom@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     1188 <getentropy+0x68>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <getentropy+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <getentropy_fallback@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     11ad <getentropy+0x8d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <getentropy+0xa5>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1b(%rip),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getentropy>:
push   %r14
push   %rbx
push   %rax
cmp    $0x100,%rsi
jbe    1146 <getentropy+0x26>
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    0x2e9b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
jmp    1166 <getentropy+0x46>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <getentropy_urandom@plt>
cmp    $0xffffffff,%eax
jne    1166 <getentropy+0x46>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <getentropy_fallback@plt>
cmp    $0xffffffff,%eax
je     112d <getentropy+0xd>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EIO = global i32 0
@errno = global i32 0
define i32 @getentropy(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 -1, i32* %6
%7 = load i64, i64* %5
%8 = icmp ugt i64 %7, 256
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i32, i32* @EIO
store i32 %10, i32* @errno
store i32 -1, i32* %3
br label %30
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i32 @getentropy_urandom(i8* %12, i64 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %30
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = load i64, i64* %5
%22 = call i32 @getentropy_fallback(i8* %20, i64 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %30
27: ; preds = %19
%28 = load i32, i32* @EIO
store i32 %28, i32* @errno
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %30
30: ; preds = %27, %25, %17, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@EIO = global i32 0
@errno = global i32 0
define i32 @getentropy(i8* %0, i64 %1) {
%3 = icmp ugt i64 %1, 256
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = tail call i32 @getentropy_urandom(i8* %0, i64 %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @getentropy_fallback(i8* %0, i64 %1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7, %2
%11 = load i32, i32* @EIO
store i32 %11, i32* @errno
br label %12
12: ; preds = %10, %7, %4
%13 = phi i32 [ %5, %4 ], [ %8, %7 ], [ -1, %10 ]
ret i32 %13
}