#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 const *, char *);
int BIO_reset(int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ *d2i_X509_bio(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ display_openssl_errors(int);
int /*<<< orphan*/ drain_openssl_errors();
int /*<<< orphan*/ err(int, char *, char const *);
X509 *read_x509(const char *x509_name) {
  X509 *x509;
  BIO *b;
  b = BIO_new_file(x509_name, "rb");
  do {
    bool __cond = (!b);
    display_openssl_errors(174);
    if (__cond) {
      err(1, "%s", x509_name);
    }
  } while (0);
  x509 = d2i_X509_bio(b, NULL);
  if (!x509) {
    do {
      bool __cond = (BIO_reset(b) != 1);
      display_openssl_errors(177);
      if (__cond) {
        err(1, "%s", x509_name);
      }
    } while (0);
    x509 = PEM_read_bio_X509(b, NULL, NULL, NULL);
    if (x509)
      drain_openssl_errors();
  }
  BIO_free(b);
  do {
    bool __cond = (!x509);
    display_openssl_errors(184);
    if (__cond) {
      err(1, "%s", x509_name);
    }
  } while (0);
  return x509;
}


x86 assembly (clang, -O0):
<read_x509>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <BIO_new_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    $0xae,%edi
call   1070 <display_openssl_errors@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11db <read_x509+0x5b>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe2d(%rip),%rsi
call   1050 <err@plt>
jmp    11e0 <read_x509+0x60>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <d2i_X509_bio@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1274 <read_x509+0xf4>
jmp    1201 <read_x509+0x81>
mov    -0x18(%rbp),%rdi
call   1080 <BIO_reset@plt>
cmp    $0x1,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    $0xb1,%edi
call   1070 <display_openssl_errors@plt>
cmpl   $0x0,-0x20(%rbp)
je     1241 <read_x509+0xc1>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xdc7(%rip),%rsi
call   1050 <err@plt>
jmp    1246 <read_x509+0xc6>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1090 <PEM_read_bio_X509@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     126f <read_x509+0xef>
mov    $0x0,%al
call   1040 <drain_openssl_errors@plt>
jmp    1274 <read_x509+0xf4>
mov    -0x18(%rbp),%rdi
call   1060 <BIO_free@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    $0xb8,%edi
call   1070 <display_openssl_errors@plt>
cmpl   $0x0,-0x24(%rbp)
je     12b8 <read_x509+0x138>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xd50(%rip),%rsi
call   1050 <err@plt>
jmp    12bd <read_x509+0x13d>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_x509>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe6e(%rip),%rsi
call   10a0 <BIO_new_file@plt>
mov    %rax,%r15
mov    $0xae,%edi
call   1070 <display_openssl_errors@plt>
test   %r15,%r15
jne    11bd <read_x509+0x3d>
lea    0xe53(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1050 <err@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <d2i_X509_bio@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    121e <read_x509+0x9e>
mov    %r15,%rdi
call   1080 <BIO_reset@plt>
mov    %eax,%ebx
mov    $0xb1,%edi
call   1070 <display_openssl_errors@plt>
cmp    $0x1,%ebx
je     11fc <read_x509+0x7c>
lea    0xe14(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1050 <err@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <PEM_read_bio_X509@plt>
test   %rax,%rax
je     121e <read_x509+0x9e>
mov    %rax,%r12
xor    %eax,%eax
call   1040 <drain_openssl_errors@plt>
mov    %r12,%rbx
mov    %r15,%rdi
call   1060 <BIO_free@plt>
mov    $0xb8,%edi
call   1070 <display_openssl_errors@plt>
test   %rbx,%rbx
jne    1249 <read_x509+0xc9>
lea    0xdc7(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1050 <err@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"%s\00"
define i32* @read_x509(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @BIO_new_file(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
br label %10
10: ; preds = %1
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
store i32 %14, i32* %5
%15 = call i32 @display_openssl_errors(i32 174)
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i8*, i8** %2
%20 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %10
br label %22
22: ; preds = %21
%23 = load i32*, i32** %4
%24 = call i32* @d2i_X509_bio(i32* %23, i32* null)
store i32* %24, i32** %3
%25 = load i32*, i32** %3
%26 = icmp ne i32* %25, null
br i1 %26, label %48, label %27
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load i32*, i32** %4
%30 = call i32 @BIO_reset(i32* %29)
%31 = icmp ne i32 %30, 1
%32 = zext i1 %31 to i32
store i32 %32, i32* %6
%33 = call i32 @display_openssl_errors(i32 177)
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i8*, i8** %2
%38 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %28
br label %40
40: ; preds = %39
%41 = load i32*, i32** %4
%42 = call i32* @PEM_read_bio_X509(i32* %41, i32* null, i32* null, i32* null)
store i32* %42, i32** %3
%43 = load i32*, i32** %3
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 (...) @drain_openssl_errors()
br label %47
47: ; preds = %45, %40
br label %48
48: ; preds = %47, %22
%49 = load i32*, i32** %4
%50 = call i32 @BIO_free(i32* %49)
br label %51
51: ; preds = %48
%52 = load i32*, i32** %3
%53 = icmp ne i32* %52, null
%54 = xor i1 %53, true
%55 = zext i1 %54 to i32
store i32 %55, i32* %7
%56 = call i32 @display_openssl_errors(i32 184)
%57 = load i32, i32* %7
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = load i8*, i8** %2
%61 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %59, %51
br label %63
63: ; preds = %62
%64 = load i32*, i32** %3
ret i32* %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"%s\00"
define i32* @read_x509(i8* %0) {
%2 = tail call i32* @BIO_new_file(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
%4 = tail call i32 @display_openssl_errors(i32 174)
br i1 %3, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %1
%8 = tail call i32* @d2i_X509_bio(i32* %2, i32* null)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = tail call i32 @BIO_reset(i32* %2)
%12 = icmp eq i32 %11, 1
%13 = tail call i32 @display_openssl_errors(i32 177)
br i1 %12, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %14, %10
%17 = tail call i32* @PEM_read_bio_X509(i32* %2, i32* null, i32* null, i32* null)
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 (...) @drain_openssl_errors()
br label %21
21: ; preds = %16, %19, %7
%22 = phi i32* [ %8, %7 ], [ %17, %19 ], [ null, %16 ]
%23 = tail call i32 @BIO_free(i32* %2)
%24 = icmp eq i32* %22, null
%25 = tail call i32 @display_openssl_errors(i32 184)
br i1 %24, label %26, label %28
26: ; preds = %21
%27 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %26, %21
ret i32* %22
}