#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_NAME;
typedef int /*<<< orphan*/ X509;
typedef int /*<<< orphan*/ OCSP_CERTID;
typedef int /*<<< orphan*/ EVP_MD;
typedef int /*<<< orphan*/ ASN1_INTEGER;
typedef int /*<<< orphan*/ ASN1_BIT_STRING;

/* Variables and functions */
int /*<<< orphan*/ *EVP_sha1();
int /*<<< orphan*/ *OCSP_cert_id_new(int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ const *);
int /*<<< orphan*/ *X509_get0_pubkey_bitstr(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *X509_get0_serialNumber(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *X509_get_issuer_name(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *X509_get_subject_name(int /*<<< orphan*/ const *);
OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, const X509 *subject,
                             const X509 *issuer) {
  X509_NAME *iname;
  const ASN1_INTEGER *serial;
  ASN1_BIT_STRING *ikey;
  if (!dgst)
    dgst = EVP_sha1();
  if (subject) {
    iname = X509_get_issuer_name(subject);
    serial = X509_get0_serialNumber(subject);
  } else {
    iname = X509_get_subject_name(issuer);
    serial = NULL;
  }
  ikey = X509_get0_pubkey_bitstr(issuer);
  return OCSP_cert_id_new(dgst, iname, ikey, serial);
}


x86 assembly (clang, -O0):
<OCSP_cert_to_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118a <OCSP_cert_to_id+0x2a>
mov    $0x0,%al
call   1050 <EVP_sha1@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b4 <OCSP_cert_to_id+0x54>
mov    -0x10(%rbp),%rdi
call   1070 <X509_get_issuer_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <X509_get0_serialNumber@plt>
mov    %rax,-0x28(%rbp)
jmp    11c9 <OCSP_cert_to_id+0x69>
mov    -0x18(%rbp),%rdi
call   1060 <X509_get_subject_name@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <X509_get0_pubkey_bitstr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1080 <OCSP_cert_id_new@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OCSP_cert_to_id>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
test   %rdi,%rdi
je     1193 <OCSP_cert_to_id+0x33>
test   %rbx,%rbx
je     11a2 <OCSP_cert_to_id+0x42>
mov    %rbx,%rdi
call   1070 <X509_get_issuer_name@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <X509_get0_serialNumber@plt>
mov    %rax,%rbx
jmp    11af <OCSP_cert_to_id+0x4f>
xor    %eax,%eax
call   1050 <EVP_sha1@plt>
mov    %rax,%r15
test   %rbx,%rbx
jne    117b <OCSP_cert_to_id+0x1b>
mov    %r14,%rdi
call   1060 <X509_get_subject_name@plt>
mov    %rax,%r12
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <X509_get0_pubkey_bitstr@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <OCSP_cert_id_new@plt>

LLVM IR (-O0):
define i32* @OCSP_cert_to_id(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32* (...) @EVP_sha1()
store i32* %13, i32** %4
br label %14
14: ; preds = %12, %3
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = call i32* @X509_get_issuer_name(i32* %18)
store i32* %19, i32** %7
%20 = load i32*, i32** %5
%21 = call i32* @X509_get0_serialNumber(i32* %20)
store i32* %21, i32** %8
br label %25
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = call i32* @X509_get_subject_name(i32* %23)
store i32* %24, i32** %7
store i32* null, i32** %8
br label %25
25: ; preds = %22, %17
%26 = load i32*, i32** %6
%27 = call i32* @X509_get0_pubkey_bitstr(i32* %26)
store i32* %27, i32** %9
%28 = load i32*, i32** %4
%29 = load i32*, i32** %7
%30 = load i32*, i32** %9
%31 = load i32*, i32** %8
%32 = call i32* @OCSP_cert_id_new(i32* %28, i32* %29, i32* %30, i32* %31)
ret i32* %32
}

LLVM IR (-O2):
define i32* @OCSP_cert_to_id(i32* %0, i32* %1, i32* %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32* (...) @EVP_sha1()
br label %7
7: ; preds = %5, %3
%8 = phi i32* [ %0, %3 ], [ %6, %5 ]
%9 = icmp eq i32* %1, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32* @X509_get_issuer_name(i32* %1)
%12 = tail call i32* @X509_get0_serialNumber(i32* %1)
br label %15
13: ; preds = %7
%14 = tail call i32* @X509_get_subject_name(i32* %2)
br label %15
15: ; preds = %13, %10
%16 = phi i32* [ %11, %10 ], [ %14, %13 ]
%17 = phi i32* [ %12, %10 ], [ null, %13 ]
%18 = tail call i32* @X509_get0_pubkey_bitstr(i32* %2)
%19 = tail call i32* @OCSP_cert_id_new(i32* %8, i32* %16, i32* %18, i32* %17)
ret i32* %19
}