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

/* Variables and functions */
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ PKCS7_R_PKCS7_DATASIGN;
int /*<<< orphan*/ PKCS7_dataFinal(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *PKCS7_dataInit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ PKCS7error(int /*<<< orphan*/);
int /*<<< orphan*/ SMIME_crlf_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int);
int PKCS7_final(PKCS7 *p7, BIO *data, int flags) {
  BIO *p7bio;
  int ret = 0;
  if (!(p7bio = PKCS7_dataInit(p7, NULL))) {
    PKCS7error(ERR_R_MALLOC_FAILURE);
    return 0;
  }
  SMIME_crlf_copy(data, p7bio, flags);
  (void)BIO_flush(p7bio);
  if (!PKCS7_dataFinal(p7, p7bio)) {
    PKCS7error(PKCS7_R_PKCS7_DATASIGN);
    goto err;
  }
  ret = 1;
err:
  BIO_free_all(p7bio);
  return ret;
}


x86 assembly (clang, -O0):
<PKCS7_final>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <PKCS7_dataInit@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11af <PKCS7_final+0x4f>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <PKCS7error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1207 <PKCS7_final+0xa7>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <SMIME_crlf_copy@plt>
mov    -0x28(%rbp),%rdi
call   1080 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <PKCS7_dataFinal@plt>
cmp    $0x0,%eax
jne    11f1 <PKCS7_final+0x91>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1070 <PKCS7error@plt>
jmp    11f8 <PKCS7_final+0x98>
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <BIO_free_all@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS7_final>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,%r15
xor    %r14d,%r14d
xor    %esi,%esi
call   1030 <PKCS7_dataInit@plt>
test   %rax,%rax
je     11c9 <PKCS7_final+0x69>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1040 <SMIME_crlf_copy@plt>
mov    %rbx,%rdi
call   1080 <BIO_flush@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <PKCS7_dataFinal@plt>
mov    $0x1,%r14d
test   %eax,%eax
jne    11bf <PKCS7_final+0x5f>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1070 <PKCS7error@plt>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1060 <BIO_free_all@plt>
jmp    11d7 <PKCS7_final+0x77>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1070 <PKCS7error@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERR_R_MALLOC_FAILURE = global i32 0
@PKCS7_R_PKCS7_DATASIGN = global i32 0
define i32 @PKCS7_final(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %9
%10 = load i32*, i32** %5
%11 = call i32* @PKCS7_dataInit(i32* %10, i32* null)
store i32* %11, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* @ERR_R_MALLOC_FAILURE
%15 = call i32 @PKCS7error(i32 %14)
store i32 0, i32* %4
br label %35
16: ; preds = %3
%17 = load i32*, i32** %6
%18 = load i32*, i32** %8
%19 = load i32, i32* %7
%20 = call i32 @SMIME_crlf_copy(i32* %17, i32* %18, i32 %19)
%21 = load i32*, i32** %8
%22 = call i32 @BIO_flush(i32* %21)
%23 = load i32*, i32** %5
%24 = load i32*, i32** %8
%25 = call i32 @PKCS7_dataFinal(i32* %23, i32* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %16
%28 = load i32, i32* @PKCS7_R_PKCS7_DATASIGN
%29 = call i32 @PKCS7error(i32 %28)
br label %31
30: ; preds = %16
store i32 1, i32* %9
br label %31
31: ; preds = %30, %27
%32 = load i32*, i32** %8
%33 = call i32 @BIO_free_all(i32* %32)
%34 = load i32, i32* %9
store i32 %34, i32* %4
br label %35
35: ; preds = %31, %13
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@ERR_R_MALLOC_FAILURE = global i32 0
@PKCS7_R_PKCS7_DATASIGN = global i32 0
define i32 @PKCS7_final(i32* %0, i32* %1, i32 %2) {
%4 = tail call i32* @PKCS7_dataInit(i32* %0, i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @ERR_R_MALLOC_FAILURE
%8 = tail call i32 @PKCS7error(i32 %7)
br label %20
9: ; preds = %3
%10 = tail call i32 @SMIME_crlf_copy(i32* %1, i32* %4, i32 %2)
%11 = tail call i32 @BIO_flush(i32* %4)
%12 = tail call i32 @PKCS7_dataFinal(i32* %0, i32* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @PKCS7_R_PKCS7_DATASIGN
%16 = tail call i32 @PKCS7error(i32 %15)
br label %17
17: ; preds = %9, %14
%18 = phi i32 [ 0, %14 ], [ 1, %9 ]
%19 = tail call i32 @BIO_free_all(i32* %4)
br label %20
20: ; preds = %17, %6
%21 = phi i32 [ %18, %17 ], [ 0, %6 ]
ret i32 %21
}