#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int (*bytes)(unsigned char *, int);
};
typedef TYPE_1__ RAND_METHOD;

/* Variables and functions */
TYPE_1__ *RAND_get_rand_method();
int stub1(unsigned char *, int);
int RAND_bytes(unsigned char *buf, int num) {
  const RAND_METHOD *meth = RAND_get_rand_method();
  if (meth && meth->bytes)
    return meth->bytes(buf, num);
  return (-1);
}


x86 assembly (clang, -O0):
<RAND_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1030 <RAND_get_rand_method@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     115b <RAND_bytes+0x4b>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     115b <RAND_bytes+0x4b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    1162 <RAND_bytes+0x52>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RAND_bytes>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <RAND_get_rand_method@plt>
test   %rax,%rax
je     1139 <RAND_bytes+0x29>
mov    (%rax),%rax
test   %rax,%rax
je     1139 <RAND_bytes+0x29>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    *%rax
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 (i8*, i32)* }
define i32 @RAND_bytes(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.TYPE_3__*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = call %struct.TYPE_3__* (...) @RAND_get_rand_method()
store %struct.TYPE_3__* %7, %struct.TYPE_3__** %6
%8 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%9 = icmp ne %struct.TYPE_3__* %8, null
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i32 (i8*, i32)*, i32 (i8*, i32)** %12
%14 = icmp ne i32 (i8*, i32)* %13, null
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%18 = load i32 (i8*, i32)*, i32 (i8*, i32)** %17
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = call i32 %18(i8* %19, i32 %20)
store i32 %21, i32* %3
br label %23
22: ; preds = %10, %2
store i32 -1, i32* %3
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 (i8*, i32)* }
define i32 @RAND_bytes(i8* %0, i32 %1) {
%3 = tail call %struct.TYPE_3__* (...) @RAND_get_rand_method()
%4 = icmp eq %struct.TYPE_3__* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%7 = load i32 (i8*, i32)*, i32 (i8*, i32)** %6
%8 = icmp eq i32 (i8*, i32)* %7, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 %7(i8* %0, i32 %1)
br label %11
11: ; preds = %2, %5, %9
%12 = phi i32 [ %10, %9 ], [ -1, %5 ], [ -1, %2 ]
ret i32 %12
}