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

/* Variables and functions */
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file();
int /*<<< orphan*/ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ *PEM_read_bio_X509_CRL(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
X509_CRL *load_crl(char *ca_name) {
  FILE *fp;
  BIO *in;
  X509_CRL *crl;
  char filename[128 + 5];
  sprintf(filename, "%s.crl", ca_name);
  in = BIO_new(BIO_s_file());
  if ((fp = fopen(filename, "rb")) == NULL) {
    BIO_free(in);
    return NULL;
  }
  BIO_set_fp(in, fp, BIO_NOCLOSE);
  crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
  fclose(fp);
  BIO_free(in);
  return crl;
}


x86 assembly (clang, -O0):
<load_crl>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1090 <sprintf@plt>
mov    $0x0,%al
call   10a0 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
lea    -0xb0(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ef <load_crl+0x6f>
mov    -0x20(%rbp),%rdi
call   1060 <BIO_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1236 <load_crl+0xb6>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
call   1070 <BIO_set_fp@plt>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <PEM_read_bio_X509_CRL@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_crl>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%rdx
lea    0xe6a(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   10a0 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,%r15
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f9 <load_crl+0x79>
mov    %rax,%rbx
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <BIO_set_fp@plt>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <PEM_read_bio_X509_CRL@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1060 <BIO_free@plt>
mov    %r14,%rax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s.crl\00"
@.str.1 = [3 x i8] c"rb\00"
@BIO_NOCLOSE = global i32 0
define i32* @load_crl(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [133 x i8]
store i8* %0, i8** %3
%8 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 (...) @BIO_s_file()
%12 = call i32* @BIO_new(i32 %11)
store i32* %12, i32** %5
%13 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i32*, i32** %5
%18 = call i32 @BIO_free(i32* %17)
store i32* null, i32** %2
br label %31
19: ; preds = %1
%20 = load i32*, i32** %5
%21 = load i32*, i32** %4
%22 = load i32, i32* @BIO_NOCLOSE
%23 = call i32 @BIO_set_fp(i32* %20, i32* %21, i32 %22)
%24 = load i32*, i32** %5
%25 = call i32* @PEM_read_bio_X509_CRL(i32* %24, i32* null, i32* null, i32* null)
store i32* %25, i32** %6
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
%28 = load i32*, i32** %5
%29 = call i32 @BIO_free(i32* %28)
%30 = load i32*, i32** %6
store i32* %30, i32** %2
br label %31
31: ; preds = %19, %16
%32 = load i32*, i32** %2
ret i32* %32
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s.crl\00"
@.str.1 = [3 x i8] c"rb\00"
@BIO_NOCLOSE = global i32 0
define i32* @load_crl(i8* %0) {
%2 = alloca [133 x i8]
%3 = getelementptr inbounds [133 x i8], [133 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32 (...) @BIO_s_file()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i32, i32* @BIO_NOCLOSE
%11 = tail call i32 @BIO_set_fp(i32* %6, i32* %7, i32 %10)
%12 = tail call i32* @PEM_read_bio_X509_CRL(i32* %6, i32* null, i32* null, i32* null)
%13 = tail call i32 @fclose(i32* %7)
br label %14
14: ; preds = %1, %9
%15 = phi i32* [ %12, %9 ], [ null, %1 ]
%16 = tail call i32 @BIO_free(i32* %6)
ret i32* %15
}