#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;

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ *PEM_read_PrivateKey(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ stderr;
EVP_PKEY *ReadPrivateKey(const char *keyfile) {
  FILE *fp = fopen(keyfile, "r");
  EVP_PKEY *pkey;
  if (!fp)
    return NULL;
  pkey = PEM_read_PrivateKey(fp, NULL, 0, NULL);
  fclose(fp);
  if (pkey == NULL)
    ERR_print_errors_fp(stderr);
  return pkey;
}


x86 assembly (clang, -O0):
<ReadPrivateKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1178 <ReadPrivateKey+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11b8 <ReadPrivateKey+0x78>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1050 <PEM_read_PrivateKey@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11b0 <ReadPrivateKey+0x70>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1060 <ERR_print_errors_fp@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadPrivateKey>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1184 <ReadPrivateKey+0x44>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <PEM_read_PrivateKey@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r14,%r14
jne    1187 <ReadPrivateKey+0x47>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1060 <ERR_print_errors_fp@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
define i32* @ReadPrivateKey(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32* null, i32** %2
br label %23
11: ; preds = %1
%12 = load i32*, i32** %4
%13 = call i32* @PEM_read_PrivateKey(i32* %12, i32* null, i32 0, i32* null)
store i32* %13, i32** %5
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
%16 = load i32*, i32** %5
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = call i32 @ERR_print_errors_fp(i32 %19)
br label %21
21: ; preds = %18, %11
%22 = load i32*, i32** %5
store i32* %22, i32** %2
br label %23
23: ; preds = %21, %10
%24 = load i32*, i32** %2
ret i32* %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
define i32* @ReadPrivateKey(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = tail call i32* @PEM_read_PrivateKey(i32* %2, i32* null, i32 0, i32* null)
%6 = tail call i32 @fclose(i32* %2)
%7 = icmp eq i32* %5, null
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @ERR_print_errors_fp(i32 %9)
br label %11
11: ; preds = %4, %8, %1
%12 = phi i32* [ null, %1 ], [ null, %8 ], [ %5, %4 ]
ret i32* %12
}