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

/* Variables and functions */
int /*<<< orphan*/ EC_F_ECKEY_PUB_DECODE;
int /*<<< orphan*/ EC_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_R_DECODE_ERROR;
int /*<<< orphan*/ ECerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_EC_LIB;
int /*<<< orphan*/ EVP_PKEY_assign_EC_KEY(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_ALGOR_get0(int /*<<< orphan*/ *, int *, void **,
                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_PUBKEY_get0_param(int /*<<< orphan*/ *,
                                          unsigned char const **, int *,
                                          int /*<<< orphan*/ **,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ *eckey_type2param(int, void *);
int /*<<< orphan*/ o2i_ECPublicKey(int /*<<< orphan*/ **,
                                   unsigned char const **, int);
int eckey_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) {
  const unsigned char *p = NULL;
  void *pval;
  int ptype, pklen;
  EC_KEY *eckey = NULL;
  X509_ALGOR *palg;
  if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
    return 0;
  X509_ALGOR_get0(NULL, &ptype, &pval, palg);
  eckey = eckey_type2param(ptype, pval);
  if (!eckey) {
    ECerr(EC_F_ECKEY_PUB_DECODE, ERR_R_EC_LIB);
    return 0;
  }
  if (!o2i_ECPublicKey(&eckey, &p, pklen)) {
    ECerr(EC_F_ECKEY_PUB_DECODE, EC_R_DECODE_ERROR);
    goto ecerr;
  }
  EVP_PKEY_assign_EC_KEY(pkey, eckey);
  return 1;
ecerr:
  if (eckey)
    EC_KEY_free(eckey);
  return 0;
}


x86 assembly (clang, -O0):
<eckey_pub_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1040 <X509_PUBKEY_get0_param@plt>
cmp    $0x0,%eax
jne    11be <eckey_pub_decode+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    127a <eckey_pub_decode+0x10a>
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x2c(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1090 <X509_ALGOR_get0@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1070 <eckey_type2param@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1211 <eckey_pub_decode+0xa1>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1050 <ECerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    127a <eckey_pub_decode+0x10a>
mov    -0x30(%rbp),%edx
lea    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <o2i_ECPublicKey@plt>
cmp    $0x0,%eax
jne    1246 <eckey_pub_decode+0xd6>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
call   1050 <ECerr@plt>
jmp    125f <eckey_pub_decode+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <EVP_PKEY_assign_EC_KEY@plt>
movl   $0x1,-0x4(%rbp)
jmp    127a <eckey_pub_decode+0x10a>
cmpq   $0x0,-0x38(%rbp)
je     1273 <eckey_pub_decode+0x103>
mov    -0x38(%rbp),%rdi
call   1060 <EC_KEY_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eckey_pub_decode>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r8
mov    %rdi,%r14
movq   $0x0,0x10(%rsp)
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %edi,%edi
call   1040 <X509_PUBKEY_get0_param@plt>
test   %eax,%eax
je     123d <eckey_pub_decode+0xcd>
mov    0x18(%rsp),%rcx
xor    %ebx,%ebx
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rdx
xor    %edi,%edi
call   1090 <X509_ALGOR_get0@plt>
mov    0xc(%rsp),%edi
mov    0x20(%rsp),%rsi
call   1070 <eckey_type2param@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     11fd <eckey_pub_decode+0x8d>
mov    0x8(%rsp),%edx
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
call   1030 <o2i_ECPublicKey@plt>
test   %eax,%eax
je     1216 <eckey_pub_decode+0xa6>
mov    (%rsp),%rsi
mov    %r14,%rdi
call   1080 <EVP_PKEY_assign_EC_KEY@plt>
mov    $0x1,%ebx
jmp    123d <eckey_pub_decode+0xcd>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
call   1050 <ECerr@plt>
jmp    123d <eckey_pub_decode+0xcd>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
call   1050 <ECerr@plt>
mov    (%rsp),%rdi
xor    %ebx,%ebx
test   %rdi,%rdi
je     123d <eckey_pub_decode+0xcd>
call   1060 <EC_KEY_free@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EC_F_ECKEY_PUB_DECODE = global i32 0
@ERR_R_EC_LIB = global i32 0
@EC_R_DECODE_ERROR = global i32 0
define i32 @eckey_pub_decode(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* null, i8** %6
store i32* null, i32** %10
%12 = load i32*, i32** %5
%13 = call i32 @X509_PUBKEY_get0_param(i32* null, i8** %6, i32* %9, i32** %11, i32* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 0, i32* %3
br label %47
16: ; preds = %2
%17 = load i32*, i32** %11
%18 = call i32 @X509_ALGOR_get0(i32* null, i32* %8, i8** %7, i32* %17)
%19 = load i32, i32* %8
%20 = load i8*, i8** %7
%21 = call i32* @eckey_type2param(i32 %19, i8* %20)
store i32* %21, i32** %10
%22 = load i32*, i32** %10
%23 = icmp ne i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %16
%25 = load i32, i32* @EC_F_ECKEY_PUB_DECODE
%26 = load i32, i32* @ERR_R_EC_LIB
%27 = call i32 @ECerr(i32 %25, i32 %26)
store i32 0, i32* %3
br label %47
28: ; preds = %16
%29 = load i32, i32* %9
%30 = call i32 @o2i_ECPublicKey(i32** %10, i8** %6, i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i32, i32* @EC_F_ECKEY_PUB_DECODE
%34 = load i32, i32* @EC_R_DECODE_ERROR
%35 = call i32 @ECerr(i32 %33, i32 %34)
br label %40
36: ; preds = %28
%37 = load i32*, i32** %4
%38 = load i32*, i32** %10
%39 = call i32 @EVP_PKEY_assign_EC_KEY(i32* %37, i32* %38)
store i32 1, i32* %3
br label %47
40: ; preds = %32
%41 = load i32*, i32** %10
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32*, i32** %10
%45 = call i32 @EC_KEY_free(i32* %44)
br label %46
46: ; preds = %43, %40
store i32 0, i32* %3
br label %47
47: ; preds = %46, %36, %24, %15
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@EC_F_ECKEY_PUB_DECODE = global i32 0
@ERR_R_EC_LIB = global i32 0
@EC_R_DECODE_ERROR = global i32 0
define i32 @eckey_pub_decode(i32* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%10 = bitcast i8** %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32** %7 to i8*
%14 = bitcast i32** %8 to i8*
%15 = call i32 @X509_PUBKEY_get0_param(i32* null, i8** %3, i32* %6, i32** %8, i32* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %43, label %17
17: ; preds = %2
%18 = load i32*, i32** %8
%19 = call i32 @X509_ALGOR_get0(i32* null, i32* %5, i8** %4, i32* %18)
%20 = load i32, i32* %5
%21 = load i8*, i8** %4
%22 = call i32* @eckey_type2param(i32 %20, i8* %21)
store i32* %22, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* @EC_F_ECKEY_PUB_DECODE
%26 = load i32, i32* @ERR_R_EC_LIB
%27 = call i32 @ECerr(i32 %25, i32 %26)
br label %43
28: ; preds = %17
%29 = load i32, i32* %6
%30 = call i32 @o2i_ECPublicKey(i32** %7, i8** %3, i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i32, i32* @EC_F_ECKEY_PUB_DECODE
%34 = load i32, i32* @EC_R_DECODE_ERROR
%35 = call i32 @ECerr(i32 %33, i32 %34)
%36 = load i32*, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %43, label %41
38: ; preds = %28
%39 = load i32*, i32** %7
%40 = call i32 @EVP_PKEY_assign_EC_KEY(i32* %0, i32* %39)
br label %43
41: ; preds = %32
%42 = call i32 @EC_KEY_free(i32* %36)
br label %43
43: ; preds = %32, %41, %2, %38, %24
%44 = phi i32 [ 1, %38 ], [ 0, %24 ], [ 0, %2 ], [ 0, %41 ], [ 0, %32 ]
ret i32 %44
}