#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 */
struct hashinfo {
  int dummy;
};
typedef int /*<<< orphan*/ X509_CRL;
typedef int /*<<< orphan*/ EVP_MD;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ *EVP_sha256();
int /*<<< orphan*/ *PEM_read_bio_X509_CRL(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *);
int X509_CRL_digest(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                    unsigned char *, unsigned int *);
int /*<<< orphan*/ X509_CRL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_CRL_get_issuer(int /*<<< orphan*/ *);
unsigned long X509_NAME_hash(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hashinfo *hashinfo(char const *, unsigned long, unsigned char *);
int /*<<< orphan*/ stderr;
struct hashinfo *certhash_crl(BIO *bio, const char *filename) {
  unsigned char fingerprint[EVP_MAX_MD_SIZE];
  struct hashinfo *hi = NULL;
  const EVP_MD *digest;
  X509_CRL *crl = NULL;
  unsigned long hash;
  unsigned int len;
  if ((crl = PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL)) == NULL)
    return (NULL);
  hash = X509_NAME_hash(X509_CRL_get_issuer(crl));
  digest = EVP_sha256();
  if (X509_CRL_digest(crl, digest, fingerprint, &len) != 1) {
    fprintf(stderr, "out of memory\n");
    goto err;
  }
  hi = hashinfo(filename, hash, fingerprint);
err:
  X509_CRL_free(crl);
  return (hi);
}


x86 assembly (clang, -O0):
<certhash_crl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <PEM_read_bio_X509_CRL@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1201 <certhash_crl+0x81>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    1285 <certhash_crl+0x105>
mov    -0x40(%rbp),%rdi
call   1050 <X509_CRL_get_issuer@plt>
mov    %eax,%edi
call   1060 <X509_NAME_hash@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   10a0 <EVP_sha256@plt>
mov    -0x58(%rbp),%rdx
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x4c(%rbp),%rcx
call   1040 <X509_CRL_digest@plt>
cmp    $0x1,%eax
je     1258 <certhash_crl+0xd8>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1080 <fprintf@plt>
jmp    126d <certhash_crl+0xed>
mov    -0x58(%rbp),%rdx
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1090 <hashinfo@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <X509_CRL_free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<certhash_crl>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %r12d,%r12d
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <PEM_read_bio_X509_CRL@plt>
test   %rax,%rax
je     1225 <certhash_crl+0xa5>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <X509_CRL_get_issuer@plt>
mov    %eax,%edi
call   1060 <X509_NAME_hash@plt>
mov    %rax,%r12
xor    %eax,%eax
call   10a0 <EVP_sha256@plt>
lea    -0x24(%rbp),%rcx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <X509_CRL_digest@plt>
cmp    $0x1,%eax
jne    1205 <certhash_crl+0x85>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1090 <hashinfo@plt>
mov    %rax,%r12
jmp    121d <certhash_crl+0x9d>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1080 <fprintf@plt>
xor    %r12d,%r12d
mov    %r15,%rdi
call   1070 <X509_CRL_free@plt>
mov    %r12,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hashinfo = type { i32 }
@EVP_MAX_MD_SIZE = global i32 0
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
define %struct.hashinfo* @certhash_crl(i32* %0, i8* %1) {
%3 = alloca %struct.hashinfo*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.hashinfo*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%14 = load i32, i32* @EVP_MAX_MD_SIZE
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %6
%17 = alloca i8, i64 %15
store i64 %15, i64* %7
store %struct.hashinfo* null, %struct.hashinfo** %8
store i32* null, i32** %10
%18 = load i32*, i32** %4
%19 = call i32* @PEM_read_bio_X509_CRL(i32* %18, i32* null, i32* null, i32* null)
store i32* %19, i32** %10
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %2
store %struct.hashinfo* null, %struct.hashinfo** %3
store i32 1, i32* %13
br label %42
22: ; preds = %2
%23 = load i32*, i32** %10
%24 = call i32 @X509_CRL_get_issuer(i32* %23)
%25 = call i64 @X509_NAME_hash(i32 %24)
store i64 %25, i64* %11
%26 = call i32* (...) @EVP_sha256()
store i32* %26, i32** %9
%27 = load i32*, i32** %10
%28 = load i32*, i32** %9
%29 = call i32 @X509_CRL_digest(i32* %27, i32* %28, i8* %17, i32* %12)
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %38
34: ; preds = %22
%35 = load i8*, i8** %5
%36 = load i64, i64* %11
%37 = call %struct.hashinfo* @hashinfo(i8* %35, i64 %36, i8* %17)
store %struct.hashinfo* %37, %struct.hashinfo** %8
br label %38
38: ; preds = %34, %31
%39 = load i32*, i32** %10
%40 = call i32 @X509_CRL_free(i32* %39)
%41 = load %struct.hashinfo*, %struct.hashinfo** %8
store %struct.hashinfo* %41, %struct.hashinfo** %3
store i32 1, i32* %13
br label %42
42: ; preds = %38, %21
%43 = load i8*, i8** %6
%44 = load %struct.hashinfo*, %struct.hashinfo** %3
ret %struct.hashinfo* %44
}

LLVM IR (-O2):
%struct.hashinfo = type { i32 }
@EVP_MAX_MD_SIZE = global i32 0
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
define %struct.hashinfo* @certhash_crl(i32* %0, i8* %1) {
%3 = alloca i32
%4 = load i32, i32* @EVP_MAX_MD_SIZE
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i32* %3 to i8*
%8 = tail call i32* @PEM_read_bio_X509_CRL(i32* %0, i32* null, i32* null, i32* null)
%9 = icmp eq i32* %8, null
br i1 %9, label %24, label %10
10: ; preds = %2
%11 = tail call i32 @X509_CRL_get_issuer(i32* %8)
%12 = tail call i64 @X509_NAME_hash(i32 %11)
%13 = tail call i32* (...) @EVP_sha256()
%14 = call i32 @X509_CRL_digest(i32* %8, i32* %13, i8* %6, i32* %3)
%15 = icmp eq i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %21
19: ; preds = %10
%20 = call %struct.hashinfo* @hashinfo(i8* %1, i64 %12, i8* %6)
br label %21
21: ; preds = %19, %16
%22 = phi %struct.hashinfo* [ null, %16 ], [ %20, %19 ]
%23 = call i32 @X509_CRL_free(i32* %8)
br label %24
24: ; preds = %2, %21
%25 = phi %struct.hashinfo* [ %22, %21 ], [ null, %2 ]
ret %struct.hashinfo* %25
}