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

/* Variables and functions */
int /*<<< orphan*/ CMS_F_CMS_DIGEST_VERIFY;
int /*<<< orphan*/ CMS_R_TYPE_NOT_DIGESTED_DATA;
int /*<<< orphan*/ *CMS_dataInit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ CMS_get0_type(int /*<<< orphan*/ *);
int /*<<< orphan*/ CMSerr(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ NID_pkcs7_digest;
scalar_t__ OBJ_obj2nid(int /*<<< orphan*/);
int /*<<< orphan*/ check_content(int /*<<< orphan*/ *);
int cms_DigestedData_do_final(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int cms_copy_content(int /*<<< orphan*/ *, int /*<<< orphan*/ *, unsigned int);
int /*<<< orphan*/ do_free_upto(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
                      unsigned int flags) {
  BIO *cont;
  int r;
  if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest) {
    CMSerr(CMS_F_CMS_DIGEST_VERIFY, CMS_R_TYPE_NOT_DIGESTED_DATA);
    return 0;
  }
  if (!dcont && !check_content(cms))
    return 0;
  cont = CMS_dataInit(cms, dcont);
  if (!cont)
    return 0;
  r = cms_copy_content(out, cont, flags);
  if (r)
    r = cms_DigestedData_do_final(cms, cont, 1);
  do_free_upto(cont, dcont);
  return r;
}


x86 assembly (clang, -O0):
<CMS_digest_verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <CMS_get0_type@plt>
mov    %eax,%edi
call   1030 <OBJ_obj2nid@plt>
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
je     11da <CMS_digest_verify+0x5a>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1050 <CMSerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <CMS_digest_verify+0xf0>
cmpq   $0x0,-0x18(%rbp)
jne    1203 <CMS_digest_verify+0x83>
mov    -0x10(%rbp),%rdi
call   1080 <check_content@plt>
cmp    $0x0,%eax
jne    1203 <CMS_digest_verify+0x83>
movl   $0x0,-0x4(%rbp)
jmp    1270 <CMS_digest_verify+0xf0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <CMS_dataInit@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122b <CMS_digest_verify+0xab>
movl   $0x0,-0x4(%rbp)
jmp    1270 <CMS_digest_verify+0xf0>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1090 <cms_copy_content@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     125d <CMS_digest_verify+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x1,%edx
call   1040 <cms_DigestedData_do_final@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <do_free_upto@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CMS_digest_verify>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   10a0 <CMS_get0_type@plt>
mov    %eax,%edi
call   1030 <OBJ_obj2nid@plt>
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
jne    11f6 <CMS_digest_verify+0x76>
test   %r14,%r14
jne    11bd <CMS_digest_verify+0x3d>
mov    %rbx,%rdi
call   1080 <check_content@plt>
test   %eax,%eax
je     120d <CMS_digest_verify+0x8d>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <CMS_dataInit@plt>
test   %rax,%rax
je     120d <CMS_digest_verify+0x8d>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1090 <cms_copy_content@plt>
test   %eax,%eax
je     1211 <CMS_digest_verify+0x91>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <cms_DigestedData_do_final@plt>
mov    %eax,%ebx
jmp    1213 <CMS_digest_verify+0x93>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
call   1050 <CMSerr@plt>
xor    %ebx,%ebx
jmp    121e <CMS_digest_verify+0x9e>
xor    %ebx,%ebx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <do_free_upto@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NID_pkcs7_digest = global i64 0
@CMS_F_CMS_DIGEST_VERIFY = global i32 0
@CMS_R_TYPE_NOT_DIGESTED_DATA = global i32 0
define i32 @CMS_digest_verify(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%12 = load i32*, i32** %6
%13 = call i32 @CMS_get0_type(i32* %12)
%14 = call i64 @OBJ_obj2nid(i32 %13)
%15 = load i64, i64* @NID_pkcs7_digest
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32, i32* @CMS_F_CMS_DIGEST_VERIFY
%19 = load i32, i32* @CMS_R_TYPE_NOT_DIGESTED_DATA
%20 = call i32 @CMSerr(i32 %18, i32 %19)
store i32 0, i32* %5
br label %52
21: ; preds = %4
%22 = load i32*, i32** %7
%23 = icmp ne i32* %22, null
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = load i32*, i32** %6
%26 = call i32 @check_content(i32* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %24
store i32 0, i32* %5
br label %52
29: ; preds = %24, %21
%30 = load i32*, i32** %6
%31 = load i32*, i32** %7
%32 = call i32* @CMS_dataInit(i32* %30, i32* %31)
store i32* %32, i32** %10
%33 = load i32*, i32** %10
%34 = icmp ne i32* %33, null
br i1 %34, label %36, label %35
35: ; preds = %29
store i32 0, i32* %5
br label %52
36: ; preds = %29
%37 = load i32*, i32** %8
%38 = load i32*, i32** %10
%39 = load i32, i32* %9
%40 = call i32 @cms_copy_content(i32* %37, i32* %38, i32 %39)
store i32 %40, i32* %11
%41 = load i32, i32* %11
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32*, i32** %6
%45 = load i32*, i32** %10
%46 = call i32 @cms_DigestedData_do_final(i32* %44, i32* %45, i32 1)
store i32 %46, i32* %11
br label %47
47: ; preds = %43, %36
%48 = load i32*, i32** %10
%49 = load i32*, i32** %7
%50 = call i32 @do_free_upto(i32* %48, i32* %49)
%51 = load i32, i32* %11
store i32 %51, i32* %5
br label %52
52: ; preds = %47, %35, %28, %17
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
@NID_pkcs7_digest = global i64 0
@CMS_F_CMS_DIGEST_VERIFY = global i32 0
@CMS_R_TYPE_NOT_DIGESTED_DATA = global i32 0
define i32 @CMS_digest_verify(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = tail call i32 @CMS_get0_type(i32* %0)
%6 = tail call i64 @OBJ_obj2nid(i32 %5)
%7 = load i64, i64* @NID_pkcs7_digest
%8 = icmp eq i64 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = load i32, i32* @CMS_F_CMS_DIGEST_VERIFY
%11 = load i32, i32* @CMS_R_TYPE_NOT_DIGESTED_DATA
%12 = tail call i32 @CMSerr(i32 %10, i32 %11)
br label %29
13: ; preds = %4
%14 = icmp eq i32* %1, null
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = tail call i32 @check_content(i32* %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %29, label %18
18: ; preds = %15, %13
%19 = tail call i32* @CMS_dataInit(i32* %0, i32* %1)
%20 = icmp eq i32* %19, null
br i1 %20, label %29, label %21
21: ; preds = %18
%22 = tail call i32 @cms_copy_content(i32* %2, i32* %19, i32 %3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @cms_DigestedData_do_final(i32* %0, i32* %19, i32 1)
br label %26
26: ; preds = %24, %21
%27 = phi i32 [ %25, %24 ], [ 0, %21 ]
%28 = tail call i32 @do_free_upto(i32* %19, i32* %1)
br label %29
29: ; preds = %18, %15, %26, %9
%30 = phi i32 [ 0, %9 ], [ %27, %26 ], [ 0, %15 ], [ 0, %18 ]
ret i32 %30
}