#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*/ X509_PUBKEY;
typedef int /*<<< orphan*/ EVP_PKEY;

/* Variables and functions */
int /*<<< orphan*/ X509_PUBKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_PUBKEY_set(int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int i2d_X509_PUBKEY(int /*<<< orphan*/ *, unsigned char **);
int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) {
  X509_PUBKEY *xpk = NULL;
  int ret;
  if (!a)
    return 0;
  if (!X509_PUBKEY_set(&xpk, a))
    return 0;
  ret = i2d_X509_PUBKEY(xpk, pp);
  X509_PUBKEY_free(xpk);
  return ret;
}


x86 assembly (clang, -O0):
<i2d_PUBKEY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115f <i2d_PUBKEY+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <i2d_PUBKEY+0x70>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1050 <X509_PUBKEY_set@plt>
cmp    $0x0,%eax
jne    1181 <i2d_PUBKEY+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <i2d_PUBKEY+0x70>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <i2d_X509_PUBKEY@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <X509_PUBKEY_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_PUBKEY>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
xor    %ebx,%ebx
test   %rdi,%rdi
je     116c <i2d_PUBKEY+0x3c>
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rdi
call   1050 <X509_PUBKEY_set@plt>
test   %eax,%eax
je     116c <i2d_PUBKEY+0x3c>
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1030 <i2d_X509_PUBKEY@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1040 <X509_PUBKEY_free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @i2d_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
store i32* null, i32** %6
%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 %23
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = call i32 @X509_PUBKEY_set(i32** %6, i32* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11
store i32 0, i32* %3
br label %23
16: ; preds = %11
%17 = load i32*, i32** %6
%18 = load i8**, i8*** %5
%19 = call i32 @i2d_X509_PUBKEY(i32* %17, i8** %18)
store i32 %19, i32* %7
%20 = load i32*, i32** %6
%21 = call i32 @X509_PUBKEY_free(i32* %20)
%22 = load i32, i32* %7
store i32 %22, i32* %3
br label %23
23: ; preds = %16, %15, %10
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @i2d_PUBKEY(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = icmp eq i32* %0, null
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = call i32 @X509_PUBKEY_set(i32** %3, i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = load i32*, i32** %3
%11 = call i32 @i2d_X509_PUBKEY(i32* %10, i8** %1)
%12 = load i32*, i32** %3
%13 = call i32 @X509_PUBKEY_free(i32* %12)
br label %14
14: ; preds = %6, %2, %9
%15 = phi i32 [ %11, %9 ], [ 0, %2 ], [ 0, %6 ]
ret i32 %15
}