#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 */
scalar_t__ ERR_GET_LIB(unsigned long);
scalar_t__ ERR_GET_REASON(unsigned long);
scalar_t__ ERR_LIB_RAND;
int /*<<< orphan*/ ERR_clear_error();
unsigned long ERR_peek_error();
scalar_t__ RAND_R_PRNG_NOT_SEEDED;
int RAND_bytes(unsigned char *, int);
int ssleay_rand_pseudo_bytes(unsigned char *buf, int num) {
  int ret;
  unsigned long err;
  ret = RAND_bytes(buf, num);
  if (ret == 0) {
    err = ERR_peek_error();
    if (ERR_GET_LIB(err) == ERR_LIB_RAND &&
        ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED)
      ERR_clear_error();
  }
  return (ret);
}


x86 assembly (clang, -O0):
<ssleay_rand_pseudo_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <RAND_bytes@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11c1 <ssleay_rand_pseudo_bytes+0x71>
mov    $0x0,%al
call   1030 <ERR_peek_error@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ERR_GET_LIB@plt>
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
jne    11bc <ssleay_rand_pseudo_bytes+0x6c>
mov    -0x18(%rbp),%rdi
call   1070 <ERR_GET_REASON@plt>
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
jne    11bc <ssleay_rand_pseudo_bytes+0x6c>
mov    $0x0,%al
call   1050 <ERR_clear_error@plt>
jmp    11c1 <ssleay_rand_pseudo_bytes+0x71>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssleay_rand_pseudo_bytes>:
push   %r14
push   %rbx
push   %rax
call   1040 <RAND_bytes@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1198 <ssleay_rand_pseudo_bytes+0x48>
xor    %eax,%eax
call   1030 <ERR_peek_error@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <ERR_GET_LIB@plt>
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <ssleay_rand_pseudo_bytes+0x48>
mov    %r14,%rdi
call   1070 <ERR_GET_REASON@plt>
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <ssleay_rand_pseudo_bytes+0x48>
xor    %eax,%eax
call   1050 <ERR_clear_error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ERR_LIB_RAND = global i64 0
@RAND_R_PRNG_NOT_SEEDED = global i64 0
define i32 @ssleay_rand_pseudo_bytes(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = call i32 @RAND_bytes(i8* %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %2
%13 = call i64 (...) @ERR_peek_error()
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = call i64 @ERR_GET_LIB(i64 %14)
%16 = load i64, i64* @ERR_LIB_RAND
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %12
%19 = load i64, i64* %6
%20 = call i64 @ERR_GET_REASON(i64 %19)
%21 = load i64, i64* @RAND_R_PRNG_NOT_SEEDED
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (...) @ERR_clear_error()
br label %25
25: ; preds = %23, %18, %12
br label %26
26: ; preds = %25, %2
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@ERR_LIB_RAND = global i64 0
@RAND_R_PRNG_NOT_SEEDED = global i64 0
define i32 @ssleay_rand_pseudo_bytes(i8* %0, i32 %1) {
%3 = tail call i32 @RAND_bytes(i8* %0, i32 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = tail call i64 (...) @ERR_peek_error()
%7 = tail call i64 @ERR_GET_LIB(i64 %6)
%8 = load i64, i64* @ERR_LIB_RAND
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = tail call i64 @ERR_GET_REASON(i64 %6)
%12 = load i64, i64* @RAND_R_PRNG_NOT_SEEDED
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 (...) @ERR_clear_error()
br label %16
16: ; preds = %5, %10, %14, %2
ret i32 %3
}