#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_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_R_DECODE_ERROR;
int /*<<< orphan*/ ECerror(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) {
    ECerror(ERR_R_EC_LIB);
    return 0;
  }
  if (!o2i_ECPublicKey(&eckey, &p, pklen)) {
    ECerror(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   1050 <X509_PUBKEY_get0_param@plt>
cmp    $0x0,%eax
jne    11be <eckey_pub_decode+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1268 <eckey_pub_decode+0xf8>
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    1208 <eckey_pub_decode+0x98>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1040 <ECerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1268 <eckey_pub_decode+0xf8>
mov    -0x30(%rbp),%edx
lea    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <o2i_ECPublicKey@plt>
cmp    $0x0,%eax
jne    1234 <eckey_pub_decode+0xc4>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1040 <ECerror@plt>
jmp    124d <eckey_pub_decode+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <EVP_PKEY_assign_EC_KEY@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <eckey_pub_decode+0xf8>
cmpq   $0x0,-0x38(%rbp)
je     1261 <eckey_pub_decode+0xf1>
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   1050 <X509_PUBKEY_get0_param@plt>
test   %eax,%eax
je     122b <eckey_pub_decode+0xbb>
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     120d <eckey_pub_decode+0x9d>
mov    (%rsp),%rsi
mov    %r14,%rdi
call   1080 <EVP_PKEY_assign_EC_KEY@plt>
mov    $0x1,%ebx
jmp    122b <eckey_pub_decode+0xbb>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1040 <ECerror@plt>
jmp    122b <eckey_pub_decode+0xbb>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1040 <ECerror@plt>
mov    (%rsp),%rdi
xor    %ebx,%ebx
test   %rdi,%rdi
je     122b <eckey_pub_decode+0xbb>
call   1060 <EC_KEY_free@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@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 %45
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 %27, label %24
24: ; preds = %16
%25 = load i32, i32* @ERR_R_EC_LIB
%26 = call i32 @ECerror(i32 %25)
store i32 0, i32* %3
br label %45
27: ; preds = %16
%28 = load i32, i32* %9
%29 = call i32 @o2i_ECPublicKey(i32** %10, i8** %6, i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* @EC_R_DECODE_ERROR
%33 = call i32 @ECerror(i32 %32)
br label %38
34: ; preds = %27
%35 = load i32*, i32** %4
%36 = load i32*, i32** %10
%37 = call i32 @EVP_PKEY_assign_EC_KEY(i32* %35, i32* %36)
store i32 1, i32* %3
br label %45
38: ; preds = %31
%39 = load i32*, i32** %10
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32*, i32** %10
%43 = call i32 @EC_KEY_free(i32* %42)
br label %44
44: ; preds = %41, %38
store i32 0, i32* %3
br label %45
45: ; preds = %44, %34, %24, %15
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@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 %41, 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 %27
24: ; preds = %17
%25 = load i32, i32* @ERR_R_EC_LIB
%26 = call i32 @ECerror(i32 %25)
br label %41
27: ; preds = %17
%28 = load i32, i32* %6
%29 = call i32 @o2i_ECPublicKey(i32** %7, i8** %3, i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* @EC_R_DECODE_ERROR
%33 = call i32 @ECerror(i32 %32)
%34 = load i32*, i32** %7
%35 = icmp eq i32* %34, null
br i1 %35, label %41, label %39
36: ; preds = %27
%37 = load i32*, i32** %7
%38 = call i32 @EVP_PKEY_assign_EC_KEY(i32* %0, i32* %37)
br label %41
39: ; preds = %31
%40 = call i32 @EC_KEY_free(i32* %34)
br label %41
41: ; preds = %31, %39, %2, %36, %24
%42 = phi i32 [ 1, %36 ], [ 0, %24 ], [ 0, %2 ], [ 0, %39 ], [ 0, %31 ]
ret i32 %42
}