#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*/ *);
RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa) {
  RSA *rtmp;
  if (!key)
    return NULL;
  rtmp = EVP_PKEY_get1_RSA(key);
  EVP_PKEY_free(key);
  if (!rtmp)
    return NULL;
  if (rsa) {
    RSA_free(*rsa);
    *rsa = rtmp;
  }
  return rtmp;
}


x86 assembly (clang, -O0):
<pkey_get_rsa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <pkey_get_rsa+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <pkey_get_rsa+0x80>
mov    -0x10(%rbp),%rdi
call   1050 <EVP_PKEY_get1_RSA@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <EVP_PKEY_free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1186 <pkey_get_rsa+0x56>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <pkey_get_rsa+0x80>
cmpq   $0x0,-0x18(%rbp)
je     11a8 <pkey_get_rsa+0x78>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <RSA_free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkey_get_rsa>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1167 <pkey_get_rsa+0x37>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <EVP_PKEY_get1_RSA@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <EVP_PKEY_free@plt>
test   %r15,%r15
je     1167 <pkey_get_rsa+0x37>
test   %r14,%r14
je     116a <pkey_get_rsa+0x3a>
mov    (%r14),%rdi
call   1030 <RSA_free@plt>
mov    %r15,(%r14)
jmp    116a <pkey_get_rsa+0x3a>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32* @pkey_get_rsa(i32* %0, i32** %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = tail call i32* @EVP_PKEY_get1_RSA(i32* %0)
%6 = tail call i32 @EVP_PKEY_free(i32* %0)
%7 = icmp eq i32* %5, null
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = icmp eq i32** %1, null
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = load i32*, i32** %1
%12 = tail call i32 @RSA_free(i32* %11)
store i32* %5, i32** %1
br label %13
13: ; preds = %8, %10, %4, %2
%14 = phi i32* [ null, %2 ], [ null, %4 ], [ %5, %10 ], [ %5, %8 ]
ret i32* %14
}