#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_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int /*<<< orphan*/ enc_digest;
  scalar_t__ auth_attr;
  int /*<<< orphan*/ pkey;
  TYPE_1__ *digest_alg;
};
struct TYPE_5__ {
  int /*<<< orphan*/ algorithm;
};
typedef TYPE_2__ PKCS7_SIGNER_INFO;
typedef int /*<<< orphan*/ EVP_PKEY_CTX;
typedef int /*<<< orphan*/ EVP_MD_CTX;
typedef int /*<<< orphan*/ EVP_MD;
typedef int /*<<< orphan*/ ASN1_VALUE;

/* Variables and functions */
int /*<<< orphan*/ ASN1_ITEM_rptr(int /*<<< orphan*/);
int /*<<< orphan*/ ASN1_STRING_set0(int /*<<< orphan*/, unsigned char *,
                                    size_t);
int ASN1_item_i2d(int /*<<< orphan*/ *, unsigned char **, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
scalar_t__ EVP_DigestSignFinal(int /*<<< orphan*/ *, unsigned char *, size_t *);
scalar_t__ EVP_DigestSignInit(int /*<<< orphan*/ *, int /*<<< orphan*/ **,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/);
scalar_t__ EVP_DigestSignUpdate(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ EVP_MD_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_MD_CTX_new();
int /*<<< orphan*/ EVP_PKEY_CTRL_PKCS7_SIGN;
scalar_t__ EVP_PKEY_CTX_ctrl(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                             int /*<<< orphan*/, int, TYPE_2__ *);
int /*<<< orphan*/ EVP_PKEY_OP_SIGN;
int /*<<< orphan*/ *EVP_get_digestbyobj(int /*<<< orphan*/);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
unsigned char *OPENSSL_malloc(size_t);
int /*<<< orphan*/ PKCS7_ATTR_SIGN;
int /*<<< orphan*/ PKCS7_F_PKCS7_SIGNER_INFO_SIGN;
int /*<<< orphan*/ PKCS7_R_CTRL_ERROR;
int /*<<< orphan*/ PKCS7err(int /*<<< orphan*/, int /*<<< orphan*/);
int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si) {
  EVP_MD_CTX *mctx;
  EVP_PKEY_CTX *pctx;
  unsigned char *abuf = NULL;
  int alen;
  size_t siglen;
  const EVP_MD *md = NULL;
  md = EVP_get_digestbyobj(si->digest_alg->algorithm);
  if (md == NULL)
    return 0;
  mctx = EVP_MD_CTX_new();
  if (mctx == NULL) {
    PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, ERR_R_MALLOC_FAILURE);
    goto err;
  }
  if (EVP_DigestSignInit(mctx, &pctx, md, NULL, si->pkey) <= 0)
    goto err;
  if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, EVP_PKEY_CTRL_PKCS7_SIGN, 0,
                        si) <= 0) {
    PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR);
    goto err;
  }
  alen = ASN1_item_i2d((ASN1_VALUE *)si->auth_attr, &abuf,
                       ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
  if (!abuf)
    goto err;
  if (EVP_DigestSignUpdate(mctx, abuf, alen) <= 0)
    goto err;
  OPENSSL_free(abuf);
  abuf = NULL;
  if (EVP_DigestSignFinal(mctx, NULL, &siglen) <= 0)
    goto err;
  abuf = OPENSSL_malloc(siglen);
  if (abuf == NULL)
    goto err;
  if (EVP_DigestSignFinal(mctx, abuf, &siglen) <= 0)
    goto err;
  if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, EVP_PKEY_CTRL_PKCS7_SIGN, 1,
                        si) <= 0) {
    PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR);
    goto err;
  }
  EVP_MD_CTX_free(mctx);
  ASN1_STRING_set0(si->enc_digest, abuf, siglen);
  return 1;
err:
  OPENSSL_free(abuf);
  EVP_MD_CTX_free(mctx);
  return 0;
}


x86 assembly (clang, -O0):
<PKCS7_SIGNER_INFO_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    (%rax),%edi
call   1050 <EVP_get_digestbyobj@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1216 <PKCS7_SIGNER_INFO_sign+0x46>
movl   $0x0,-0x4(%rbp)
jmp    141b <PKCS7_SIGNER_INFO_sign+0x24b>
mov    $0x0,%al
call   10c0 <EVP_MD_CTX_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1248 <PKCS7_SIGNER_INFO_sign+0x78>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
call   1080 <PKCS7err@plt>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8d
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <EVP_DigestSignInit@plt>
cmp    $0x0,%rax
jg     1274 <PKCS7_SIGNER_INFO_sign+0xa4>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x20(%rbp),%rdi
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
mov    0x2d38(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r9
mov    $0xffffffff,%esi
xor    %r8d,%r8d
call   1070 <EVP_PKEY_CTX_ctrl@plt>
cmp    $0x0,%rax
jg     12c1 <PKCS7_SIGNER_INFO_sign+0xf1>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
call   1080 <PKCS7err@plt>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
call   1040 <ASN1_ITEM_rptr@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    -0x28(%rbp),%rsi
call   10f0 <ASN1_item_i2d@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12fd <PKCS7_SIGNER_INFO_sign+0x12d>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   10e0 <EVP_DigestSignUpdate@plt>
cmp    $0x0,%rax
jg     131c <PKCS7_SIGNER_INFO_sign+0x14c>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x28(%rbp),%rdi
call   10d0 <OPENSSL_free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x38(%rbp),%rdx
call   1090 <EVP_DigestSignFinal@plt>
cmp    $0x0,%rax
jg     134d <PKCS7_SIGNER_INFO_sign+0x17d>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x38(%rbp),%rdi
call   10a0 <OPENSSL_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    136a <PKCS7_SIGNER_INFO_sign+0x19a>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <EVP_DigestSignFinal@plt>
cmp    $0x0,%rax
jg     138a <PKCS7_SIGNER_INFO_sign+0x1ba>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x20(%rbp),%rdi
mov    0x2c3b(%rip),%rax
mov    (%rax),%edx
mov    0x2c22(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r9
mov    $0xffffffff,%esi
mov    $0x1,%r8d
call   1070 <EVP_PKEY_CTX_ctrl@plt>
cmp    $0x0,%rax
jg     13da <PKCS7_SIGNER_INFO_sign+0x20a>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    0x2c1a(%rip),%rax
mov    (%rax),%esi
call   1080 <PKCS7err@plt>
jmp    1402 <PKCS7_SIGNER_INFO_sign+0x232>
mov    -0x18(%rbp),%rdi
call   1030 <EVP_MD_CTX_free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   10b0 <ASN1_STRING_set0@plt>
movl   $0x1,-0x4(%rbp)
jmp    141b <PKCS7_SIGNER_INFO_sign+0x24b>
mov    -0x28(%rbp),%rdi
call   10d0 <OPENSSL_free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <EVP_MD_CTX_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS7_SIGNER_INFO_sign>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
mov    0x18(%rdi),%rax
mov    (%rax),%edi
call   1050 <EVP_get_digestbyobj@plt>
test   %rax,%rax
je     137d <PKCS7_SIGNER_INFO_sign+0x1ad>
mov    %rax,%rbp
xor    %eax,%eax
call   10c0 <EVP_MD_CTX_new@plt>
mov    %rax,%r14
test   %rax,%rax
je     1342 <PKCS7_SIGNER_INFO_sign+0x172>
mov    0x10(%rbx),%r8d
lea    0x18(%rsp),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1060 <EVP_DigestSignInit@plt>
test   %rax,%rax
jle    136b <PKCS7_SIGNER_INFO_sign+0x19b>
mov    0x18(%rsp),%rdi
mov    0x2d93(%rip),%r15
mov    (%r15),%edx
mov    0x2d79(%rip),%r12
mov    (%r12),%ecx
mov    $0xffffffff,%esi
xor    %r8d,%r8d
mov    %rbx,%r9
call   1070 <EVP_PKEY_CTX_ctrl@plt>
test   %rax,%rax
jle    1354 <PKCS7_SIGNER_INFO_sign+0x184>
mov    0x8(%rbx),%rbp
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   1040 <ASN1_ITEM_rptr@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
mov    %eax,%edx
call   10f0 <ASN1_item_i2d@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     136b <PKCS7_SIGNER_INFO_sign+0x19b>
mov    %r14,%rdi
mov    %eax,%edx
call   10e0 <EVP_DigestSignUpdate@plt>
test   %rax,%rax
jle    136b <PKCS7_SIGNER_INFO_sign+0x19b>
mov    0x8(%rsp),%rdi
call   10d0 <OPENSSL_free@plt>
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <EVP_DigestSignFinal@plt>
test   %rax,%rax
jle    136b <PKCS7_SIGNER_INFO_sign+0x19b>
mov    0x10(%rsp),%rdi
call   10a0 <OPENSSL_malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     136b <PKCS7_SIGNER_INFO_sign+0x19b>
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
call   1090 <EVP_DigestSignFinal@plt>
test   %rax,%rax
jle    136b <PKCS7_SIGNER_INFO_sign+0x19b>
mov    0x18(%rsp),%rdi
mov    (%r15),%edx
mov    (%r12),%ecx
mov    $0x1,%ebp
mov    $0xffffffff,%esi
mov    $0x1,%r8d
mov    %rbx,%r9
call   1070 <EVP_PKEY_CTX_ctrl@plt>
test   %rax,%rax
jle    1354 <PKCS7_SIGNER_INFO_sign+0x184>
mov    %r14,%rdi
call   1030 <EVP_MD_CTX_free@plt>
mov    (%rbx),%edi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   10b0 <ASN1_STRING_set0@plt>
jmp    137f <PKCS7_SIGNER_INFO_sign+0x1af>
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
mov    0x2c8e(%rip),%rax
jmp    1364 <PKCS7_SIGNER_INFO_sign+0x194>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
mov    0x2c84(%rip),%rax
mov    (%rax),%esi
call   1080 <PKCS7err@plt>
mov    0x8(%rsp),%rdi
call   10d0 <OPENSSL_free@plt>
mov    %r14,%rdi
call   1030 <EVP_MD_CTX_free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i64, i32, %struct.TYPE_5__* }
%struct.TYPE_5__ = type { i32 }
@PKCS7_F_PKCS7_SIGNER_INFO_SIGN = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@EVP_PKEY_OP_SIGN = global i32 0
@EVP_PKEY_CTRL_PKCS7_SIGN = global i32 0
@PKCS7_R_CTRL_ERROR = global i32 0
@PKCS7_ATTR_SIGN = global i32 0
define i32 @PKCS7_SIGNER_INFO_sign(%struct.TYPE_6__* %0) {
%2 = alloca i32
%3 = alloca %struct.TYPE_6__*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32*
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %3
store i8* null, i8** %6
store i32* null, i32** %9
%10 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%11 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %10, i32 0, i32 3
%12 = load %struct.TYPE_5__*, %struct.TYPE_5__** %11
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32* @EVP_get_digestbyobj(i32 %14)
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 0, i32* %2
br label %109
19: ; preds = %1
%20 = call i32* (...) @EVP_MD_CTX_new()
store i32* %20, i32** %4
%21 = load i32*, i32** %4
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @PKCS7_F_PKCS7_SIGNER_INFO_SIGN
%25 = load i32, i32* @ERR_R_MALLOC_FAILURE
%26 = call i32 @PKCS7err(i32 %24, i32 %25)
br label %104
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = load i32*, i32** %9
%30 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%31 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = call i64 @EVP_DigestSignInit(i32* %28, i32** %5, i32* %29, i32* null, i32 %32)
%34 = icmp sle i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %27
br label %104
36: ; preds = %27
%37 = load i32*, i32** %5
%38 = load i32, i32* @EVP_PKEY_OP_SIGN
%39 = load i32, i32* @EVP_PKEY_CTRL_PKCS7_SIGN
%40 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%41 = call i64 @EVP_PKEY_CTX_ctrl(i32* %37, i32 -1, i32 %38, i32 %39, i32 0, %struct.TYPE_6__* %40)
%42 = icmp sle i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* @PKCS7_F_PKCS7_SIGNER_INFO_SIGN
%45 = load i32, i32* @PKCS7_R_CTRL_ERROR
%46 = call i32 @PKCS7err(i32 %44, i32 %45)
br label %104
47: ; preds = %36
%48 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%49 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %48, i32 0, i32 1
%50 = load i64, i64* %49
%51 = inttoptr i64 %50 to i32*
%52 = load i32, i32* @PKCS7_ATTR_SIGN
%53 = call i32 @ASN1_ITEM_rptr(i32 %52)
%54 = call i32 @ASN1_item_i2d(i32* %51, i8** %6, i32 %53)
store i32 %54, i32* %7
%55 = load i8*, i8** %6
%56 = icmp ne i8* %55, null
br i1 %56, label %58, label %57
57: ; preds = %47
br label %104
58: ; preds = %47
%59 = load i32*, i32** %4
%60 = load i8*, i8** %6
%61 = load i32, i32* %7
%62 = call i64 @EVP_DigestSignUpdate(i32* %59, i8* %60, i32 %61)
%63 = icmp sle i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %58
br label %104
65: ; preds = %58
%66 = load i8*, i8** %6
%67 = call i32 @OPENSSL_free(i8* %66)
store i8* null, i8** %6
%68 = load i32*, i32** %4
%69 = call i64 @EVP_DigestSignFinal(i32* %68, i8* null, i64* %8)
%70 = icmp sle i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %65
br label %104
72: ; preds = %65
%73 = load i64, i64* %8
%74 = call i8* @OPENSSL_malloc(i64 %73)
store i8* %74, i8** %6
%75 = load i8*, i8** %6
%76 = icmp eq i8* %75, null
br i1 %76, label %77, label %78
77: ; preds = %72
br label %104
78: ; preds = %72
%79 = load i32*, i32** %4
%80 = load i8*, i8** %6
%81 = call i64 @EVP_DigestSignFinal(i32* %79, i8* %80, i64* %8)
%82 = icmp sle i64 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %78
br label %104
84: ; preds = %78
%85 = load i32*, i32** %5
%86 = load i32, i32* @EVP_PKEY_OP_SIGN
%87 = load i32, i32* @EVP_PKEY_CTRL_PKCS7_SIGN
%88 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%89 = call i64 @EVP_PKEY_CTX_ctrl(i32* %85, i32 -1, i32 %86, i32 %87, i32 1, %struct.TYPE_6__* %88)
%90 = icmp sle i64 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %84
%92 = load i32, i32* @PKCS7_F_PKCS7_SIGNER_INFO_SIGN
%93 = load i32, i32* @PKCS7_R_CTRL_ERROR
%94 = call i32 @PKCS7err(i32 %92, i32 %93)
br label %104
95: ; preds = %84
%96 = load i32*, i32** %4
%97 = call i32 @EVP_MD_CTX_free(i32* %96)
%98 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%99 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %98, i32 0, i32 0
%100 = load i32, i32* %99
%101 = load i8*, i8** %6
%102 = load i64, i64* %8
%103 = call i32 @ASN1_STRING_set0(i32 %100, i8* %101, i64 %102)
store i32 1, i32* %2
br label %109
104: ; preds = %91, %83, %77, %71, %64, %57, %43, %35, %23
%105 = load i8*, i8** %6
%106 = call i32 @OPENSSL_free(i8* %105)
%107 = load i32*, i32** %4
%108 = call i32 @EVP_MD_CTX_free(i32* %107)
store i32 0, i32* %2
br label %109
109: ; preds = %104, %95, %18
%110 = load i32, i32* %2
ret i32 %110
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i64, i32, %struct.TYPE_5__* }
%struct.TYPE_5__ = type { i32 }
@PKCS7_F_PKCS7_SIGNER_INFO_SIGN = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@EVP_PKEY_OP_SIGN = global i32 0
@EVP_PKEY_CTRL_PKCS7_SIGN = global i32 0
@PKCS7_R_CTRL_ERROR = global i32 0
@PKCS7_ATTR_SIGN = global i32 0
define i32 @PKCS7_SIGNER_INFO_sign(%struct.TYPE_6__* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i32** %2 to i8*
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i64* %4 to i8*
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 3
%9 = load %struct.TYPE_5__*, %struct.TYPE_5__** %8
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32* @EVP_get_digestbyobj(i32 %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %81, label %14
14: ; preds = %1
%15 = tail call i32* (...) @EVP_MD_CTX_new()
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @PKCS7_F_PKCS7_SIGNER_INFO_SIGN
%19 = load i32, i32* @ERR_R_MALLOC_FAILURE
%20 = tail call i32 @PKCS7err(i32 %18, i32 %19)
br label %77
21: ; preds = %14
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i64 @EVP_DigestSignInit(i32* %15, i32** %2, i32* %12, i32* null, i32 %23)
%25 = icmp slt i64 %24, 1
br i1 %25, label %77, label %26
26: ; preds = %21
%27 = load i32*, i32** %2
%28 = load i32, i32* @EVP_PKEY_OP_SIGN
%29 = load i32, i32* @EVP_PKEY_CTRL_PKCS7_SIGN
%30 = call i64 @EVP_PKEY_CTX_ctrl(i32* %27, i32 -1, i32 %28, i32 %29, i32 0, %struct.TYPE_6__* %0)
%31 = icmp slt i64 %30, 1
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* @PKCS7_F_PKCS7_SIGNER_INFO_SIGN
%34 = load i32, i32* @PKCS7_R_CTRL_ERROR
%35 = call i32 @PKCS7err(i32 %33, i32 %34)
br label %77
36: ; preds = %26
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 1
%38 = load i64, i64* %37
%39 = inttoptr i64 %38 to i32*
%40 = load i32, i32* @PKCS7_ATTR_SIGN
%41 = call i32 @ASN1_ITEM_rptr(i32 %40)
%42 = call i32 @ASN1_item_i2d(i32* %39, i8** %3, i32 %41)
%43 = load i8*, i8** %3
%44 = icmp eq i8* %43, null
br i1 %44, label %77, label %45
45: ; preds = %36
%46 = call i64 @EVP_DigestSignUpdate(i32* %15, i8* %43, i32 %42)
%47 = icmp slt i64 %46, 1
br i1 %47, label %77, label %48
48: ; preds = %45
%49 = load i8*, i8** %3
%50 = call i32 @OPENSSL_free(i8* %49)
store i8* null, i8** %3
%51 = call i64 @EVP_DigestSignFinal(i32* %15, i8* null, i64* %4)
%52 = icmp slt i64 %51, 1
br i1 %52, label %77, label %53
53: ; preds = %48
%54 = load i64, i64* %4
%55 = call i8* @OPENSSL_malloc(i64 %54)
store i8* %55, i8** %3
%56 = icmp eq i8* %55, null
br i1 %56, label %77, label %57
57: ; preds = %53
%58 = call i64 @EVP_DigestSignFinal(i32* %15, i8* %55, i64* %4)
%59 = icmp slt i64 %58, 1
br i1 %59, label %77, label %60
60: ; preds = %57
%61 = load i32*, i32** %2
%62 = load i32, i32* @EVP_PKEY_OP_SIGN
%63 = load i32, i32* @EVP_PKEY_CTRL_PKCS7_SIGN
%64 = call i64 @EVP_PKEY_CTX_ctrl(i32* %61, i32 -1, i32 %62, i32 %63, i32 1, %struct.TYPE_6__* %0)
%65 = icmp slt i64 %64, 1
br i1 %65, label %66, label %70
66: ; preds = %60
%67 = load i32, i32* @PKCS7_F_PKCS7_SIGNER_INFO_SIGN
%68 = load i32, i32* @PKCS7_R_CTRL_ERROR
%69 = call i32 @PKCS7err(i32 %67, i32 %68)
br label %77
70: ; preds = %60
%71 = call i32 @EVP_MD_CTX_free(i32* %15)
%72 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0
%73 = load i32, i32* %72
%74 = load i8*, i8** %3
%75 = load i64, i64* %4
%76 = call i32 @ASN1_STRING_set0(i32 %73, i8* %74, i64 %75)
br label %81
77: ; preds = %57, %53, %48, %45, %36, %21, %66, %32, %17
%78 = load i8*, i8** %3
%79 = call i32 @OPENSSL_free(i8* %78)
%80 = call i32 @EVP_MD_CTX_free(i32* %15)
br label %81
81: ; preds = %1, %77, %70
%82 = phi i32 [ 0, %77 ], [ 1, %70 ], [ 0, %1 ]
ret i32 %82
}