#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_ALGOR;
typedef int /*<<< orphan*/ EVP_MD;

/* Variables and functions */
scalar_t__ EVP_MD_type(int /*<<< orphan*/ const *);
scalar_t__ NID_sha1;
int /*<<< orphan*/ *X509_ALGOR_new();
int /*<<< orphan*/ X509_ALGOR_set_md(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ const *);
int rsa_md_to_algor(X509_ALGOR **palg, const EVP_MD *md) {
  if (EVP_MD_type(md) == NID_sha1)
    return 1;
  *palg = X509_ALGOR_new();
  if (!*palg)
    return 0;
  X509_ALGOR_set_md(*palg, md);
  return 1;
}


x86 assembly (clang, -O0):
<rsa_md_to_algor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <EVP_MD_type@plt>
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%rax
jne    1165 <rsa_md_to_algor+0x35>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <rsa_md_to_algor+0x77>
mov    $0x0,%al
call   1030 <X509_ALGOR_new@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1190 <rsa_md_to_algor+0x60>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <rsa_md_to_algor+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <X509_ALGOR_set_md@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_md_to_algor>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <EVP_MD_type@plt>
mov    0x2e97(%rip),%rcx
mov    $0x1,%ebp
cmp    (%rcx),%rax
je     1174 <rsa_md_to_algor+0x44>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <X509_ALGOR_new@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1174 <rsa_md_to_algor+0x44>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <X509_ALGOR_set_md@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@NID_sha1 = global i64 0
define i32 @rsa_md_to_algor(i32** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32*
store i32** %0, i32*** %4
store i32* %1, i32** %5
%6 = load i32*, i32** %5
%7 = call i64 @EVP_MD_type(i32* %6)
%8 = load i64, i64* @NID_sha1
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %23
11: ; preds = %2
%12 = call i32* (...) @X509_ALGOR_new()
%13 = load i32**, i32*** %4
store i32* %12, i32** %13
%14 = load i32**, i32*** %4
%15 = load i32*, i32** %14
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %11
store i32 0, i32* %3
br label %23
18: ; preds = %11
%19 = load i32**, i32*** %4
%20 = load i32*, i32** %19
%21 = load i32*, i32** %5
%22 = call i32 @X509_ALGOR_set_md(i32* %20, i32* %21)
store i32 1, i32* %3
br label %23
23: ; preds = %18, %17, %10
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@NID_sha1 = global i64 0
define i32 @rsa_md_to_algor(i32** nocapture writeonly %0, i32* %1) {
%3 = tail call i64 @EVP_MD_type(i32* %1)
%4 = load i64, i64* @NID_sha1
%5 = icmp eq i64 %3, %4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32* (...) @X509_ALGOR_new()
store i32* %7, i32** %0
%8 = icmp eq i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @X509_ALGOR_set_md(i32* %7, i32* %1)
br label %11
11: ; preds = %6, %2, %9
%12 = phi i32 [ 1, %9 ], [ 1, %2 ], [ 0, %6 ]
ret i32 %12
}