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

/* Variables and functions */
int /*<<< orphan*/ BIO_f_md();
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_set_md(int /*<<< orphan*/ *, int /*<<< orphan*/ const *);
int /*<<< orphan*/ ERR_R_BIO_LIB;
int /*<<< orphan*/ *EVP_get_digestbyobj(int /*<<< orphan*/);
int /*<<< orphan*/ PKCS7_R_UNKNOWN_DIGEST_TYPE;
int /*<<< orphan*/ PKCS7error(int /*<<< orphan*/);
int PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg) {
  BIO *btmp;
  const EVP_MD *md;
  if ((btmp = BIO_new(BIO_f_md())) == NULL) {
    PKCS7error(ERR_R_BIO_LIB);
    goto err;
  }
  md = EVP_get_digestbyobj(alg->algorithm);
  if (md == NULL) {
    PKCS7error(PKCS7_R_UNKNOWN_DIGEST_TYPE);
    goto err;
  }
  BIO_set_md(btmp, md);
  if (*pbio == NULL)
    *pbio = btmp;
  else if (!BIO_push(*pbio, btmp)) {
    PKCS7error(ERR_R_BIO_LIB);
    goto err;
  }
  btmp = NULL;
  return 1;
err:
  BIO_free(btmp);
  return 0;
}


x86 assembly (clang, -O0):
<PKCS7_bio_add_digest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1030 <BIO_f_md@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11af <PKCS7_bio_add_digest+0x3f>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1090 <PKCS7error@plt>
jmp    124c <PKCS7_bio_add_digest+0xdc>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <EVP_get_digestbyobj@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dc <PKCS7_bio_add_digest+0x6c>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1090 <PKCS7error@plt>
jmp    124c <PKCS7_bio_add_digest+0xdc>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <BIO_set_md@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1207 <PKCS7_bio_add_digest+0x97>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1238 <PKCS7_bio_add_digest+0xc8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <BIO_push@plt>
cmp    $0x0,%eax
jne    1233 <PKCS7_bio_add_digest+0xc3>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1090 <PKCS7error@plt>
jmp    124c <PKCS7_bio_add_digest+0xdc>
jmp    1238 <PKCS7_bio_add_digest+0xc8>
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x4(%rbp)
jmp    125c <PKCS7_bio_add_digest+0xec>
mov    -0x20(%rbp),%rdi
call   1080 <BIO_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS7_bio_add_digest>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <BIO_f_md@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2e42(%rip),%r12
test   %rax,%rax
je     11d7 <PKCS7_bio_add_digest+0x67>
mov    (%r15),%edi
call   1060 <EVP_get_digestbyobj@plt>
test   %rax,%rax
je     11d0 <PKCS7_bio_add_digest+0x60>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <BIO_set_md@plt>
mov    (%r14),%rdi
test   %rdi,%rdi
je     11f6 <PKCS7_bio_add_digest+0x86>
mov    %rbx,%rsi
call   1050 <BIO_push@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    11ea <PKCS7_bio_add_digest+0x7a>
jmp    11d7 <PKCS7_bio_add_digest+0x67>
mov    0x2e11(%rip),%r12
mov    (%r12),%edi
call   1090 <PKCS7error@plt>
mov    %rbx,%rdi
call   1080 <BIO_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    11ea <PKCS7_bio_add_digest+0x7a>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@ERR_R_BIO_LIB = global i32 0
@PKCS7_R_UNKNOWN_DIGEST_TYPE = global i32 0
define i32 @PKCS7_bio_add_digest(i32** %0, %struct.TYPE_3__* %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca %struct.TYPE_3__*
%6 = alloca i32*
%7 = alloca i32*
store i32** %0, i32*** %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
%8 = call i32 (...) @BIO_f_md()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @ERR_R_BIO_LIB
%13 = call i32 @PKCS7error(i32 %12)
br label %45
14: ; preds = %2
%15 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32* @EVP_get_digestbyobj(i32 %17)
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* @PKCS7_R_UNKNOWN_DIGEST_TYPE
%23 = call i32 @PKCS7error(i32 %22)
br label %45
24: ; preds = %14
%25 = load i32*, i32** %6
%26 = load i32*, i32** %7
%27 = call i32 @BIO_set_md(i32* %25, i32* %26)
%28 = load i32**, i32*** %4
%29 = load i32*, i32** %28
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32*, i32** %6
%33 = load i32**, i32*** %4
store i32* %32, i32** %33
br label %44
34: ; preds = %24
%35 = load i32**, i32*** %4
%36 = load i32*, i32** %35
%37 = load i32*, i32** %6
%38 = call i32 @BIO_push(i32* %36, i32* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = load i32, i32* @ERR_R_BIO_LIB
%42 = call i32 @PKCS7error(i32 %41)
br label %45
43: ; preds = %34
br label %44
44: ; preds = %43, %31
store i32* null, i32** %6
store i32 1, i32* %3
br label %48
45: ; preds = %40, %21, %11
%46 = load i32*, i32** %6
%47 = call i32 @BIO_free(i32* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %45, %44
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@ERR_R_BIO_LIB = global i32 0
@PKCS7_R_UNKNOWN_DIGEST_TYPE = global i32 0
define i32 @PKCS7_bio_add_digest(i32** nocapture %0, %struct.TYPE_3__* nocapture %1) {
%3 = tail call i32 (...) @BIO_f_md()
%4 = tail call i32* @BIO_new(i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32* @EVP_get_digestbyobj(i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = tail call i32 @BIO_set_md(i32* %4, i32* %9)
%13 = load i32*, i32** %0
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
store i32* %4, i32** %0
br label %24
16: ; preds = %11
%17 = tail call i32 @BIO_push(i32* %13, i32* %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16, %6, %2
%20 = phi i32* [ @ERR_R_BIO_LIB, %2 ], [ @PKCS7_R_UNKNOWN_DIGEST_TYPE, %6 ], [ @ERR_R_BIO_LIB, %16 ]
%21 = load i32, i32* %20
%22 = tail call i32 @PKCS7error(i32 %21)
%23 = tail call i32 @BIO_free(i32* %4)
br label %24
24: ; preds = %15, %16, %19
%25 = phi i32 [ 0, %19 ], [ 1, %16 ], [ 1, %15 ]
ret i32 %25
}