#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ *PEM_read_RSAPrivateKey(int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *,
                                           int /*<<< orphan*/,
                                           int /*<<< orphan*/ *);
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
RSA *util_read_rsa_pem(char *path) {
  if (access(path, R_OK))
    if (errno != ENOENT)
      ;
  FILE *fd = fopen(path, "r");
  if (!fd)
    ;
  RSA *rsa = PEM_read_RSAPrivateKey(fd, NULL, 0, NULL);
  if (!rsa)
    ;
  if (fclose(fd))
    ;
  return rsa;
}


x86 assembly (clang, -O0):
<util_read_rsa_pem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
je     118c <util_read_rsa_pem+0x4c>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
je     1187 <util_read_rsa_pem+0x47>
jmp    1187 <util_read_rsa_pem+0x47>
jmp    118c <util_read_rsa_pem+0x4c>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b0 <util_read_rsa_pem+0x70>
jmp    11b0 <util_read_rsa_pem+0x70>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <PEM_read_RSAPrivateKey@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d6 <util_read_rsa_pem+0x96>
jmp    11d6 <util_read_rsa_pem+0x96>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11ee <util_read_rsa_pem+0xae>
jmp    11ee <util_read_rsa_pem+0xae>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_read_rsa_pem>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
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

LLVM IR (-O0):
@R_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str = [2 x i8] c"r\00"
define i32* @util_read_rsa_pem(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @R_OK
%7 = call i64 @access(i8* %5, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
br label %14
14: ; preds = %13, %9
br label %15
15: ; preds = %14, %1
%16 = load i8*, i8** %2
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %3
%18 = load i32*, i32** %3
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %15
br label %21
21: ; preds = %20, %15
%22 = load i32*, i32** %3
%23 = call i32* @PEM_read_RSAPrivateKey(i32* %22, i32* null, i32 0, i32* null)
store i32* %23, i32** %4
%24 = load i32*, i32** %4
%25 = icmp ne i32* %24, null
br i1 %25, label %27, label %26
26: ; preds = %21
br label %27
27: ; preds = %26, %21
%28 = load i32*, i32** %3
%29 = call i64 @fclose(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %32
32: ; preds = %31, %27
%33 = load i32*, i32** %4
ret i32* %33
}

LLVM IR (-O2):
@R_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str = [2 x i8] c"r\00"
define i32* @util_read_rsa_pem(i8* nocapture %0) {
%2 = load i32, i32* @R_OK
%3 = tail call i64 @access(i8* %0, i32 %2)
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @PEM_read_RSAPrivateKey(i32* %4, i32* null, i32 0, i32* null)
%6 = tail call i64 @fclose(i32* %4)
ret i32* %5
}