#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*/ X509;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_file(char *, char *);
int /*<<< orphan*/ OPENSSL_free(char *);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
char *mk_file_path(char const *, char const *);
X509 *load_pem_cert(const char *dir, const char *file) {
  X509 *cert = NULL;
  char *file_path = mk_file_path(dir, file);
  if (file_path != NULL) {
    BIO *cert_io = BIO_new_file(file_path, "r");
    if (cert_io != NULL)
      cert = PEM_read_bio_X509(cert_io, NULL, NULL, NULL);
    BIO_free(cert_io);
  }
  OPENSSL_free(file_path);
  return cert;
}


x86 assembly (clang, -O0):
<load_pem_cert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <mk_file_path@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c3 <load_pem_cert+0x73>
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1070 <BIO_new_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ba <load_pem_cert+0x6a>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1060 <PEM_read_bio_X509@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <BIO_free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <OPENSSL_free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_pem_cert>:
push   %r15
push   %r14
push   %rbx
call   1030 <mk_file_path@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118c <load_pem_cert+0x3c>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1070 <BIO_new_file@plt>
mov    %rax,%r14
test   %rax,%rax
je     1191 <load_pem_cert+0x41>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <PEM_read_bio_X509@plt>
mov    %rax,%r15
jmp    1194 <load_pem_cert+0x44>
xor    %r15d,%r15d
jmp    119c <load_pem_cert+0x4c>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1040 <BIO_free@plt>
mov    %rbx,%rdi
call   1050 <OPENSSL_free@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32* @load_pem_cert(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32* null, i32** %5
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = call i8* @mk_file_path(i8* %8, i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i32* @BIO_new_file(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32*, i32** %7
%20 = call i32* @PEM_read_bio_X509(i32* %19, i32* null, i32* null, i32* null)
store i32* %20, i32** %5
br label %21
21: ; preds = %18, %13
%22 = load i32*, i32** %7
%23 = call i32 @BIO_free(i32* %22)
br label %24
24: ; preds = %21, %2
%25 = load i8*, i8** %6
%26 = call i32 @OPENSSL_free(i8* %25)
%27 = load i32*, i32** %5
ret i32* %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32* @load_pem_cert(i8* %0, i8* %1) {
%3 = tail call i8* @mk_file_path(i8* %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32* @BIO_new_file(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32* @PEM_read_bio_X509(i32* %6, i32* null, i32* null, i32* null)
br label %10
10: ; preds = %8, %5
%11 = phi i32* [ %9, %8 ], [ null, %5 ]
%12 = tail call i32 @BIO_free(i32* %6)
br label %13
13: ; preds = %10, %2
%14 = phi i32* [ %11, %10 ], [ null, %2 ]
%15 = tail call i32 @OPENSSL_free(i8* %3)
ret i32* %14
}