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

/* Variables and functions */
int /*<<< orphan*/ *PEM_read_RSAPrivateKey(int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
RSA *rsa_read_private_key(char *path) {
  FILE *keyfile;
  RSA *rsa;
  keyfile = fopen(path, "r");
  if (keyfile == NULL) {
    perror("fopen");
    return NULL;
  }
  rsa = PEM_read_RSAPrivateKey(keyfile, NULL, NULL, NULL);
  fclose(keyfile);
  return rsa;
}


x86 assembly (clang, -O0):
<rsa_read_private_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1184 <rsa_read_private_key+0x44>
lea    0xe90(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ac <rsa_read_private_key+0x6c>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <PEM_read_RSAPrivateKey@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_read_private_key>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117c <rsa_read_private_key+0x3c>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <PEM_read_RSAPrivateKey@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
jmp    1174 <rsa_read_private_key+0x34>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
define i32* @rsa_read_private_key(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 eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32* null, i32** %2
br label %18
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = call i32* @PEM_read_RSAPrivateKey(i32* %13, i32* null, i32* null, i32* null)
store i32* %14, i32** %5
%15 = load i32*, i32** %4
%16 = call i32 @fclose(i32* %15)
%17 = load i32*, i32** %5
store i32* %17, i32** %2
br label %18
18: ; preds = %12, %10
%19 = load i32*, i32** %2
ret i32* %19
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
define i32* @rsa_read_private_key(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 %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %9
6: ; preds = %1
%7 = tail call i32* @PEM_read_RSAPrivateKey(i32* %2, i32* null, i32* null, i32* null)
%8 = tail call i32 @fclose(i32* %2)
br label %9
9: ; preds = %6, %4
%10 = phi i32* [ null, %4 ], [ %7, %6 ]
ret i32* %10
}