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

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
size_t BIO_write(int /*<<< orphan*/ *, unsigned char const *, size_t);
int /*<<< orphan*/ EVP_PKEY_assign_EC_KEY(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
scalar_t__ d2i_EC_PUBKEY_bio(int /*<<< orphan*/ *, int /*<<< orphan*/ **);
EVP_PKEY *pub_der_to_pkey(const unsigned char *string, size_t len) {
  EVP_PKEY *pub_key = EVP_PKEY_new();
  EC_KEY *ec_key = NULL;
  BIO *bo = NULL;
  if ((pub_key = EVP_PKEY_new()) == NULL)
    return NULL;
  if ((bo = BIO_new(BIO_s_mem())) == NULL)
    goto BAILOUT1;
  if (BIO_write(bo, string, len) == len && d2i_EC_PUBKEY_bio(bo, &ec_key))
    EVP_PKEY_assign_EC_KEY(pub_key, ec_key);
  else
    goto BAILOUT2;
  BIO_free(bo);
  return pub_key;
BAILOUT2:
  BIO_free(bo);
BAILOUT1:
  EVP_PKEY_free(pub_key);
  return NULL;
}


x86 assembly (clang, -O0):
<pub_der_to_pkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1070 <EVP_PKEY_new@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1070 <EVP_PKEY_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11cd <pub_der_to_pkey+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    1267 <pub_der_to_pkey+0xe7>
mov    $0x0,%al
call   10a0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ee <pub_der_to_pkey+0x6e>
jmp    1256 <pub_der_to_pkey+0xd6>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1090 <BIO_write@plt>
cmp    -0x18(%rbp),%rax
jne    1232 <pub_der_to_pkey+0xb2>
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <d2i_EC_PUBKEY_bio@plt>
cmp    $0x0,%rax
je     1232 <pub_der_to_pkey+0xb2>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <EVP_PKEY_assign_EC_KEY@plt>
jmp    1237 <pub_der_to_pkey+0xb7>
jmp    124d <pub_der_to_pkey+0xcd>
mov    -0x30(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <pub_der_to_pkey+0xe7>
mov    -0x30(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <EVP_PKEY_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pub_der_to_pkey>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
xor    %eax,%eax
call   1070 <EVP_PKEY_new@plt>
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1070 <EVP_PKEY_new@plt>
test   %rax,%rax
je     120b <pub_der_to_pkey+0x8b>
mov    %rax,%rbx
xor    %eax,%eax
call   10a0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
test   %rax,%rax
je     1203 <pub_der_to_pkey+0x83>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1090 <BIO_write@plt>
cmp    %r14,%rax
jne    11fb <pub_der_to_pkey+0x7b>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1040 <d2i_EC_PUBKEY_bio@plt>
test   %rax,%rax
je     11fb <pub_der_to_pkey+0x7b>
mov    (%rsp),%rsi
mov    %rbx,%rdi
call   1080 <EVP_PKEY_assign_EC_KEY@plt>
mov    %r15,%rdi
call   1060 <BIO_free@plt>
jmp    120d <pub_der_to_pkey+0x8d>
mov    %r15,%rdi
call   1060 <BIO_free@plt>
mov    %rbx,%rdi
call   1030 <EVP_PKEY_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @pub_der_to_pkey(i8* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = call i32* (...) @EVP_PKEY_new()
store i32* %9, i32** %6
store i32* null, i32** %7
store i32* null, i32** %8
%10 = call i32* (...) @EVP_PKEY_new()
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32* null, i32** %3
br label %44
13: ; preds = %2
%14 = call i32 (...) @BIO_s_mem()
%15 = call i32* @BIO_new(i32 %14)
store i32* %15, i32** %8
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %13
br label %41
18: ; preds = %13
%19 = load i32*, i32** %8
%20 = load i8*, i8** %4
%21 = load i64, i64* %5
%22 = call i64 @BIO_write(i32* %19, i8* %20, i64 %21)
%23 = load i64, i64* %5
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %18
%26 = load i32*, i32** %8
%27 = call i64 @d2i_EC_PUBKEY_bio(i32* %26, i32** %7)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32*, i32** %6
%31 = load i32*, i32** %7
%32 = call i32 @EVP_PKEY_assign_EC_KEY(i32* %30, i32* %31)
br label %34
33: ; preds = %25, %18
br label %38
34: ; preds = %29
%35 = load i32*, i32** %8
%36 = call i32 @BIO_free(i32* %35)
%37 = load i32*, i32** %6
store i32* %37, i32** %3
br label %44
38: ; preds = %33
%39 = load i32*, i32** %8
%40 = call i32 @BIO_free(i32* %39)
br label %41
41: ; preds = %38, %17
%42 = load i32*, i32** %6
%43 = call i32 @EVP_PKEY_free(i32* %42)
store i32* null, i32** %3
br label %44
44: ; preds = %41, %34, %12
%45 = load i32*, i32** %3
ret i32* %45
}

LLVM IR (-O2):
define i32* @pub_der_to_pkey(i8* %0, i64 %1) {
%3 = alloca i32*
%4 = tail call i32* (...) @EVP_PKEY_new()
%5 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%6 = tail call i32* (...) @EVP_PKEY_new()
%7 = icmp eq i32* %6, null
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = tail call i32 (...) @BIO_s_mem()
%10 = tail call i32* @BIO_new(i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %24, label %12
12: ; preds = %8
%13 = tail call i64 @BIO_write(i32* %10, i8* %0, i64 %1)
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = call i64 @d2i_EC_PUBKEY_bio(i32* %10, i32** %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32*, i32** %3
%20 = call i32 @EVP_PKEY_assign_EC_KEY(i32* %6, i32* %19)
%21 = call i32 @BIO_free(i32* %10)
br label %26
22: ; preds = %12, %15
%23 = call i32 @BIO_free(i32* %10)
br label %24
24: ; preds = %8, %22
%25 = call i32 @EVP_PKEY_free(i32* %6)
br label %26
26: ; preds = %2, %24, %18
%27 = phi i32* [ null, %24 ], [ %6, %18 ], [ null, %2 ]
ret i32* %27
}