#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ algorithm;
};
typedef TYPE_1__ X509_ALGOR;
typedef int /*<<< orphan*/ EVP_MD;

/* Variables and functions */
int /*<<< orphan*/ *EVP_get_digestbyobj(int /*<<< orphan*/);
int /*<<< orphan*/ const *EVP_sha1();
int /*<<< orphan*/ RSA_F_RSA_ALGOR_TO_MD;
int /*<<< orphan*/ RSA_R_UNKNOWN_DIGEST;
int /*<<< orphan*/ RSAerr(int /*<<< orphan*/, int /*<<< orphan*/);
const EVP_MD *rsa_algor_to_md(X509_ALGOR *alg) {
  const EVP_MD *md;
  if (!alg)
    return EVP_sha1();
  md = EVP_get_digestbyobj(alg->algorithm);
  if (md == NULL)
    RSAerr(RSA_F_RSA_ALGOR_TO_MD, RSA_R_UNKNOWN_DIGEST);
  return md;
}


x86 assembly (clang, -O0):
<rsa_algor_to_md>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <rsa_algor_to_md+0x27>
mov    $0x0,%al
call   1030 <EVP_sha1@plt>
mov    %rax,-0x8(%rbp)
jmp    1190 <rsa_algor_to_md+0x60>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <EVP_get_digestbyobj@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1188 <rsa_algor_to_md+0x58>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_algor_to_md>:
test   %rdi,%rdi
je     1144 <rsa_algor_to_md+0x14>
push   %rax
mov    (%rdi),%edi
call   1040 <EVP_get_digestbyobj@plt>
test   %rax,%rax
je     114b <rsa_algor_to_md+0x1b>
pop    %rcx
ret
xor    %eax,%eax
jmp    1030 <EVP_sha1@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@RSA_F_RSA_ALGOR_TO_MD = global i32 0
@RSA_R_UNKNOWN_DIGEST = global i32 0
define i32* @rsa_algor_to_md(%struct.TYPE_3__* %0) {
%2 = alloca i32*
%3 = alloca %struct.TYPE_3__*
%4 = alloca i32*
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %3
%5 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%6 = icmp ne %struct.TYPE_3__* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32* (...) @EVP_sha1()
store i32* %8, i32** %2
br label %22
9: ; preds = %1
%10 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32* @EVP_get_digestbyobj(i32 %12)
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load i32, i32* @RSA_F_RSA_ALGOR_TO_MD
%18 = load i32, i32* @RSA_R_UNKNOWN_DIGEST
%19 = call i32 @RSAerr(i32 %17, i32 %18)
br label %20
20: ; preds = %16, %9
%21 = load i32*, i32** %4
store i32* %21, i32** %2
br label %22
22: ; preds = %20, %7
%23 = load i32*, i32** %2
ret i32* %23
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@RSA_F_RSA_ALGOR_TO_MD = global i32 0
@RSA_R_UNKNOWN_DIGEST = global i32 0
define i32* @rsa_algor_to_md(%struct.TYPE_3__* %0) {
%2 = icmp eq %struct.TYPE_3__* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32* (...) @EVP_sha1()
br label %14
5: ; preds = %1
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32* @EVP_get_digestbyobj(i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = load i32, i32* @RSA_F_RSA_ALGOR_TO_MD
%12 = load i32, i32* @RSA_R_UNKNOWN_DIGEST
%13 = tail call i32 @RSAerr(i32 %11, i32 %12)
br label %14
14: ; preds = %5, %10, %3
%15 = phi i32* [ %4, %3 ], [ null, %10 ], [ %8, %5 ]
ret i32* %15
}