#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*/ *);
int /*<<< orphan*/ printf(char *);
RSA *createRSA(unsigned char *key, int public) {
  RSA *rsa = NULL;
  BIO *keybio;
  keybio = BIO_new_mem_buf(key, -1);
  if (keybio == NULL) {
    printf("Failed to create key BIO");
    return 0;
  }
  if (public) {
    rsa = PEM_read_bio_RSA_PUBKEY(keybio, &rsa, NULL, NULL);
  } else {
    rsa = PEM_read_bio_RSAPrivateKey(keybio, &rsa, NULL, NULL);
  }
  if (rsa == NULL) {
    printf("Failed to create RSA");
  }
  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   1050 <BIO_new_mem_buf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118d <createRSA+0x4d>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11eb <createRSA+0xab>
cmpl   $0x0,-0x14(%rbp)
je     11b4 <createRSA+0x74>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1060 <PEM_read_bio_RSA_PUBKEY@plt>
mov    %rax,-0x20(%rbp)
jmp    11cc <createRSA+0x8c>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <PEM_read_bio_RSAPrivateKey@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e3 <createRSA+0xa3>
lea    0xe3b(%rip),%rdi
call   1030 <printf@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   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movq   $0x0,0x8(%rsp)
mov    $0xffffffff,%esi
call   1050 <BIO_new_mem_buf@plt>
test   %rax,%rax
je     1176 <createRSA+0x36>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
test   %ebx,%ebx
je     1186 <createRSA+0x46>
call   1060 <PEM_read_bio_RSA_PUBKEY@plt>
jmp    118b <createRSA+0x4b>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11a6 <createRSA+0x66>
call   1040 <PEM_read_bio_RSAPrivateKey@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
jne    11a6 <createRSA+0x66>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Failed to create key BIO\00"
@.str.1 = [21 x i8] c"Failed to create RSA\00"
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 %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %3
br label %30
14: ; preds = %2
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32*, i32** %7
%19 = call i32* @PEM_read_bio_RSA_PUBKEY(i32* %18, i32** %6, i32* null, i32* null)
store i32* %19, i32** %6
br label %23
20: ; preds = %14
%21 = load i32*, i32** %7
%22 = call i32* @PEM_read_bio_RSAPrivateKey(i32* %21, i32** %6, i32* null, i32* null)
store i32* %22, i32** %6
br label %23
23: ; preds = %20, %17
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = load i32*, i32** %6
store i32* %29, i32** %3
br label %30
30: ; preds = %28, %12
%31 = load i32*, i32** %3
ret i32* %31
}

LLVM IR (-O2):
@.str = [25 x i8] c"Failed to create key BIO\00"
@.str.1 = [21 x i8] c"Failed to create RSA\00"
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 %7, label %9
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %21
9: ; preds = %2
%10 = icmp eq i32 %1, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = call i32* @PEM_read_bio_RSA_PUBKEY(i32* %5, i32** %3, i32* null, i32* null)
br label %15
13: ; preds = %9
%14 = call i32* @PEM_read_bio_RSAPrivateKey(i32* %5, i32** %3, i32* null, i32* null)
br label %15
15: ; preds = %13, %11
%16 = phi i32* [ %14, %13 ], [ %12, %11 ]
store i32* %16, i32** %3
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32*, i32** %3
br label %21
21: ; preds = %15, %18, %7
%22 = phi i32* [ null, %7 ], [ %20, %18 ], [ %16, %15 ]
ret i32* %22
}