#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");
    OPENSSL_free(file_path);
    if (cert_io != NULL)
      cert = PEM_read_bio_X509(cert_io, NULL, NULL, NULL);
    BIO_free(cert_io);
  }
  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     11cc <load_pem_cert+0x7c>
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1070 <BIO_new_file@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <OPENSSL_free@plt>
cmpq   $0x0,-0x28(%rbp)
je     11c3 <load_pem_cert+0x73>
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    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_pem_cert>:
push   %r14
push   %rbx
push   %rax
call   1030 <mk_file_path@plt>
test   %rax,%rax
je     1193 <load_pem_cert+0x43>
mov    %rax,%rbx
lea    0xe98(%rip),%rsi
mov    %rax,%rdi
call   1070 <BIO_new_file@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <OPENSSL_free@plt>
test   %r14,%r14
je     1197 <load_pem_cert+0x47>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <PEM_read_bio_X509@plt>
mov    %rax,%rbx
jmp    1199 <load_pem_cert+0x49>
xor    %ebx,%ebx
jmp    11a1 <load_pem_cert+0x51>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <BIO_free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 %26
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 i8*, i8** %6
%17 = call i32 @OPENSSL_free(i8* %16)
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32*, i32** %7
%22 = call i32* @PEM_read_bio_X509(i32* %21, i32* null, i32* null, i32* null)
store i32* %22, i32** %5
br label %23
23: ; preds = %20, %13
%24 = load i32*, i32** %7
%25 = call i32 @BIO_free(i32* %24)
br label %26
26: ; preds = %23, %2
%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 %14, 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 = tail call i32 @OPENSSL_free(i8* %3)
%8 = icmp eq i32* %6, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32* @PEM_read_bio_X509(i32* %6, i32* null, i32* null, i32* null)
br label %11
11: ; preds = %9, %5
%12 = phi i32* [ %10, %9 ], [ null, %5 ]
%13 = tail call i32 @BIO_free(i32* %6)
br label %14
14: ; preds = %11, %2
%15 = phi i32* [ %12, %11 ], [ null, %2 ]
ret i32* %15
}