#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ ndef_bio;
  int /*<<< orphan*/ out;
  int /*<<< orphan*/ boundary;
};
typedef int /*<<< orphan*/ PKCS7;
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef TYPE_1__ ASN1_STREAM_ARG;
typedef int /*<<< orphan*/ ASN1_ITEM;

/* Variables and functions */
#define ASN1_OP_DETACHED_POST 131
#define ASN1_OP_DETACHED_PRE 130
#define ASN1_OP_STREAM_POST 129
#define ASN1_OP_STREAM_PRE 128
int /*<<< orphan*/ PKCS7_dataFinal(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ PKCS7_dataInit(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ PKCS7_stream(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int pk7_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) {
  ASN1_STREAM_ARG *sarg = exarg;
  PKCS7 **pp7 = (PKCS7 **)pval;
  switch (operation) {
  case ASN1_OP_STREAM_PRE:
    if (PKCS7_stream(&sarg->boundary, *pp7) <= 0)
      return 0;
  case ASN1_OP_DETACHED_PRE:
    sarg->ndef_bio = PKCS7_dataInit(*pp7, sarg->out);
    if (!sarg->ndef_bio)
      return 0;
    break;
  case ASN1_OP_STREAM_POST:
  case ASN1_OP_DETACHED_POST:
    if (PKCS7_dataFinal(*pp7, sarg->ndef_bio) <= 0)
      return 0;
    break;
  }
  return 1;
}


x86 assembly (clang, -O0):
<pk7_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x3,%eax
ja     1213 <pk7_cb+0xe3>
mov    -0x38(%rbp),%rax
lea    0xe89(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rdi
add    $0x8,%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   1040 <PKCS7_stream@plt>
cmp    $0x0,%eax
jg     11a9 <pk7_cb+0x79>
movl   $0x0,-0x4(%rbp)
jmp    121a <pk7_cb+0xea>
jmp    11ae <pk7_cb+0x7e>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%esi
call   1030 <PKCS7_dataInit@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11e2 <pk7_cb+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    121a <pk7_cb+0xea>
jmp    1213 <pk7_cb+0xe3>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1050 <PKCS7_dataFinal@plt>
cmp    $0x0,%eax
jg     120e <pk7_cb+0xde>
movl   $0x0,-0x4(%rbp)
jmp    121a <pk7_cb+0xea>
jmp    1213 <pk7_cb+0xe3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pk7_cb>:
push   %r14
push   %rbx
push   %rax
add    $0xffffff80,%edi
cmp    $0x3,%edi
ja     1186 <pk7_cb+0x56>
mov    %rcx,%r14
mov    %rsi,%rbx
lea    0xeb7(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    (%rbx),%rdi
mov    (%r14),%esi
call   1050 <PKCS7_dataFinal@plt>
test   %eax,%eax
jg     1186 <pk7_cb+0x56>
jmp    118d <pk7_cb+0x5d>
lea    0x8(%r14),%rdi
mov    (%rbx),%rsi
call   1040 <PKCS7_stream@plt>
test   %eax,%eax
jle    118d <pk7_cb+0x5d>
mov    (%rbx),%rdi
mov    0x4(%r14),%esi
call   1030 <PKCS7_dataInit@plt>
mov    %eax,(%r14)
test   %eax,%eax
je     118d <pk7_cb+0x5d>
mov    $0x1,%eax
jmp    118f <pk7_cb+0x5f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32, i32, i32 }
define i32 @pk7_cb(i32 %0, i32** %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca %struct.TYPE_2__*
%11 = alloca i32**
store i32 %0, i32* %6
store i32** %1, i32*** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %9
%13 = bitcast i8* %12 to %struct.TYPE_2__*
store %struct.TYPE_2__* %13, %struct.TYPE_2__** %10
%14 = load i32**, i32*** %7
store i32** %14, i32*** %11
%15 = load i32, i32* %6
switch i32 %15, label %50 [
i32 128, label %16
i32 130, label %25
i32 129, label %40
i32 131, label %40
]
16: ; preds = %4
%17 = load %struct.TYPE_2__*, %struct.TYPE_2__** %10
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 2
%19 = load i32**, i32*** %11
%20 = load i32*, i32** %19
%21 = call i32 @PKCS7_stream(i32* %18, i32* %20)
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 0, i32* %5
br label %51
24: ; preds = %16
br label %25
25: ; preds = %4, %24
%26 = load i32**, i32*** %11
%27 = load i32*, i32** %26
%28 = load %struct.TYPE_2__*, %struct.TYPE_2__** %10
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = call i32 @PKCS7_dataInit(i32* %27, i32 %30)
%32 = load %struct.TYPE_2__*, %struct.TYPE_2__** %10
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load %struct.TYPE_2__*, %struct.TYPE_2__** %10
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %25
store i32 0, i32* %5
br label %51
39: ; preds = %25
br label %50
40: ; preds = %4, %4
%41 = load i32**, i32*** %11
%42 = load i32*, i32** %41
%43 = load %struct.TYPE_2__*, %struct.TYPE_2__** %10
%44 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @PKCS7_dataFinal(i32* %42, i32 %45)
%47 = icmp sle i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %40
store i32 0, i32* %5
br label %51
49: ; preds = %40
br label %50
50: ; preds = %4, %49, %39
store i32 1, i32* %5
br label %51
51: ; preds = %50, %48, %38, %23
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
define i32 @pk7_cb(i32 %0, i32** nocapture %1, i32* nocapture readnone %2, i8* %3) {
switch i32 %0, label %25 [
i32 128, label %5
i32 130, label %11
i32 129, label %19
i32 131, label %19
]
5: ; preds = %4
%6 = getelementptr inbounds i8, i8* %3, i64 8
%7 = bitcast i8* %6 to i32*
%8 = load i32*, i32** %1
%9 = tail call i32 @PKCS7_stream(i32* %7, i32* %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %26, label %11
11: ; preds = %5, %4
%12 = load i32*, i32** %1
%13 = getelementptr inbounds i8, i8* %3, i64 4
%14 = bitcast i8* %13 to i32*
%15 = load i32, i32* %14
%16 = tail call i32 @PKCS7_dataInit(i32* %12, i32 %15)
%17 = bitcast i8* %3 to i32*
store i32 %16, i32* %17
%18 = icmp eq i32 %16, 0
br i1 %18, label %26, label %25
19: ; preds = %4, %4
%20 = load i32*, i32** %1
%21 = bitcast i8* %3 to i32*
%22 = load i32, i32* %21
%23 = tail call i32 @PKCS7_dataFinal(i32* %20, i32 %22)
%24 = icmp slt i32 %23, 1
br i1 %24, label %26, label %25
25: ; preds = %19, %11, %4
br label %26
26: ; preds = %19, %11, %5, %25
%27 = phi i32 [ 1, %25 ], [ 0, %5 ], [ 0, %11 ], [ 0, %19 ]
ret i32 %27
}