#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_15__ TYPE_6__;
typedef struct TYPE_14__ TYPE_5__;
typedef struct TYPE_13__ TYPE_4__;
typedef struct TYPE_12__ TYPE_3__;
typedef struct TYPE_11__ TYPE_2__;
typedef struct TYPE_10__ TYPE_1__;

/* Type definitions */
struct TYPE_15__ {
  unsigned char *data;
  int /*<<< orphan*/ length;
};
struct TYPE_11__ {
  TYPE_6__ *octet_string;
};
struct TYPE_14__ {
  scalar_t__ type;
  TYPE_2__ value;
};
struct TYPE_10__ {
  TYPE_5__ *other;
  TYPE_3__ *sign;
};
struct TYPE_13__ {
  TYPE_1__ d;
  int /*<<< orphan*/ type;
};
struct TYPE_12__ {
  TYPE_4__ *contents;
};
typedef int /*<<< orphan*/ TS_TST_INFO;
typedef TYPE_3__ PKCS7_SIGNED;
typedef TYPE_4__ PKCS7;
typedef TYPE_5__ ASN1_TYPE;
typedef TYPE_6__ ASN1_OCTET_STRING;

/* Variables and functions */
scalar_t__ NID_id_smime_ct_TSTInfo;
scalar_t__ OBJ_obj2nid(int /*<<< orphan*/);
scalar_t__ PKCS7_get_detached(TYPE_4__ *);
int /*<<< orphan*/ PKCS7_type_is_signed(TYPE_4__ *);
int /*<<< orphan*/ TS_F_PKCS7_TO_TS_TST_INFO;
int /*<<< orphan*/ TS_R_BAD_PKCS7_TYPE;
int /*<<< orphan*/ TS_R_BAD_TYPE;
int /*<<< orphan*/ TS_R_DETACHED_CONTENT;
int /*<<< orphan*/ TSerr(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ V_ASN1_OCTET_STRING;
int /*<<< orphan*/ *d2i_TS_TST_INFO(int /*<<< orphan*/ *,
                                    unsigned char const **, int /*<<< orphan*/);
TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token) {
  PKCS7_SIGNED *pkcs7_signed;
  PKCS7 *enveloped;
  ASN1_TYPE *tst_info_wrapper;
  ASN1_OCTET_STRING *tst_info_der;
  const unsigned char *p;
  if (!PKCS7_type_is_signed(token)) {
    TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
    return NULL;
  }
  if (PKCS7_get_detached(token)) {
    TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_DETACHED_CONTENT);
    return NULL;
  }
  pkcs7_signed = token->d.sign;
  enveloped = pkcs7_signed->contents;
  if (OBJ_obj2nid(enveloped->type) != NID_id_smime_ct_TSTInfo) {
    TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
    return NULL;
  }
  tst_info_wrapper = enveloped->d.other;
  if (tst_info_wrapper->type != V_ASN1_OCTET_STRING) {
    TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_TYPE);
    return NULL;
  }
  tst_info_der = tst_info_wrapper->value.octet_string;
  p = tst_info_der->data;
  return d2i_TS_TST_INFO(NULL, &p, tst_info_der->length);
}


x86 assembly (clang, -O0):
<PKCS7_to_TS_TST_INFO>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <PKCS7_type_is_signed@plt>
cmp    $0x0,%eax
jne    1192 <PKCS7_to_TS_TST_INFO+0x42>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1050 <TSerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    1295 <PKCS7_to_TS_TST_INFO+0x145>
mov    -0x10(%rbp),%rdi
call   1070 <PKCS7_get_detached@plt>
cmp    $0x0,%rax
je     11c9 <PKCS7_to_TS_TST_INFO+0x79>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
call   1050 <TSerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    1295 <PKCS7_to_TS_TST_INFO+0x145>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edi
call   1040 <OBJ_obj2nid@plt>
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%rax
je     1220 <PKCS7_to_TS_TST_INFO+0xd0>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   1050 <TSerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    1295 <PKCS7_to_TS_TST_INFO+0x145>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2d87(%rip),%rcx
cmp    (%rcx),%rax
je     1266 <PKCS7_to_TS_TST_INFO+0x116>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
call   1050 <TSerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    1295 <PKCS7_to_TS_TST_INFO+0x145>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x38(%rbp),%rsi
call   1060 <d2i_TS_TST_INFO@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS7_to_TS_TST_INFO>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <PKCS7_type_is_signed@plt>
test   %eax,%eax
je     11ca <PKCS7_to_TS_TST_INFO+0x7a>
mov    %rbx,%rdi
call   1070 <PKCS7_get_detached@plt>
test   %rax,%rax
je     1180 <PKCS7_to_TS_TST_INFO+0x30>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
jmp    11da <PKCS7_to_TS_TST_INFO+0x8a>
mov    0x8(%rbx),%rax
mov    (%rax),%rbx
mov    0x10(%rbx),%edi
call   1040 <OBJ_obj2nid@plt>
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
jne    11ca <PKCS7_to_TS_TST_INFO+0x7a>
mov    (%rbx),%rax
mov    (%rax),%rcx
mov    0x2e18(%rip),%rdx
cmp    (%rdx),%rcx
jne    11e9 <PKCS7_to_TS_TST_INFO+0x99>
mov    0x8(%rax),%rax
mov    (%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x8(%rax),%edx
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1060 <d2i_TS_TST_INFO@plt>
jmp    11e3 <PKCS7_to_TS_TST_INFO+0x93>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
call   1050 <TSerr@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
jmp    11da <PKCS7_to_TS_TST_INFO+0x8a>

LLVM IR (-O0):
%struct.TYPE_13__ = type { %struct.TYPE_10__, i32 }
%struct.TYPE_10__ = type { %struct.TYPE_14__*, %struct.TYPE_12__* }
%struct.TYPE_14__ = type { i64, %struct.TYPE_11__ }
%struct.TYPE_11__ = type { %struct.TYPE_15__* }
%struct.TYPE_15__ = type { i8*, i32 }
%struct.TYPE_12__ = type { %struct.TYPE_13__* }
@TS_F_PKCS7_TO_TS_TST_INFO = global i32 0
@TS_R_BAD_PKCS7_TYPE = global i32 0
@TS_R_DETACHED_CONTENT = global i32 0
@NID_id_smime_ct_TSTInfo = global i64 0
@V_ASN1_OCTET_STRING = global i64 0
@TS_R_BAD_TYPE = global i32 0
define i32* @PKCS7_to_TS_TST_INFO(%struct.TYPE_13__* %0) {
%2 = alloca i32*
%3 = alloca %struct.TYPE_13__*
%4 = alloca %struct.TYPE_12__*
%5 = alloca %struct.TYPE_13__*
%6 = alloca %struct.TYPE_14__*
%7 = alloca %struct.TYPE_15__*
%8 = alloca i8*
store %struct.TYPE_13__* %0, %struct.TYPE_13__** %3
%9 = load %struct.TYPE_13__*, %struct.TYPE_13__** %3
%10 = call i32 @PKCS7_type_is_signed(%struct.TYPE_13__* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%14 = load i32, i32* @TS_R_BAD_PKCS7_TYPE
%15 = call i32 @TSerr(i32 %13, i32 %14)
store i32* null, i32** %2
br label %68
16: ; preds = %1
%17 = load %struct.TYPE_13__*, %struct.TYPE_13__** %3
%18 = call i64 @PKCS7_get_detached(%struct.TYPE_13__* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%22 = load i32, i32* @TS_R_DETACHED_CONTENT
%23 = call i32 @TSerr(i32 %21, i32 %22)
store i32* null, i32** %2
br label %68
24: ; preds = %16
%25 = load %struct.TYPE_13__*, %struct.TYPE_13__** %3
%26 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %25, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %26, i32 0, i32 1
%28 = load %struct.TYPE_12__*, %struct.TYPE_12__** %27
store %struct.TYPE_12__* %28, %struct.TYPE_12__** %4
%29 = load %struct.TYPE_12__*, %struct.TYPE_12__** %4
%30 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %29, i32 0, i32 0
%31 = load %struct.TYPE_13__*, %struct.TYPE_13__** %30
store %struct.TYPE_13__* %31, %struct.TYPE_13__** %5
%32 = load %struct.TYPE_13__*, %struct.TYPE_13__** %5
%33 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %32, i32 0, i32 1
%34 = load i32, i32* %33
%35 = call i64 @OBJ_obj2nid(i32 %34)
%36 = load i64, i64* @NID_id_smime_ct_TSTInfo
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %24
%39 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%40 = load i32, i32* @TS_R_BAD_PKCS7_TYPE
%41 = call i32 @TSerr(i32 %39, i32 %40)
store i32* null, i32** %2
br label %68
42: ; preds = %24
%43 = load %struct.TYPE_13__*, %struct.TYPE_13__** %5
%44 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %43, i32 0, i32 0
%45 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %44, i32 0, i32 0
%46 = load %struct.TYPE_14__*, %struct.TYPE_14__** %45
store %struct.TYPE_14__* %46, %struct.TYPE_14__** %6
%47 = load %struct.TYPE_14__*, %struct.TYPE_14__** %6
%48 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = load i64, i64* @V_ASN1_OCTET_STRING
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %42
%53 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%54 = load i32, i32* @TS_R_BAD_TYPE
%55 = call i32 @TSerr(i32 %53, i32 %54)
store i32* null, i32** %2
br label %68
56: ; preds = %42
%57 = load %struct.TYPE_14__*, %struct.TYPE_14__** %6
%58 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %57, i32 0, i32 1
%59 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %58, i32 0, i32 0
%60 = load %struct.TYPE_15__*, %struct.TYPE_15__** %59
store %struct.TYPE_15__* %60, %struct.TYPE_15__** %7
%61 = load %struct.TYPE_15__*, %struct.TYPE_15__** %7
%62 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %61, i32 0, i32 0
%63 = load i8*, i8** %62
store i8* %63, i8** %8
%64 = load %struct.TYPE_15__*, %struct.TYPE_15__** %7
%65 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %64, i32 0, i32 1
%66 = load i32, i32* %65
%67 = call i32* @d2i_TS_TST_INFO(i32* null, i8** %8, i32 %66)
store i32* %67, i32** %2
br label %68
68: ; preds = %56, %52, %38, %20, %12
%69 = load i32*, i32** %2
ret i32* %69
}

LLVM IR (-O2):
%struct.TYPE_13__ = type { %struct.TYPE_10__, i32 }
%struct.TYPE_10__ = type { %struct.TYPE_14__*, %struct.TYPE_12__* }
%struct.TYPE_14__ = type { i64, %struct.TYPE_11__ }
%struct.TYPE_11__ = type { %struct.TYPE_15__* }
%struct.TYPE_15__ = type { i8*, i32 }
%struct.TYPE_12__ = type { %struct.TYPE_13__* }
@TS_F_PKCS7_TO_TS_TST_INFO = global i32 0
@TS_R_BAD_PKCS7_TYPE = global i32 0
@TS_R_DETACHED_CONTENT = global i32 0
@NID_id_smime_ct_TSTInfo = global i64 0
@V_ASN1_OCTET_STRING = global i64 0
@TS_R_BAD_TYPE = global i32 0
define i32* @PKCS7_to_TS_TST_INFO(%struct.TYPE_13__* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 @PKCS7_type_is_signed(%struct.TYPE_13__* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%8 = load i32, i32* @TS_R_BAD_PKCS7_TYPE
%9 = tail call i32 @TSerr(i32 %7, i32 %8)
br label %50
10: ; preds = %1
%11 = tail call i64 @PKCS7_get_detached(%struct.TYPE_13__* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%15 = load i32, i32* @TS_R_DETACHED_CONTENT
%16 = tail call i32 @TSerr(i32 %14, i32 %15)
br label %50
17: ; preds = %10
%18 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %0, i64 0, i32 0, i32 1
%19 = load %struct.TYPE_12__*, %struct.TYPE_12__** %18
%20 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %19, i64 0, i32 0
%21 = load %struct.TYPE_13__*, %struct.TYPE_13__** %20
%22 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %21, i64 0, i32 1
%23 = load i32, i32* %22
%24 = tail call i64 @OBJ_obj2nid(i32 %23)
%25 = load i64, i64* @NID_id_smime_ct_TSTInfo
%26 = icmp eq i64 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %17
%28 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%29 = load i32, i32* @TS_R_BAD_PKCS7_TYPE
%30 = tail call i32 @TSerr(i32 %28, i32 %29)
br label %50
31: ; preds = %17
%32 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %21, i64 0, i32 0, i32 0
%33 = load %struct.TYPE_14__*, %struct.TYPE_14__** %32
%34 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %33, i64 0, i32 0
%35 = load i64, i64* %34
%36 = load i64, i64* @V_ASN1_OCTET_STRING
%37 = icmp eq i64 %35, %36
br i1 %37, label %42, label %38
38: ; preds = %31
%39 = load i32, i32* @TS_F_PKCS7_TO_TS_TST_INFO
%40 = load i32, i32* @TS_R_BAD_TYPE
%41 = tail call i32 @TSerr(i32 %39, i32 %40)
br label %50
42: ; preds = %31
%43 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %33, i64 0, i32 1, i32 0
%44 = load %struct.TYPE_15__*, %struct.TYPE_15__** %43
%45 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %44, i64 0, i32 0
%46 = load i8*, i8** %45
store i8* %46, i8** %2
%47 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %44, i64 0, i32 1
%48 = load i32, i32* %47
%49 = call i32* @d2i_TS_TST_INFO(i32* null, i8** %2, i32 %48)
br label %50
50: ; preds = %42, %38, %27, %13, %6
%51 = phi i32* [ null, %13 ], [ null, %27 ], [ null, %38 ], [ %49, %42 ], [ null, %6 ]
ret i32* %51
}