#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*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ CMS_F_CMS_FINAL;
int /*<<< orphan*/ CMS_R_CMS_DATAFINAL_ERROR;
int /*<<< orphan*/ CMS_R_CMS_LIB;
int /*<<< orphan*/ CMS_dataFinal(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *CMS_dataInit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ CMSerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ SMIME_crlf_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   unsigned int);
int /*<<< orphan*/ do_free_upto(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags) {
  BIO *cmsbio;
  int ret = 0;
  if (!(cmsbio = CMS_dataInit(cms, dcont))) {
    CMSerr(CMS_F_CMS_FINAL, CMS_R_CMS_LIB);
    return 0;
  }
  SMIME_crlf_copy(data, cmsbio, flags);
  (void)BIO_flush(cmsbio);
  if (!CMS_dataFinal(cms, cmsbio)) {
    CMSerr(CMS_F_CMS_FINAL, CMS_R_CMS_DATAFINAL_ERROR);
    goto err;
  }
  ret = 1;
err:
  do_free_upto(cmsbio, dcont);
  return ret;
}


x86 assembly (clang, -O0):
<CMS_final>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <CMS_dataInit@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11bc <CMS_final+0x5c>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1221 <CMS_final+0xc1>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <SMIME_crlf_copy@plt>
mov    -0x30(%rbp),%rdi
call   1080 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <CMS_dataFinal@plt>
cmp    $0x0,%eax
jne    1207 <CMS_final+0xa7>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
jmp    120e <CMS_final+0xae>
movl   $0x1,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <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_final>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %rdx,%rsi
call   1050 <CMS_dataInit@plt>
test   %rax,%rax
je     11d4 <CMS_final+0x74>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1070 <SMIME_crlf_copy@plt>
mov    %rbx,%rdi
call   1080 <BIO_flush@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <CMS_dataFinal@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    11c7 <CMS_final+0x67>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <do_free_upto@plt>
jmp    11ed <CMS_final+0x8d>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CMS_F_CMS_FINAL = global i32 0
@CMS_R_CMS_LIB = global i32 0
@CMS_R_CMS_DATAFINAL_ERROR = global i32 0
define i32 @CMS_final(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
store i32 0, i32* %11
%12 = load i32*, i32** %6
%13 = load i32*, i32** %8
%14 = call i32* @CMS_dataInit(i32* %12, i32* %13)
store i32* %14, i32** %10
%15 = icmp ne i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %4
%17 = load i32, i32* @CMS_F_CMS_FINAL
%18 = load i32, i32* @CMS_R_CMS_LIB
%19 = call i32 @CMSerr(i32 %17, i32 %18)
store i32 0, i32* %5
br label %41
20: ; preds = %4
%21 = load i32*, i32** %7
%22 = load i32*, i32** %10
%23 = load i32, i32* %9
%24 = call i32 @SMIME_crlf_copy(i32* %21, i32* %22, i32 %23)
%25 = load i32*, i32** %10
%26 = call i32 @BIO_flush(i32* %25)
%27 = load i32*, i32** %6
%28 = load i32*, i32** %10
%29 = call i32 @CMS_dataFinal(i32* %27, i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %20
%32 = load i32, i32* @CMS_F_CMS_FINAL
%33 = load i32, i32* @CMS_R_CMS_DATAFINAL_ERROR
%34 = call i32 @CMSerr(i32 %32, i32 %33)
br label %36
35: ; preds = %20
store i32 1, i32* %11
br label %36
36: ; preds = %35, %31
%37 = load i32*, i32** %10
%38 = load i32*, i32** %8
%39 = call i32 @do_free_upto(i32* %37, i32* %38)
%40 = load i32, i32* %11
store i32 %40, i32* %5
br label %41
41: ; preds = %36, %16
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@CMS_F_CMS_FINAL = global i32 0
@CMS_R_CMS_LIB = global i32 0
@CMS_R_CMS_DATAFINAL_ERROR = global i32 0
define i32 @CMS_final(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = tail call i32* @CMS_dataInit(i32* %0, i32* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @CMS_F_CMS_FINAL
%9 = load i32, i32* @CMS_R_CMS_LIB
%10 = tail call i32 @CMSerr(i32 %8, i32 %9)
br label %23
11: ; preds = %4
%12 = tail call i32 @SMIME_crlf_copy(i32* %1, i32* %5, i32 %3)
%13 = tail call i32 @BIO_flush(i32* %5)
%14 = tail call i32 @CMS_dataFinal(i32* %0, i32* %5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @CMS_F_CMS_FINAL
%18 = load i32, i32* @CMS_R_CMS_DATAFINAL_ERROR
%19 = tail call i32 @CMSerr(i32 %17, i32 %18)
br label %20
20: ; preds = %11, %16
%21 = phi i32 [ 0, %16 ], [ 1, %11 ]
%22 = tail call i32 @do_free_upto(i32* %5, i32* %2)
br label %23
23: ; preds = %20, %7
%24 = phi i32 [ %21, %20 ], [ 0, %7 ]
ret i32 %24
}