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

/* Variables and functions */
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_get1_EC_KEY(int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_PrivateKey(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
EC_KEY *ecqv_read_private_key(FILE *file) {
  EVP_PKEY *pk = PEM_read_PrivateKey(file, NULL, NULL, NULL);
  EC_KEY *key;
  if (!pk) {
    fprintf(stderr, "Error reading private key file.\n");
    return NULL;
  }
  key = EVP_PKEY_get1_EC_KEY(pk);
  if (!key) {
    fprintf(stderr, "Error loading EC private key.\n");
  }
  EVP_PKEY_free(pk);
  return key;
}


x86 assembly (clang, -O0):
<ecqv_read_private_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1060 <PEM_read_PrivateKey@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <ecqv_read_private_key+0x50>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ce <ecqv_read_private_key+0x8e>
mov    -0x18(%rbp),%rdi
call   1040 <EVP_PKEY_get1_EC_KEY@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bd <ecqv_read_private_key+0x7d>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <EVP_PKEY_free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecqv_read_private_key>:
push   %r14
push   %rbx
push   %rax
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <PEM_read_PrivateKey@plt>
test   %rax,%rax
je     1186 <ecqv_read_private_key+0x46>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <EVP_PKEY_get1_EC_KEY@plt>
mov    %rax,%r14
test   %rax,%rax
jne    117c <ecqv_read_private_key+0x3c>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <EVP_PKEY_free@plt>
jmp    119e <ecqv_read_private_key+0x5e>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1050 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Error reading private key file.\0A\00"
@.str.1 = [31 x i8] c"Error loading EC private key.\0A\00"
define i32* @ecqv_read_private_key(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32* @PEM_read_PrivateKey(i32* %6, i32* null, i32* null, i32* null)
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %2
br label %25
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = call i32* @EVP_PKEY_get1_EC_KEY(i32* %14)
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %18, %13
%22 = load i32*, i32** %4
%23 = call i32 @EVP_PKEY_free(i32* %22)
%24 = load i32*, i32** %5
store i32* %24, i32** %2
br label %25
25: ; preds = %21, %10
%26 = load i32*, i32** %2
ret i32* %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Error reading private key file.\0A\00"
@.str.1 = [31 x i8] c"Error loading EC private key.\0A\00"
define i32* @ecqv_read_private_key(i32* %0) {
%2 = tail call i32* @PEM_read_PrivateKey(i32* %0, i32* null, i32* null, i32* null)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = tail call i32* @EVP_PKEY_get1_EC_KEY(i32* %2)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %7
%14 = tail call i32 @EVP_PKEY_free(i32* %2)
br label %15
15: ; preds = %13, %4
%16 = phi i32* [ %8, %13 ], [ null, %4 ]
ret i32* %16
}