#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_OP_DETACHED_POST;
int /*<<< orphan*/ ASN1_OP_DETACHED_PRE;
int /*<<< orphan*/ ASN1_R_STREAMING_NOT_SUPPORTED;
int /*<<< orphan*/ ASN1error(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) {
    ASN1error(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    0x2e59(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1197 <asn1_output_data+0x57>
mov    -0x24(%rbp),%eax
mov    0x2e3c(%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   1050 <SMIME_crlf_copy@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ad <asn1_output_data+0x16d>
cmpq   $0x0,-0x40(%rbp)
je     11cc <asn1_output_data+0x8c>
mov    -0x40(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11e6 <asn1_output_data+0xa6>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ad <asn1_output_data+0x16d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2dcc(%rip),%rcx
mov    (%rcx),%edi
mov    -0x30(%rbp),%rdx
lea    -0x20(%rbp),%rsi
lea    -0x58(%rbp),%rcx
call   *%rax
cmp    $0x0,%rax
jg     1232 <asn1_output_data+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    12ad <asn1_output_data+0x16d>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <SMIME_crlf_copy@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2da0(%rip),%rcx
mov    (%rcx),%edi
mov    -0x30(%rbp),%rdx
lea    -0x20(%rbp),%rsi
lea    -0x58(%rbp),%rcx
call   *%rax
cmp    $0x0,%rax
jg     1271 <asn1_output_data+0x131>
movl   $0x0,-0x5c(%rbp)
jmp    1276 <asn1_output_data+0x136>
mov    -0x58(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     12a7 <asn1_output_data+0x167>
mov    -0x58(%rbp),%rdi
call   1030 <BIO_pop@plt>
mov    %rax,-0x38(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <BIO_free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    1276 <asn1_output_data+0x136>
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    0x2e6e(%rip),%rax
test   %ecx,(%rax)
je     1171 <asn1_output_data+0x31>
mov    0x2e5b(%rip),%rax
test   %ebp,(%rax)
je     1192 <asn1_output_data+0x52>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1050 <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    0x2e16(%rip),%rcx
mov    (%rcx),%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %r14,%rdx
call   *%rax
test   %rax,%rax
jle    1252 <asn1_output_data+0x112>
mov    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
call   1050 <SMIME_crlf_copy@plt>
mov    0x2e02(%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>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1030 <BIO_pop@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rdi
call   1040 <BIO_free@plt>
mov    %rbp,0x10(%rsp)
cmp    %r13,%rbp
jne    1220 <asn1_output_data+0xe0>
jmp    1180 <asn1_output_data+0x40>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@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_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 %88
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 %44, label %41
41: ; preds = %36, %33
%42 = load i32, i32* @ASN1_R_STREAMING_NOT_SUPPORTED
%43 = call i32 @ASN1error(i32 %42)
store i32 0, i32* %6
br label %88
44: ; preds = %36
%45 = load i32*, i32** %7
%46 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 2
store i32* %45, i32** %46
%47 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
store i32* null, i32** %47
%48 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 1
store i32* null, i32** %48
%49 = load %struct.TYPE_11__*, %struct.TYPE_11__** %13
%50 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %49, i32 0, i32 0
%51 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %50
%52 = load i32, i32* @ASN1_OP_DETACHED_PRE
%53 = load %struct.TYPE_10__*, %struct.TYPE_10__** %11
%54 = call i64 %51(i32 %52, i32** %9, %struct.TYPE_10__* %53, %struct.TYPE_9__* %14)
%55 = icmp sle i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %44
store i32 0, i32* %6
br label %88
57: ; preds = %44
%58 = load i32*, i32** %8
%59 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%60 = load i32*, i32** %59
%61 = load i32, i32* %10
%62 = call i32 @SMIME_crlf_copy(i32* %58, i32* %60, i32 %61)
%63 = load %struct.TYPE_11__*, %struct.TYPE_11__** %13
%64 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %63, i32 0, i32 0
%65 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %64
%66 = load i32, i32* @ASN1_OP_DETACHED_POST
%67 = load %struct.TYPE_10__*, %struct.TYPE_10__** %11
%68 = call i64 %65(i32 %66, i32** %9, %struct.TYPE_10__* %67, %struct.TYPE_9__* %14)
%69 = icmp sle i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %57
store i32 0, i32* %15
br label %71
71: ; preds = %70, %57
br label %72
72: ; preds = %77, %71
%73 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%74 = load i32*, i32** %73
%75 = load i32*, i32** %7
%76 = icmp ne i32* %74, %75
br i1 %76, label %77, label %86
77: ; preds = %72
%78 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%79 = load i32*, i32** %78
%80 = call i32* @BIO_pop(i32* %79)
store i32* %80, i32** %12
%81 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
%82 = load i32*, i32** %81
%83 = call i32 @BIO_free(i32* %82)
%84 = load i32*, i32** %12
%85 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %14, i32 0, i32 0
store i32* %84, i32** %85
br label %72
86: ; preds = %72
%87 = load i32, i32* %15
store i32 %87, i32* %6
br label %88
88: ; preds = %86, %56, %41, %28
%89 = load i32, i32* %6
ret i32 %89
}

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_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 %51
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 %29
26: ; preds = %22, %20
%27 = load i32, i32* @ASN1_R_STREAMING_NOT_SUPPORTED
%28 = tail call i32 @ASN1error(i32 %27)
br label %51
29: ; preds = %22
%30 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %7, i64 0, i32 2
store i32* %0, i32** %30
%31 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %7, i64 0, i32 0
%32 = bitcast %struct.TYPE_9__* %7 to i8*
%33 = load i32, i32* @ASN1_OP_DETACHED_PRE
%34 = call i64 %24(i32 %33, i32** %6, %struct.TYPE_10__* %4, %struct.TYPE_9__* %7)
%35 = icmp slt i64 %34, 1
br i1 %35, label %51, label %36
36: ; preds = %29
%37 = load i32*, i32** %31
%38 = call i32 @SMIME_crlf_copy(i32* %1, i32* %37, i32 %3)
%39 = load i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)*, i64 (i32, i32**, %struct.TYPE_10__*, %struct.TYPE_9__*)** %23
%40 = load i32, i32* @ASN1_OP_DETACHED_POST
%41 = call i64 %39(i32 %40, i32** %6, %struct.TYPE_10__* %4, %struct.TYPE_9__* %7)
%42 = icmp sgt i64 %41, 0
%43 = load i32*, i32** %31
%44 = icmp eq i32* %43, %0
br i1 %44, label %51, label %45
45: ; preds = %36, %45
%46 = phi i32* [ %47, %45 ], [ %43, %36 ]
%47 = call i32* @BIO_pop(i32* %46)
%48 = load i32*, i32** %31
%49 = call i32 @BIO_free(i32* %48)
store i32* %47, i32** %31
%50 = icmp eq i32* %47, %0
br i1 %50, label %51, label %45
51: ; preds = %45, %36, %29, %26, %18
%52 = phi i1 [ true, %18 ], [ false, %26 ], [ false, %29 ], [ %42, %36 ], [ %42, %45 ]
%53 = zext i1 %52 to i32
ret i32 %53
}