#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*/ *PEM_read_PrivateKey(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ **,
                                        int /*<<< orphan*/ *, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
EVP_PKEY *file_to_pkey(const char *fname, unsigned char *passphrase) {
  EVP_PKEY *key = NULL;
  FILE *fp = fopen(fname, "r");
  if (fp != NULL) {
    key = PEM_read_PrivateKey(fp, &key, NULL, passphrase);
    fclose(fp);
  }
  return key;
}


x86 assembly (clang, -O0):
<file_to_pkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1189 <file_to_pkey+0x59>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <PEM_read_PrivateKey@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_to_pkey>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movq   $0x0,(%rsp)
lea    0xeba(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1175 <file_to_pkey+0x45>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
mov    %r14,%rcx
call   1050 <PEM_read_PrivateKey@plt>
mov    %rax,(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%rax
jmp    1177 <file_to_pkey+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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