#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_F_PKCS7_FINAL;
int /*<<< orphan*/ PKCS7_R_PKCS7_DATASIGN;
int /*<<< orphan*/ PKCS7_dataFinal(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *PKCS7_dataInit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ PKCS7err(int /*<<< orphan*/, 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))) {
    PKCS7err(PKCS7_F_PKCS7_FINAL, ERR_R_MALLOC_FAILURE);
    return 0;
  }
  SMIME_crlf_copy(data, p7bio, flags);
  (void)BIO_flush(p7bio);
  if (!PKCS7_dataFinal(p7, p7bio)) {
    PKCS7err(PKCS7_F_PKCS7_FINAL, 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    11b8 <PKCS7_final+0x58>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1040 <PKCS7err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1219 <PKCS7_final+0xb9>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <SMIME_crlf_copy@plt>
mov    -0x28(%rbp),%rdi
call   1080 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <PKCS7_dataFinal@plt>
cmp    $0x0,%eax
jne    1203 <PKCS7_final+0xa3>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1040 <PKCS7err@plt>
jmp    120a <PKCS7_final+0xaa>
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <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     11d2 <PKCS7_final+0x72>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1050 <SMIME_crlf_copy@plt>
mov    %rbx,%rdi
call   1080 <BIO_flush@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <PKCS7_dataFinal@plt>
mov    $0x1,%r14d
test   %eax,%eax
jne    11c8 <PKCS7_final+0x68>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1040 <PKCS7err@plt>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1070 <BIO_free_all@plt>
jmp    11e9 <PKCS7_final+0x89>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   1040 <PKCS7err@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PKCS7_F_PKCS7_FINAL = global i32 0
@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 %17, label %13
13: ; preds = %3
%14 = load i32, i32* @PKCS7_F_PKCS7_FINAL
%15 = load i32, i32* @ERR_R_MALLOC_FAILURE
%16 = call i32 @PKCS7err(i32 %14, i32 %15)
store i32 0, i32* %4
br label %37
17: ; preds = %3
%18 = load i32*, i32** %6
%19 = load i32*, i32** %8
%20 = load i32, i32* %7
%21 = call i32 @SMIME_crlf_copy(i32* %18, i32* %19, i32 %20)
%22 = load i32*, i32** %8
%23 = call i32 @BIO_flush(i32* %22)
%24 = load i32*, i32** %5
%25 = load i32*, i32** %8
%26 = call i32 @PKCS7_dataFinal(i32* %24, i32* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %17
%29 = load i32, i32* @PKCS7_F_PKCS7_FINAL
%30 = load i32, i32* @PKCS7_R_PKCS7_DATASIGN
%31 = call i32 @PKCS7err(i32 %29, i32 %30)
br label %33
32: ; preds = %17
store i32 1, i32* %9
br label %33
33: ; preds = %32, %28
%34 = load i32*, i32** %8
%35 = call i32 @BIO_free_all(i32* %34)
%36 = load i32, i32* %9
store i32 %36, i32* %4
br label %37
37: ; preds = %33, %13
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@PKCS7_F_PKCS7_FINAL = global i32 0
@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 %10
6: ; preds = %3
%7 = load i32, i32* @PKCS7_F_PKCS7_FINAL
%8 = load i32, i32* @ERR_R_MALLOC_FAILURE
%9 = tail call i32 @PKCS7err(i32 %7, i32 %8)
br label %22
10: ; preds = %3
%11 = tail call i32 @SMIME_crlf_copy(i32* %1, i32* %4, i32 %2)
%12 = tail call i32 @BIO_flush(i32* %4)
%13 = tail call i32 @PKCS7_dataFinal(i32* %0, i32* %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @PKCS7_F_PKCS7_FINAL
%17 = load i32, i32* @PKCS7_R_PKCS7_DATASIGN
%18 = tail call i32 @PKCS7err(i32 %16, i32 %17)
br label %19
19: ; preds = %10, %15
%20 = phi i32 [ 0, %15 ], [ 1, %10 ]
%21 = tail call i32 @BIO_free_all(i32* %4)
br label %22
22: ; preds = %19, %6
%23 = phi i32 [ %20, %19 ], [ 0, %6 ]
ret i32 %23
}