#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int const ERR_LIB_NONE;
int /*<<< orphan*/ ERR_error_string_n(unsigned long const, char *, int);
unsigned long ERR_get_error();
size_t INT_MAX;
int RAND_bytes(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ keygen_cleanBuffer(int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ stderr;
int getRandomBytes(uint8_t *buffer, size_t length) {
  assert(length < INT_MAX);
  const int rtn = RAND_bytes(buffer, (int)length);
  if (rtn != ERR_LIB_NONE) {
    const unsigned long error = ERR_get_error();
    char errBuffer[128 + 1];
    ERR_error_string_n(error, errBuffer, 128);
    fprintf(stderr, "%s", errBuffer);
    keygen_cleanBuffer(buffer, length);
  }
  return rtn;
}


x86 assembly (clang, -O0):
<getRandomBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%esi
call   1040 <RAND_bytes@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
je     11fb <getRandomBytes+0x9b>
mov    $0x0,%al
call   1080 <ERR_get_error@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
call   1050 <ERR_error_string_n@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    -0xb0(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <keygen_cleanBuffer@plt>
mov    -0x14(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRandomBytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e6e(%rip),%rax
xor    %edi,%edi
cmp    %rsi,(%rax)
seta   %dil
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <RAND_bytes@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11d5 <getRandomBytes+0x75>
xor    %eax,%eax
call   1080 <ERR_get_error@plt>
mov    %rsp,%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x80,%edx
call   1050 <ERR_error_string_n@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <keygen_cleanBuffer@plt>
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
@ERR_LIB_NONE = constant i32 0
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @getRandomBytes(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca [129 x i8]
store i32* %0, i32** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = load i64, i64* @INT_MAX
%10 = icmp ult i64 %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32*, i32** %3
%14 = load i64, i64* %4
%15 = trunc i64 %14 to i32
%16 = call i32 @RAND_bytes(i32* %13, i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = load i32, i32* @ERR_LIB_NONE
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %2
%21 = call i64 (...) @ERR_get_error()
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 0
%24 = call i32 @ERR_error_string_n(i64 %22, i8* %23, i32 128)
%25 = load i32, i32* @stderr
%26 = getelementptr inbounds [129 x i8], [129 x i8]* %7, i64 0, i64 0
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i32*, i32** %3
%29 = load i64, i64* %4
%30 = call i32 @keygen_cleanBuffer(i32* %28, i64 %29)
br label %31
31: ; preds = %20, %2
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@INT_MAX = global i64 0
@ERR_LIB_NONE = constant i32 0
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @getRandomBytes(i32* %0, i64 %1) {
%3 = alloca [129 x i8]
%4 = load i64, i64* @INT_MAX
%5 = icmp ugt i64 %4, %1
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = trunc i64 %1 to i32
%9 = tail call i32 @RAND_bytes(i32* %0, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = tail call i64 (...) @ERR_get_error()
%13 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%14 = call i32 @ERR_error_string_n(i64 %12, i8* %13, i32 128)
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
%17 = call i32 @keygen_cleanBuffer(i32* %0, i64 %1)
br label %18
18: ; preds = %11, %2
ret i32 %9
}