#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*/ *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
EVP_PKEY *ReadPrivKey_FromFile(char *filename, char *pass) {
  int i;
  FILE *fp = fopen(filename, "r");
  if (fp == NULL) {
    printf("%s can't be opened. Plese run Certificate Genrataion demo first\n",
           filename);
    return 0;
  }
  EVP_PKEY *key = NULL;
  PEM_read_PrivateKey(fp, &key, NULL, pass);
  fclose(fp);
  return key;
}


x86 assembly (clang, -O0):
<ReadPrivKey_FromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118c <ReadPrivKey_FromFile+0x4c>
mov    -0x10(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ba <ReadPrivKey_FromFile+0x7a>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <PEM_read_PrivateKey@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadPrivKey_FromFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeaa(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118d <ReadPrivKey_FromFile+0x4d>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
mov    %r14,%rcx
call   1060 <PEM_read_PrivateKey@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rax
jmp    119e <ReadPrivKey_FromFile+0x5e>
lea    0xe6e(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [65 x i8] c"%s can't be opened. Plese run Certificate Genrataion demo first\0A\00"
define i32* @ReadPrivKey_FromFile(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32* null, i32** %3
br label %23
16: ; preds = %2
store i32* null, i32** %8
%17 = load i32*, i32** %7
%18 = load i8*, i8** %5
%19 = call i32 @PEM_read_PrivateKey(i32* %17, i32** %8, i32* null, i8* %18)
%20 = load i32*, i32** %7
%21 = call i32 @fclose(i32* %20)
%22 = load i32*, i32** %8
store i32* %22, i32** %3
br label %23
23: ; preds = %16, %13
%24 = load i32*, i32** %3
ret i32* %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [65 x i8] c"%s can't be opened. Plese run Certificate Genrataion demo first\0A\00"
define i32* @ReadPrivKey_FromFile(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
8: ; preds = %2
%9 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%10 = call i32 @PEM_read_PrivateKey(i32* %4, i32** %3, i32* null, i8* %1)
%11 = call i32 @fclose(i32* %4)
%12 = load i32*, i32** %3
br label %13
13: ; preds = %8, %6
%14 = phi i32* [ null, %6 ], [ %12, %8 ]
ret i32* %14
}