#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*/ EVP_PKEY;

/* Variables and functions */
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_get1_RSA(int /*<<< orphan*/ *);
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *d2i_PUBKEY(int /*<<< orphan*/ *, unsigned char const **,
                               long);
RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length) {
  EVP_PKEY *pkey;
  RSA *key;
  const unsigned char *q;
  q = *pp;
  pkey = d2i_PUBKEY(NULL, &q, length);
  if (!pkey)
    return NULL;
  key = EVP_PKEY_get1_RSA(pkey);
  EVP_PKEY_free(pkey);
  if (!key)
    return NULL;
  *pp = q;
  if (a) {
    RSA_free(*a);
    *a = key;
  }
  return key;
}


x86 assembly (clang, -O0):
<d2i_RSA_PUBKEY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x38(%rbp),%rsi
call   1050 <d2i_PUBKEY@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118c <d2i_RSA_PUBKEY+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    11ef <d2i_RSA_PUBKEY+0xaf>
mov    -0x28(%rbp),%rdi
call   1060 <EVP_PKEY_get1_RSA@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <EVP_PKEY_free@plt>
cmpq   $0x0,-0x30(%rbp)
jne    11ba <d2i_RSA_PUBKEY+0x7a>
movq   $0x0,-0x8(%rbp)
jmp    11ef <d2i_RSA_PUBKEY+0xaf>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11e7 <d2i_RSA_PUBKEY+0xa7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <RSA_free@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2i_RSA_PUBKEY>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%rax
mov    %rax,(%rsp)
xor    %r12d,%r12d
mov    %rsp,%rsi
xor    %edi,%edi
call   1050 <d2i_PUBKEY@plt>
test   %rax,%rax
je     119e <d2i_RSA_PUBKEY+0x5e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <EVP_PKEY_get1_RSA@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <EVP_PKEY_free@plt>
test   %r12,%r12
je     119b <d2i_RSA_PUBKEY+0x5b>
mov    (%rsp),%rax
mov    %rax,(%r15)
test   %r14,%r14
je     119e <d2i_RSA_PUBKEY+0x5e>
mov    (%r14),%rdi
call   1030 <RSA_free@plt>
mov    %r12,(%r14)
jmp    119e <d2i_RSA_PUBKEY+0x5e>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @d2i_RSA_PUBKEY(i32** %0, i8** %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
store i32** %0, i32*** %5
store i8** %1, i8*** %6
store i64 %2, i64* %7
%11 = load i8**, i8*** %6
%12 = load i8*, i8** %11
store i8* %12, i8** %10
%13 = load i64, i64* %7
%14 = call i32* @d2i_PUBKEY(i32* null, i8** %10, i64 %13)
store i32* %14, i32** %8
%15 = load i32*, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %3
store i32* null, i32** %4
br label %39
18: ; preds = %3
%19 = load i32*, i32** %8
%20 = call i32* @EVP_PKEY_get1_RSA(i32* %19)
store i32* %20, i32** %9
%21 = load i32*, i32** %8
%22 = call i32 @EVP_PKEY_free(i32* %21)
%23 = load i32*, i32** %9
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %18
store i32* null, i32** %4
br label %39
26: ; preds = %18
%27 = load i8*, i8** %10
%28 = load i8**, i8*** %6
store i8* %27, i8** %28
%29 = load i32**, i32*** %5
%30 = icmp ne i32** %29, null
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i32**, i32*** %5
%33 = load i32*, i32** %32
%34 = call i32 @RSA_free(i32* %33)
%35 = load i32*, i32** %9
%36 = load i32**, i32*** %5
store i32* %35, i32** %36
br label %37
37: ; preds = %31, %26
%38 = load i32*, i32** %9
store i32* %38, i32** %4
br label %39
39: ; preds = %37, %25, %17
%40 = load i32*, i32** %4
ret i32* %40
}

LLVM IR (-O2):
define i32* @d2i_RSA_PUBKEY(i32** %0, i8** nocapture %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = load i8*, i8** %1
store i8* %6, i8** %4
%7 = call i32* @d2i_PUBKEY(i32* null, i8** %4, i64 %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %19, label %9
9: ; preds = %3
%10 = call i32* @EVP_PKEY_get1_RSA(i32* %7)
%11 = call i32 @EVP_PKEY_free(i32* %7)
%12 = icmp eq i32* %10, null
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = load i8*, i8** %4
store i8* %14, i8** %1
%15 = icmp eq i32** %0, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32*, i32** %0
%18 = call i32 @RSA_free(i32* %17)
store i32* %10, i32** %0
br label %19
19: ; preds = %13, %16, %9, %3
%20 = phi i32* [ null, %3 ], [ null, %9 ], [ %10, %16 ], [ %10, %13 ]
ret i32* %20
}