#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;
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef int /*<<< orphan*/ ASN1_ITEM;

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_pop(int /*<<< orphan*/ *);
scalar_t__ PKCS7_dataFinal(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *PKCS7_dataInit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int SMIME_DETACHED;
int /*<<< orphan*/ SMIME_crlf_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int);
int pk7_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
                    const ASN1_ITEM *it) {
  PKCS7 *p7 = (PKCS7 *)val;
  BIO *tmpbio, *p7bio;
  if (!(flags & SMIME_DETACHED)) {
    SMIME_crlf_copy(data, out, flags);
    return 1;
  }
  p7bio = PKCS7_dataInit(p7, out);
  if (!p7bio)
    return 0;
  SMIME_crlf_copy(data, p7bio, flags);
  if (PKCS7_dataFinal(p7, p7bio) <= 0)
    goto err;
err:
  while (p7bio != out) {
    tmpbio = BIO_pop(p7bio);
    BIO_free(p7bio);
    p7bio = tmpbio;
  }
  return 1;
}


x86 assembly (clang, -O0):
<pk7_output_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e63(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11a4 <pk7_output_data+0x54>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <SMIME_crlf_copy@plt>
movl   $0x1,-0x4(%rbp)
jmp    123a <pk7_output_data+0xea>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <PKCS7_dataInit@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11cc <pk7_output_data+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    123a <pk7_output_data+0xea>
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <SMIME_crlf_copy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <PKCS7_dataFinal@plt>
cmp    $0x0,%rax
jg     11f8 <pk7_output_data+0xa8>
jmp    11fd <pk7_output_data+0xad>
jmp    11fd <pk7_output_data+0xad>
jmp    1202 <pk7_output_data+0xb2>
mov    -0x48(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1233 <pk7_output_data+0xe3>
mov    -0x48(%rbp),%rdi
call   1040 <BIO_pop@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1202 <pk7_output_data+0xb2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pk7_output_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e75(%rip),%rax
test   %ecx,(%rax)
je     11cd <pk7_output_data+0x7d>
mov    %rdx,%r15
mov    %rdx,%rdi
mov    %r13,%rsi
call   1030 <PKCS7_dataInit@plt>
test   %rax,%rax
je     11e3 <pk7_output_data+0x93>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   1060 <SMIME_crlf_copy@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <PKCS7_dataFinal@plt>
mov    $0x1,%r14d
cmp    %r13,%rbp
je     11e6 <pk7_output_data+0x96>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1040 <BIO_pop@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1050 <BIO_free@plt>
mov    %rbx,%rbp
cmp    %r13,%rbx
jne    11b0 <pk7_output_data+0x60>
jmp    11e6 <pk7_output_data+0x96>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1060 <SMIME_crlf_copy@plt>
mov    $0x1,%r14d
jmp    11e6 <pk7_output_data+0x96>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SMIME_DETACHED = global i32 0
define i32 @pk7_output_data(i32* %0, i32* %1, i32* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%15 = load i32*, i32** %9
store i32* %15, i32** %12
%16 = load i32, i32* %10
%17 = load i32, i32* @SMIME_DETACHED
%18 = and i32 %16, %17
%19 = icmp ne i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %5
%21 = load i32*, i32** %8
%22 = load i32*, i32** %7
%23 = load i32, i32* %10
%24 = call i32 @SMIME_crlf_copy(i32* %21, i32* %22, i32 %23)
store i32 1, i32* %6
br label %55
25: ; preds = %5
%26 = load i32*, i32** %12
%27 = load i32*, i32** %7
%28 = call i32* @PKCS7_dataInit(i32* %26, i32* %27)
store i32* %28, i32** %14
%29 = load i32*, i32** %14
%30 = icmp ne i32* %29, null
br i1 %30, label %32, label %31
31: ; preds = %25
store i32 0, i32* %6
br label %55
32: ; preds = %25
%33 = load i32*, i32** %8
%34 = load i32*, i32** %14
%35 = load i32, i32* %10
%36 = call i32 @SMIME_crlf_copy(i32* %33, i32* %34, i32 %35)
%37 = load i32*, i32** %12
%38 = load i32*, i32** %14
%39 = call i64 @PKCS7_dataFinal(i32* %37, i32* %38)
%40 = icmp sle i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %32
br label %43
42: ; preds = %32
br label %43
43: ; preds = %42, %41
br label %44
44: ; preds = %48, %43
%45 = load i32*, i32** %14
%46 = load i32*, i32** %7
%47 = icmp ne i32* %45, %46
br i1 %47, label %48, label %54
48: ; preds = %44
%49 = load i32*, i32** %14
%50 = call i32* @BIO_pop(i32* %49)
store i32* %50, i32** %13
%51 = load i32*, i32** %14
%52 = call i32 @BIO_free(i32* %51)
%53 = load i32*, i32** %13
store i32* %53, i32** %14
br label %44
54: ; preds = %44
store i32 1, i32* %6
br label %55
55: ; preds = %54, %31, %20
%56 = load i32, i32* %6
ret i32 %56
}

LLVM IR (-O2):
@SMIME_DETACHED = global i32 0
define i32 @pk7_output_data(i32* %0, i32* %1, i32* %2, i32 %3, i32* nocapture readnone %4) {
%6 = load i32, i32* @SMIME_DETACHED
%7 = and i32 %6, %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @SMIME_crlf_copy(i32* %1, i32* %0, i32 %3)
br label %23
11: ; preds = %5
%12 = tail call i32* @PKCS7_dataInit(i32* %2, i32* %0)
%13 = icmp eq i32* %12, null
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = tail call i32 @SMIME_crlf_copy(i32* %1, i32* %12, i32 %3)
%16 = tail call i64 @PKCS7_dataFinal(i32* %2, i32* %12)
%17 = icmp eq i32* %12, %0
br i1 %17, label %23, label %18
18: ; preds = %14, %18
%19 = phi i32* [ %20, %18 ], [ %12, %14 ]
%20 = tail call i32* @BIO_pop(i32* %19)
%21 = tail call i32 @BIO_free(i32* %19)
%22 = icmp eq i32* %20, %0
br i1 %22, label %23, label %18
23: ; preds = %18, %14, %11, %9
%24 = phi i32 [ 1, %9 ], [ 0, %11 ], [ 1, %14 ], [ 1, %18 ]
ret i32 %24
}