#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_free_all(int /*<<< orphan*/ *);
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 public) {
  RSA *rsa = NULL;
  BIO *keybio;
  keybio = BIO_new_mem_buf(key, -1);
  if (keybio == NULL) {
    return NULL;
  }
  if (public) {
    rsa = PEM_read_bio_RSA_PUBKEY(keybio, &rsa, NULL, NULL);
  } else {
    rsa = PEM_read_bio_RSAPrivateKey(keybio, &rsa, NULL, NULL);
  }
  BIO_free_all(keybio);
  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    1181 <createRSA+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <createRSA+0x91>
cmpl   $0x0,-0x14(%rbp)
je     11a8 <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    11c0 <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    -0x28(%rbp),%rdi
call   1060 <BIO_free_all@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createRSA>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
movq   $0x0,(%rsp)
mov    $0xffffffff,%esi
call   1040 <BIO_new_mem_buf@plt>
test   %rax,%rax
je     1174 <createRSA+0x34>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
test   %ebp,%ebp
je     1178 <createRSA+0x38>
call   1050 <PEM_read_bio_RSA_PUBKEY@plt>
jmp    117d <createRSA+0x3d>
xor    %eax,%eax
jmp    118d <createRSA+0x4d>
call   1030 <PEM_read_bio_RSAPrivateKey@plt>
mov    %rax,(%rsp)
mov    %rbx,%rdi
call   1060 <BIO_free_all@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 %26
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** %7
%24 = call i32 @BIO_free_all(i32* %23)
%25 = load i32*, i32** %6
store i32* %25, i32** %3
br label %26
26: ; preds = %22, %12
%27 = load i32*, i32** %3
ret i32* %27
}

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 %17, 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 = %11, %9
%14 = phi i32* [ %12, %11 ], [ %10, %9 ]
store i32* %14, i32** %3
%15 = call i32 @BIO_free_all(i32* %5)
%16 = load i32*, i32** %3
br label %17
17: ; preds = %2, %13
%18 = phi i32* [ %16, %13 ], [ null, %2 ]
ret i32* %18
}