#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))
    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    120f <CMS_digest_create+0xbf>
mov    -0x1c(%rbp),%eax
mov    0x2e50(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11be <CMS_digest_create+0x6e>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e18(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11f1 <CMS_digest_create+0xa1>
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     11fe <CMS_digest_create+0xae>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120f <CMS_digest_create+0xbf>
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     11b4 <CMS_digest_create+0x64>
mov    %rax,%rbx
mov    0x2e79(%rip),%rax
test   %ebp,(%rax)
jne    118d <CMS_digest_create+0x3d>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    0x2e4c(%rip),%rax
test   %ebp,(%rax)
jne    11b6 <CMS_digest_create+0x66>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %ebp,%ecx
call   1060 <CMS_final@plt>
test   %rax,%rax
jne    11b6 <CMS_digest_create+0x66>
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 %43
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 %27, label %24
24: ; preds = %19
%25 = load i32*, i32** %8
%26 = call i32 @CMS_set_detached(i32* %25, i32 0)
br label %27
27: ; preds = %24, %19
%28 = load i32, i32* %7
%29 = load i32, i32* @CMS_STREAM
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %27
%33 = load i32*, i32** %8
%34 = load i32*, i32** %5
%35 = load i32, i32* %7
%36 = call i64 @CMS_final(i32* %33, i32* %34, i32* null, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32, %27
%39 = load i32*, i32** %8
store i32* %39, i32** %4
br label %43
40: ; preds = %32
%41 = load i32*, i32** %8
%42 = call i32 @CMS_ContentInfo_free(i32* %41)
store i32* null, i32** %4
br label %43
43: ; preds = %40, %38, %18
%44 = load i32*, i32** %4
ret i32* %44
}

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 %26, 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 %17
15: ; preds = %11
%16 = tail call i32 @CMS_set_detached(i32* %9, i32 0)
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* @CMS_STREAM
%19 = and i32 %18, %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = tail call i64 @CMS_final(i32* %9, i32* %0, i32* null, i32 %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @CMS_ContentInfo_free(i32* %9)
br label %26
26: ; preds = %17, %21, %7, %24
%27 = phi i32* [ null, %24 ], [ null, %7 ], [ %9, %21 ], [ %9, %17 ]
ret i32* %27
}