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

/* Variables and functions */
int /*<<< orphan*/ *BIO_new_mem_buf(unsigned char *, int);
int /*<<< orphan*/ *PEM_read_bio_RSAPrivateKey(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ **,
                                               int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_bio_RSA_PUBKEY(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ **,
                                            int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *);
RSA *createRSA(unsigned char *key, int pub) {
  RSA *rsa = NULL;
  BIO *keybio;
  keybio = BIO_new_mem_buf(key, -1);
  if (keybio == NULL)
    return 0;
  if (pub)
    rsa = PEM_read_bio_RSA_PUBKEY(keybio, &rsa, NULL, NULL);
  else
    rsa = PEM_read_bio_RSAPrivateKey(keybio, &rsa, NULL, NULL);
  return rsa;
}


x86 assembly (clang, -O0):
<createRSA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xffffffff,%esi
call   1040 <BIO_new_mem_buf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1171 <createRSA+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11b8 <createRSA+0x88>
cmpl   $0x0,-0x14(%rbp)
je     1198 <createRSA+0x68>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <PEM_read_bio_RSA_PUBKEY@plt>
mov    %rax,-0x20(%rbp)
jmp    11b0 <createRSA+0x80>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <PEM_read_bio_RSAPrivateKey@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createRSA>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movq   $0x0,0x8(%rsp)
mov    $0xffffffff,%esi
call   1040 <BIO_new_mem_buf@plt>
test   %rax,%rax
je     1166 <createRSA+0x36>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
test   %ebx,%ebx
je     116a <createRSA+0x3a>
call   1050 <PEM_read_bio_RSA_PUBKEY@plt>
jmp    116f <createRSA+0x3f>
xor    %eax,%eax
jmp    116f <createRSA+0x3f>
call   1030 <PEM_read_bio_RSAPrivateKey@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32* @createRSA(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* null, i32** %6
%8 = load i8*, i8** %4
%9 = call i32* @BIO_new_mem_buf(i8* %8, i32 -1)
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32* null, i32** %3
br label %24
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32*, i32** %7
%18 = call i32* @PEM_read_bio_RSA_PUBKEY(i32* %17, i32** %6, i32* null, i32* null)
store i32* %18, i32** %6
br label %22
19: ; preds = %13
%20 = load i32*, i32** %7
%21 = call i32* @PEM_read_bio_RSAPrivateKey(i32* %20, i32** %6, i32* null, i32* null)
store i32* %21, i32** %6
br label %22
22: ; preds = %19, %16
%23 = load i32*, i32** %6
store i32* %23, i32** %3
br label %24
24: ; preds = %22, %12
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
define i32* @createRSA(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 -1)
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 0
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = call i32* @PEM_read_bio_RSA_PUBKEY(i32* %5, i32** %3, i32* null, i32* null)
br label %13
11: ; preds = %7
%12 = call i32* @PEM_read_bio_RSAPrivateKey(i32* %5, i32** %3, i32* null, i32* null)
br label %13
13: ; preds = %9, %11, %2
%14 = phi i32* [ null, %2 ], [ %12, %11 ], [ %10, %9 ]
ret i32* %14
}