#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*/ ASN1_F_I2D_RSA_PUBKEY;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ EVP_PKEY_set1_RSA(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int i2d_PUBKEY(int /*<<< orphan*/ *, unsigned char **);
int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) {
  EVP_PKEY *pktmp;
  int ret;
  if (!a)
    return 0;
  pktmp = EVP_PKEY_new();
  if (!pktmp) {
    ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
    return 0;
  }
  EVP_PKEY_set1_RSA(pktmp, a);
  ret = i2d_PUBKEY(pktmp, pp);
  EVP_PKEY_free(pktmp);
  return ret;
}


x86 assembly (clang, -O0):
<i2d_RSA_PUBKEY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <i2d_RSA_PUBKEY+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11dc <i2d_RSA_PUBKEY+0x8c>
mov    $0x0,%al
call   1050 <EVP_PKEY_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b0 <i2d_RSA_PUBKEY+0x60>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11dc <i2d_RSA_PUBKEY+0x8c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <EVP_PKEY_set1_RSA@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <i2d_PUBKEY@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <EVP_PKEY_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2d_RSA_PUBKEY>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ac <i2d_RSA_PUBKEY+0x5c>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <EVP_PKEY_new@plt>
test   %rax,%rax
je     1195 <i2d_RSA_PUBKEY+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <EVP_PKEY_set1_RSA@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <i2d_PUBKEY@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <EVP_PKEY_free@plt>
mov    %ebp,%eax
jmp    11ae <i2d_RSA_PUBKEY+0x5e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@ASN1_F_I2D_RSA_PUBKEY = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @i2d_RSA_PUBKEY(i32* %0, i8** %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i32* (...) @EVP_PKEY_new()
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @ASN1_F_I2D_RSA_PUBKEY
%9 = load i32, i32* @ERR_R_MALLOC_FAILURE
%10 = tail call i32 @ASN1err(i32 %8, i32 %9)
br label %15
11: ; preds = %4
%12 = tail call i32 @EVP_PKEY_set1_RSA(i32* %5, i32* %0)
%13 = tail call i32 @i2d_PUBKEY(i32* %5, i8** %1)
%14 = tail call i32 @EVP_PKEY_free(i32* %5)
br label %15
15: ; preds = %2, %11, %7
%16 = phi i32 [ %13, %11 ], [ 0, %7 ], [ 0, %2 ]
ret i32 %16
}