#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*/ ASN1error(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) {
    ASN1error(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    11d2 <i2d_EC_PUBKEY+0x82>
mov    $0x0,%al
call   1040 <EVP_PKEY_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a6 <i2d_EC_PUBKEY+0x56>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1070 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <i2d_EC_PUBKEY+0x82>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <EVP_PKEY_set1_EC_KEY@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <i2d_PUBKEY@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <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     11a3 <i2d_EC_PUBKEY+0x53>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <EVP_PKEY_new@plt>
test   %rax,%rax
je     1195 <i2d_EC_PUBKEY+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <EVP_PKEY_set1_EC_KEY@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <i2d_PUBKEY@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <EVP_PKEY_free@plt>
mov    %ebp,%eax
jmp    11a5 <i2d_EC_PUBKEY+0x55>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <ASN1error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@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 %27
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 %17
14: ; preds = %11
%15 = load i32, i32* @ERR_R_MALLOC_FAILURE
%16 = call i32 @ASN1error(i32 %15)
store i32 0, i32* %3
br label %27
17: ; preds = %11
%18 = load i32*, i32** %6
%19 = load i32*, i32** %4
%20 = call i32 @EVP_PKEY_set1_EC_KEY(i32* %18, i32* %19)
%21 = load i32*, i32** %6
%22 = load i8**, i8*** %5
%23 = call i32 @i2d_PUBKEY(i32* %21, i8** %22)
store i32 %23, i32* %7
%24 = load i32*, i32** %6
%25 = call i32 @EVP_PKEY_free(i32* %24)
%26 = load i32, i32* %7
store i32 %26, i32* %3
br label %27
27: ; preds = %17, %14, %10
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@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 %14, label %4
4: ; preds = %2
%5 = tail call i32* (...) @EVP_PKEY_new()
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @ERR_R_MALLOC_FAILURE
%9 = tail call i32 @ASN1error(i32 %8)
br label %14
10: ; preds = %4
%11 = tail call i32 @EVP_PKEY_set1_EC_KEY(i32* %5, i32* %0)
%12 = tail call i32 @i2d_PUBKEY(i32* %5, i8** %1)
%13 = tail call i32 @EVP_PKEY_free(i32* %5)
br label %14
14: ; preds = %2, %10, %7
%15 = phi i32 [ 0, %7 ], [ %12, %10 ], [ 0, %2 ]
ret i32 %15
}