#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*/ EC_KEY;

/* Variables and functions */
unsigned long ERR_get_error();
int /*<<< orphan*/ *d2i_ECPrivateKey(int /*<<< orphan*/ *,
                                     unsigned char const **, long);
EC_KEY *openssl_d2i_ECPrivateKey(const unsigned char *data, long len,
                                 unsigned long *e) {
  EC_KEY *k = d2i_ECPrivateKey(NULL, &data, len);
  if (k != NULL) {
    *e = 0;
    return k;
  }
  *e = ERR_get_error();
  return NULL;
}


x86 assembly (clang, -O0):
<openssl_d2i_ECPrivateKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x10(%rbp),%rsi
call   1040 <d2i_ECPrivateKey@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     116c <openssl_d2i_ECPrivateKey+0x4c>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <openssl_d2i_ECPrivateKey+0x65>
mov    $0x0,%al
call   1030 <ERR_get_error@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openssl_d2i_ECPrivateKey>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %rdi,0x8(%rsp)
xor    %r15d,%r15d
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1040 <d2i_ECPrivateKey@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1155 <openssl_d2i_ECPrivateKey+0x35>
xor    %eax,%eax
call   1030 <ERR_get_error@plt>
mov    %rax,%r15
mov    %r15,(%r14)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @openssl_d2i_ECPrivateKey(i8* %0, i64 %1, i64* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i32*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64* %2, i64** %7
%9 = load i64, i64* %6
%10 = call i32* @d2i_ECPrivateKey(i32* null, i8** %5, i64 %9)
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i64*, i64** %7
store i64 0, i64* %14
%15 = load i32*, i32** %8
store i32* %15, i32** %4
br label %19
16: ; preds = %3
%17 = call i64 (...) @ERR_get_error()
%18 = load i64*, i64** %7
store i64 %17, i64* %18
store i32* null, i32** %4
br label %19
19: ; preds = %16, %13
%20 = load i32*, i32** %4
ret i32* %20
}

LLVM IR (-O2):
define i32* @openssl_d2i_ECPrivateKey(i8* %0, i64 %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
store i8* %0, i8** %4
%5 = call i32* @d2i_ECPrivateKey(i32* null, i8** %4, i64 %1)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = call i64 (...) @ERR_get_error()
br label %9
9: ; preds = %3, %7
%10 = phi i64 [ %8, %7 ], [ 0, %3 ]
store i64 %10, i64* %2
ret i32* %5
}