#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 */
typedef struct TYPE_11__ TYPE_3__;
typedef struct TYPE_10__ TYPE_2__;
typedef struct TYPE_9__ TYPE_1__;

/* Type definitions */
struct TYPE_11__ {
  scalar_t__ (*asn1_cb)(int /*<<< orphan*/, int /*<<< orphan*/ **,
                        TYPE_2__ const *, TYPE_1__ *);
};
struct TYPE_10__ {
  TYPE_3__ *funcs;
};
struct TYPE_9__ {
  int /*<<< orphan*/ *ndef_bio;
  int /*<<< orphan*/ *boundary;
  int /*<<< orphan*/ *out;
};
typedef int /*<<< orphan*/ BIO;
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_1__ ASN1_STREAM_ARG;
typedef TYPE_2__ ASN1_ITEM;
typedef TYPE_3__ ASN1_AUX;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_OUTPUT_DATA;
int /*<<< orphan*/ ASN1_OP_DETACHED_POST;
int /*<<< orphan*/ ASN1_OP_DETACHED_PRE;
int /*<<< orphan*/ ASN1_R_STREAMING_NOT_SUPPORTED;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_pop(int /*<<< orphan*/ *);
int PKCS7_REUSE_DIGEST;
int SMIME_DETACHED;
int /*<<< orphan*/ SMIME_crlf_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int);
scalar_t__ stub1(int /*<<< orphan*/, int /*<<< orphan*/ **, TYPE_2__ const *,
                 TYPE_1__ *);
scalar_t__ stub2(int /*<<< orphan*/, int /*<<< orphan*/ **, TYPE_2__ const *,
                 TYPE_1__ *);
int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
                     const ASN1_ITEM *it) {
  BIO *tmpbio;
  const ASN1_AUX *aux = it->funcs;
  ASN1_STREAM_ARG sarg;
  int rv = 1;
  if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) {
    SMIME_crlf_copy(data, out, flags);
    return 1;
  }
  if (!aux || !aux->asn1_cb) {
    ASN1err(ASN1_F_ASN1_OUTPUT_DATA, ASN1_R_STREAMING_NOT_SUPPORTED);
    return 0;
  }
  sarg.out = out;
  sarg.ndef_bio = NULL;
  sarg.boundary = NULL;
  if (aux->asn1_cb(ASN1_OP_DETACHED_PRE, &val, it, &sarg) <= 0)
    return 0;
  SMIME_crlf_copy(data, sarg.ndef_bio, flags);
  if (aux->asn1_cb(ASN1_OP_DETACHED_POST, &val, it, &sarg) <= 0)
    rv = 0;
  while (sarg.ndef_bio != out) {
    tmpbio = BIO_pop(sarg.ndef_bio);
    BIO_free(sarg.ndef_bio);
    sarg.ndef_bio = tmpbio;
  }
  return rv;
}


x86 assembly (clang, -O0):
<asn1_output_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e51(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1197 <asn1_output_data+0x57>
mov    -0x24(%rbp),%eax
mov    0x2e34(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b3 <asn1_output_data+0x73>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <SMIME_crlf_copy@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <asn1_output_data+0x176>
cmpq   $0x0,-0x40(%rbp)
je     11cc <asn1_output_data+0x8c>
mov    -0x40(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ef <asn1_output_data+0xaf>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b6 <asn1_output_data+0x176>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2dbb(%rip),%rcx
mov    (%rcx),%edi
mov    -0x30(%rbp),%rdx
lea    -0x20(%rbp),%rsi
lea    -0x58(%rbp),%rcx
call   *%rax
cmp    $0x0,%rax
jg     123b <asn1_output_data+0xfb>
movl   $0x0,-0x4(%rbp)
jmp    12b6 <asn1_output_data+0x176>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <SMIME_crlf_copy@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2d97(%rip),%rcx
mov    (%rcx),%edi
mov    -0x30(%rbp),%rdx
lea    -0x20(%rbp),%rsi
lea    -0x58(%rbp),%rcx
call   *%rax
cmp    $0x0,%rax
jg     127a <asn1_output_data+0x13a>
movl   $0x0,-0x5c(%rbp)
jmp    127f <asn1_output_data+0x13f>
mov    -0x58(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     12b0 <asn1_output_data+0x170>
mov    -0x58(%rbp),%rdi
call   1040 <BIO_pop@plt>
mov    %rax,-0x38(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    127f <asn1_output_data+0x13f>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_output_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%ebp
mov    %rsi,%r15
mov    %rdi,%r13
mov    %rdx,0x8(%rsp)
mov    0x2e66(%rip),%rax
test   %ecx,(%rax)
je     1171 <asn1_output_data+0x31>
mov    0x2e53(%rip),%rax
test   %ebp,(%rax)
je     1192 <asn1_output_data+0x52>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <SMIME_crlf_copy@plt>
mov    $0x1,%bl
movzbl %bl,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r8,%r14
mov    (%r8),%r12
test   %r12,%r12
je     1244 <asn1_output_data+0x104>
mov    (%r12),%rax
test   %rax,%rax
je     1244 <asn1_output_data+0x104>
mov    %r13,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %r14,%rdx
call   *%rax
test   %rax,%rax
jle    125b <asn1_output_data+0x11b>
mov    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
call   1060 <SMIME_crlf_copy@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %r14,%rdx
call   *(%r12)
test   %rax,%rax
setg   %bl
mov    0x10(%rsp),%rbp
cmp    %r13,%rbp
je     1180 <asn1_output_data+0x40>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1040 <BIO_pop@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rdi
call   1050 <BIO_free@plt>
mov    %rbp,0x10(%rsp)
cmp    %r13,%rbp
jne    1220 <asn1_output_data+0xe0>
jmp    1180 <asn1_output_data+0x40>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
xor    %ebx,%ebx
jmp    1180 <asn1_output_data+0x40>

LLVM IR (-O0):
%struct.TYPE_10__ = type { %struct.TYPE_11__* }
%struct.TYPE_11__ = type { i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)* }
%struct.TYPE_9__ = type { i32*, i32*, i32* }
@SMIME_DETACHED = global i32 0
@PKCS7_REUSE_DIGEST = global i32 0
@ASN1_F_ASN1_OUTPUT_DATA = global i32 0
@ASN1_R_STREAMING_NOT_SUPPORTED = global i32 0
@ASN1_OP_DETACHED_PRE = global i32 0
@ASN1_OP_DETACHED_POST = global i32 0
define i32 @asn1_output_data(i32* %0, i32* %1, i32* %2, i32 %3, %struct.TYPE_10__* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca %struct.TYPE_10__*
%12 = alloca i32*
%13 = alloca %struct.TYPE_11__*
%14 = alloca %struct.TYPE_9__
%15 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store %struct.TYPE_10__* %4, %struct.TYPE_10__** %11
%16 = load %struct.TYPE_10__*, %struct.TYPE_10__** %11
%17 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %16, i32 0, i32 0
%18 = load %struct.TYPE_11__*, %struct.TYPE_11__** %17
store %struct.TYPE_11__* %18, %struct.TYPE_11__** %13
store i32 1, i32* %15
%19 = load i32, i32* %10
%20 = load i32, i32* @SMIME_DETACHED
%21 = and i32 %19, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %5
%24 = load i32, i32* %10
%25 = load i32, i32* @PKCS7_REUSE_DIGEST
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23, %5
%29 = load i32*, i32** %8
%30 = load i32*, i32** %7
%31 = load i32, i32* %10
%32 = call i32 @SMIME_crlf_copy(i32* %29, i32* %30, i32 %31)
store i32 1, i32* %6
br label %89
33: ; preds = %23
%34 = load %struct.TYPE_11__*, %struct.TYPE_11__** %13
%35 = icmp ne %struct.TYPE_11__* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load %struct.TYPE_11__*, %struct.TYPE_11__** %13
%38 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %37, i32 0, i32 0
%39 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %38
%40 = icmp ne i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)* %39, null
br i1 %40, label %45, label %41
41: ; preds = %36, %33
%42 = load i32, i32* @ASN1_F_ASN1_OUTPUT_DATA
%43 = load i32, i32* @ASN1_R_STREAMING_NOT_SUPPORTED
%44 = call i32 @ASN1err(i32 %42, i32 %43)
store i32 0, i32* %6
br label %89
45: ; preds = %36
%46 = load i32*, i32** %7
%47 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 2
store i32* %46, i32** %47
%48 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
store i32* null, i32** %48
%49 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 1
store i32* null, i32** %49
%50 = load %struct.TYPE_11__*, %struct.TYPE_11__** %13
%51 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %50, i32 0, i32 0
%52 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %51
%53 = load i32, i32* @ASN1_OP_DETACHED_PRE
%54 = load %struct.TYPE_10__*, %struct.TYPE_10__** %11
%55 = call i64 %52(i32 %53, i32** %9, %struct.TYPE_10__* %54, %struct.TYPE_9__* %14)
%56 = icmp sle i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %45
store i32 0, i32* %6
br label %89
58: ; preds = %45
%59 = load i32*, i32** %8
%60 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%61 = load i32*, i32** %60
%62 = load i32, i32* %10
%63 = call i32 @SMIME_crlf_copy(i32* %59, i32* %61, i32 %62)
%64 = load %struct.TYPE_11__*, %struct.TYPE_11__** %13
%65 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %64, i32 0, i32 0
%66 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %65
%67 = load i32, i32* @ASN1_OP_DETACHED_POST
%68 = load %struct.TYPE_10__*, %struct.TYPE_10__** %11
%69 = call i64 %66(i32 %67, i32** %9, %struct.TYPE_10__* %68, %struct.TYPE_9__* %14)
%70 = icmp sle i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %58
store i32 0, i32* %15
br label %72
72: ; preds = %71, %58
br label %73
73: ; preds = %78, %72
%74 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%75 = load i32*, i32** %74
%76 = load i32*, i32** %7
%77 = icmp ne i32* %75, %76
br i1 %77, label %78, label %87
78: ; preds = %73
%79 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%80 = load i32*, i32** %79
%81 = call i32* @BIO_pop(i32* %80)
store i32* %81, i32** %12
%82 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%83 = load i32*, i32** %82
%84 = call i32 @BIO_free(i32* %83)
%85 = load i32*, i32** %12
%86 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
store i32* %85, i32** %86
br label %73
87: ; preds = %73
%88 = load i32, i32* %15
store i32 %88, i32* %6
br label %89
89: ; preds = %87, %57, %41, %28
%90 = load i32, i32* %6
ret i32 %90
}

LLVM IR (-O2):
%struct.TYPE_10__ = type { %struct.TYPE_11__* }
%struct.TYPE_11__ = type { i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)* }
%struct.TYPE_9__ = type { i32*, i32*, i32* }
@SMIME_DETACHED = global i32 0
@PKCS7_REUSE_DIGEST = global i32 0
@ASN1_F_ASN1_OUTPUT_DATA = global i32 0
@ASN1_R_STREAMING_NOT_SUPPORTED = global i32 0
@ASN1_OP_DETACHED_PRE = global i32 0
@ASN1_OP_DETACHED_POST = global i32 0
define i32 @asn1_output_data(i32* %0, i32* %1, i32* %2, i32 %3, %struct.TYPE_10__* %4) {
%6 = alloca i32*
%7 = alloca %struct.TYPE_9__
store i32* %2, i32** %6
%8 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %4, i64 0, i32 0
%9 = load %struct.TYPE_11__*, %struct.TYPE_11__** %8
%10 = bitcast %struct.TYPE_9__* %7 to i8*
%11 = load i32, i32* @SMIME_DETACHED
%12 = and i32 %11, %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %5
%15 = load i32, i32* @PKCS7_REUSE_DIGEST
%16 = and i32 %15, %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14, %5
%19 = tail call i32 @SMIME_crlf_copy(i32* %1, i32* %0, i32 %3)
br label %52
20: ; preds = %14
%21 = icmp eq %struct.TYPE_11__* %9, null
br i1 %21, label %26, label %22
22: ; preds = %20
%23 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %9, i64 0, i32 0
%24 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %23
%25 = icmp eq i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)* %24, null
br i1 %25, label %26, label %30
26: ; preds = %22, %20
%27 = load i32, i32* @ASN1_F_ASN1_OUTPUT_DATA
%28 = load i32, i32* @ASN1_R_STREAMING_NOT_SUPPORTED
%29 = tail call i32 @ASN1err(i32 %27, i32 %28)
br label %52
30: ; preds = %22
%31 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %7, i64 0, i32 2
store i32* %0, i32** %31
%32 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %7, i64 0, i32 0
%33 = bitcast %struct.TYPE_9__* %7 to i8*
%34 = load i32, i32* @ASN1_OP_DETACHED_PRE
%35 = call i64 %24(i32 %34, i32** %6, %struct.TYPE_10__* %4, %struct.TYPE_9__* %7)
%36 = icmp slt i64 %35, 1
br i1 %36, label %52, label %37
37: ; preds = %30
%38 = load i32*, i32** %32
%39 = call i32 @SMIME_crlf_copy(i32* %1, i32* %38, i32 %3)
%40 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %23
%41 = load i32, i32* @ASN1_OP_DETACHED_POST
%42 = call i64 %40(i32 %41, i32** %6, %struct.TYPE_10__* %4, %struct.TYPE_9__* %7)
%43 = icmp sgt i64 %42, 0
%44 = load i32*, i32** %32
%45 = icmp eq i32* %44, %0
br i1 %45, label %52, label %46
46: ; preds = %37, %46
%47 = phi i32* [ %48, %46 ], [ %44, %37 ]
%48 = call i32* @BIO_pop(i32* %47)
%49 = load i32*, i32** %32
%50 = call i32 @BIO_free(i32* %49)
store i32* %48, i32** %32
%51 = icmp eq i32* %48, %0
br i1 %51, label %52, label %46
52: ; preds = %46, %37, %30, %26, %18
%53 = phi i1 [ true, %18 ], [ false, %26 ], [ false, %30 ], [ %43, %37 ], [ %43, %46 ]
%54 = zext i1 %53 to i32
ret i32 %54
}