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

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_I2D_EC_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_EC_KEY(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int i2d_PUBKEY(int /*<<< orphan*/ *, unsigned char **);
int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) {
  EVP_PKEY *pktmp;
  int ret;
  if (!a)
    return (0);
  if ((pktmp = EVP_PKEY_new()) == NULL) {
    ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE);
    return (0);
  }
  EVP_PKEY_set1_EC_KEY(pktmp, a);
  ret = i2d_PUBKEY(pktmp, pp);
  EVP_PKEY_free(pktmp);
  return (ret);
}


x86 assembly (clang, -O0):
<i2d_EC_PUBKEY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <i2d_EC_PUBKEY+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11db <i2d_EC_PUBKEY+0x8b>
mov    $0x0,%al
call   1050 <EVP_PKEY_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11af <i2d_EC_PUBKEY+0x5f>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11db <i2d_EC_PUBKEY+0x8b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <EVP_PKEY_set1_EC_KEY@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_EC_PUBKEY>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ac <i2d_EC_PUBKEY+0x5c>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <EVP_PKEY_new@plt>
test   %rax,%rax
je     1195 <i2d_EC_PUBKEY+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <EVP_PKEY_set1_EC_KEY@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_EC_PUBKEY+0x5e>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x2e43(%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_EC_PUBKEY = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @i2d_EC_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 %28
11: ; preds = %2
%12 = call i32* (...) @EVP_PKEY_new()
store i32* %12, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @ASN1_F_I2D_EC_PUBKEY
%16 = load i32, i32* @ERR_R_MALLOC_FAILURE
%17 = call i32 @ASN1err(i32 %15, i32 %16)
store i32 0, i32* %3
br label %28
18: ; preds = %11
%19 = load i32*, i32** %6
%20 = load i32*, i32** %4
%21 = call i32 @EVP_PKEY_set1_EC_KEY(i32* %19, i32* %20)
%22 = load i32*, i32** %6
%23 = load i8**, i8*** %5
%24 = call i32 @i2d_PUBKEY(i32* %22, i8** %23)
store i32 %24, i32* %7
%25 = load i32*, i32** %6
%26 = call i32 @EVP_PKEY_free(i32* %25)
%27 = load i32, i32* %7
store i32 %27, i32* %3
br label %28
28: ; preds = %18, %14, %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@ASN1_F_I2D_EC_PUBKEY = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @i2d_EC_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_EC_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_EC_KEY(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 [ 0, %7 ], [ %13, %11 ], [ 0, %2 ]
ret i32 %16
}