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

/* Variables and functions */
int /*<<< orphan*/ CMS_ContentInfo_free(int /*<<< orphan*/ *);
unsigned int CMS_DETACHED;
unsigned int CMS_STREAM;
scalar_t__ CMS_final(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *, unsigned int);
int /*<<< orphan*/ CMS_set_detached(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *EVP_sha1();
int /*<<< orphan*/ *cms_DigestedData_create(int /*<<< orphan*/ const *);
CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
                                   unsigned int flags) {
  CMS_ContentInfo *cms;
  if (!md)
    md = EVP_sha1();
  cms = cms_DigestedData_create(md);
  if (!cms)
    return NULL;
  if (!(flags & CMS_DETACHED)) {
    flags &= ~CMS_STREAM;
    CMS_set_detached(cms, 0);
  }
  if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
    return cms;
  CMS_ContentInfo_free(cms);
  return NULL;
}


x86 assembly (clang, -O0):
<CMS_digest_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1179 <CMS_digest_create+0x29>
mov    $0x0,%al
call   1030 <EVP_sha1@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <cms_DigestedData_create@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119e <CMS_digest_create+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    1221 <CMS_digest_create+0xd1>
mov    -0x1c(%rbp),%eax
mov    0x2e50(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11d0 <CMS_digest_create+0x80>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e06(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1203 <CMS_digest_create+0xb3>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edx
call   1060 <CMS_final@plt>
cmp    $0x0,%rax
je     1210 <CMS_digest_create+0xc0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1221 <CMS_digest_create+0xd1>
mov    -0x28(%rbp),%rdi
call   1070 <CMS_ContentInfo_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CMS_digest_create>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
test   %rsi,%rsi
jne    1168 <CMS_digest_create+0x18>
xor    %eax,%eax
call   1030 <EVP_sha1@plt>
mov    %rax,%rsi
mov    %rsi,%rdi
call   1050 <cms_DigestedData_create@plt>
test   %rax,%rax
je     11c1 <CMS_digest_create+0x71>
mov    %rax,%rbx
mov    0x2e79(%rip),%rax
test   %ebp,(%rax)
jne    119a <CMS_digest_create+0x4a>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    0x2e3f(%rip),%rax
test   %ebp,(%rax)
jne    11c3 <CMS_digest_create+0x73>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %ebp,%ecx
call   1060 <CMS_final@plt>
test   %rax,%rax
jne    11c3 <CMS_digest_create+0x73>
mov    %rbx,%rdi
call   1070 <CMS_ContentInfo_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@CMS_DETACHED = global i32 0
@CMS_STREAM = global i32 0
define i32* @CMS_digest_create(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = call i32* (...) @EVP_sha1()
store i32* %12, i32** %6
br label %13
13: ; preds = %11, %3
%14 = load i32*, i32** %6
%15 = call i32* @cms_DigestedData_create(i32* %14)
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %13
store i32* null, i32** %4
br label %47
19: ; preds = %13
%20 = load i32, i32* %7
%21 = load i32, i32* @CMS_DETACHED
%22 = and i32 %20, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %19
%25 = load i32, i32* @CMS_STREAM
%26 = xor i32 %25, -1
%27 = load i32, i32* %7
%28 = and i32 %27, %26
store i32 %28, i32* %7
%29 = load i32*, i32** %8
%30 = call i32 @CMS_set_detached(i32* %29, i32 0)
br label %31
31: ; preds = %24, %19
%32 = load i32, i32* %7
%33 = load i32, i32* @CMS_STREAM
%34 = and i32 %32, %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %31
%37 = load i32*, i32** %8
%38 = load i32*, i32** %5
%39 = load i32, i32* %7
%40 = call i64 @CMS_final(i32* %37, i32* %38, i32* null, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36, %31
%43 = load i32*, i32** %8
store i32* %43, i32** %4
br label %47
44: ; preds = %36
%45 = load i32*, i32** %8
%46 = call i32 @CMS_ContentInfo_free(i32* %45)
store i32* null, i32** %4
br label %47
47: ; preds = %44, %42, %18
%48 = load i32*, i32** %4
ret i32* %48
}

LLVM IR (-O2):
@CMS_DETACHED = global i32 0
@CMS_STREAM = global i32 0
define i32* @CMS_digest_create(i32* %0, i32* %1, i32 %2) {
%4 = icmp eq i32* %1, 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* [ %1, %3 ], [ %6, %5 ]
%9 = tail call i32* @cms_DigestedData_create(i32* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %30, label %11
11: ; preds = %7
%12 = load i32, i32* @CMS_DETACHED
%13 = and i32 %12, %2
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32, i32* @CMS_STREAM
%17 = xor i32 %16, -1
%18 = and i32 %17, %2
%19 = tail call i32 @CMS_set_detached(i32* %9, i32 0)
br label %20
20: ; preds = %15, %11
%21 = phi i32 [ %2, %11 ], [ %18, %15 ]
%22 = load i32, i32* @CMS_STREAM
%23 = and i32 %22, %21
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = tail call i64 @CMS_final(i32* %9, i32* %0, i32* null, i32 %21)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @CMS_ContentInfo_free(i32* %9)
br label %30
30: ; preds = %20, %25, %7, %28
%31 = phi i32* [ null, %28 ], [ null, %7 ], [ %9, %25 ], [ %9, %20 ]
ret i32* %31
}