#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*/ *PEM_read_RSA_PUBKEY(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ **,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ *RSA_new();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
RSA *createRSAWithFilename(char *filename, int public) {
  FILE *fp = fopen(filename, "rb");
  if (fp == NULL) {
    fprintf(stderr, "Unable to open file %s\n", filename);
    return NULL;
  }
  RSA *rsa = RSA_new();
  if (public)
    rsa = PEM_read_RSA_PUBKEY(fp, &rsa, NULL, NULL);
  else
    rsa = PEM_read_RSAPrivateKey(fp, &rsa, NULL, NULL);
  return rsa;
}


x86 assembly (clang, -O0):
<createRSAWithFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <createRSAWithFilename+0x54>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe71(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f6 <createRSAWithFilename+0xa6>
mov    $0x0,%al
call   1050 <RSA_new@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d6 <createRSAWithFilename+0x86>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1070 <PEM_read_RSA_PUBKEY@plt>
mov    %rax,-0x28(%rbp)
jmp    11ee <createRSAWithFilename+0x9e>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <PEM_read_RSAPrivateKey@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createRSAWithFilename>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1196 <createRSAWithFilename+0x46>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <RSA_new@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
test   %r14d,%r14d
je     11b2 <createRSAWithFilename+0x62>
call   1070 <PEM_read_RSA_PUBKEY@plt>
jmp    11b7 <createRSAWithFilename+0x67>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    %rbp,%rdx
call   1030 <fprintf@plt>
xor    %eax,%eax
jmp    11b7 <createRSAWithFilename+0x67>
call   1040 <PEM_read_RSAPrivateKey@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Unable to open file %s\0A\00"
define i32* @createRSAWithFilename(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32* null, i32** %3
br label %28
16: ; preds = %2
%17 = call i32* (...) @RSA_new()
store i32* %17, i32** %7
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = call i32* @PEM_read_RSA_PUBKEY(i32* %21, i32** %7, i32* null, i32* null)
store i32* %22, i32** %7
br label %26
23: ; preds = %16
%24 = load i32*, i32** %6
%25 = call i32* @PEM_read_RSAPrivateKey(i32* %24, i32** %7, i32* null, i32* null)
store i32* %25, i32** %7
br label %26
26: ; preds = %23, %20
%27 = load i32*, i32** %7
store i32* %27, i32** %3
br label %28
28: ; preds = %26, %12
%29 = load i32*, i32** %3
ret i32* %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Unable to open file %s\0A\00"
define i32* @createRSAWithFilename(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %19
9: ; preds = %2
%10 = bitcast i32** %3 to i8*
%11 = tail call i32* (...) @RSA_new()
store i32* %11, i32** %3
%12 = icmp eq i32 %1, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32* @PEM_read_RSA_PUBKEY(i32* %4, i32** %3, i32* null, i32* null)
br label %17
15: ; preds = %9
%16 = call i32* @PEM_read_RSAPrivateKey(i32* %4, i32** %3, i32* null, i32* null)
br label %17
17: ; preds = %15, %13
%18 = phi i32* [ %16, %15 ], [ %14, %13 ]
br label %19
19: ; preds = %17, %6
%20 = phi i32* [ null, %6 ], [ %18, %17 ]
ret i32* %20
}