#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 */

/* Type definitions */
typedef int /*<<< orphan*/ PKCS7_SIGNER_INFO;
typedef int /*<<< orphan*/ ESS_SIGNING_CERT;
typedef int /*<<< orphan*/ ASN1_STRING;

/* Variables and functions */
int /*<<< orphan*/ ASN1_STRING_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASN1_STRING_new();
int /*<<< orphan*/ ASN1_STRING_set(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ NID_id_smime_aa_signingCertificate;
int PKCS7_add_signed_attribute(int /*<<< orphan*/ *, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ TSerror(int /*<<< orphan*/);
int /*<<< orphan*/ V_ASN1_SEQUENCE;
int /*<<< orphan*/ free(unsigned char *);
int i2d_ESS_SIGNING_CERT(int /*<<< orphan*/ *, unsigned char **);
unsigned char *malloc(int);
int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc) {
  ASN1_STRING *seq = NULL;
  unsigned char *p, *pp = NULL;
  int len;
  len = i2d_ESS_SIGNING_CERT(sc, NULL);
  if (!(pp = malloc(len))) {
    TSerror(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  p = pp;
  i2d_ESS_SIGNING_CERT(sc, &p);
  if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) {
    TSerror(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  free(pp);
  pp = NULL;
  return PKCS7_add_signed_attribute(si, NID_id_smime_aa_signingCertificate,
                                    V_ASN1_SEQUENCE, seq);
err:
  ASN1_STRING_free(seq);
  free(pp);
  return 0;
}


x86 assembly (clang, -O0):
<ESS_add_signing_cert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <i2d_ESS_SIGNING_CERT@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11d9 <ESS_add_signing_cert+0x59>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   10a0 <TSerror@plt>
jmp    1267 <ESS_add_signing_cert+0xe7>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <i2d_ESS_SIGNING_CERT@plt>
mov    $0x0,%al
call   1050 <ASN1_STRING_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     121c <ESS_add_signing_cert+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1090 <ASN1_STRING_set@plt>
cmp    $0x0,%eax
jne    122f <ESS_add_signing_cert+0xaf>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   10a0 <TSerror@plt>
jmp    1267 <ESS_add_signing_cert+0xe7>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    0x2d74(%rip),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
call   1070 <PKCS7_add_signed_attribute@plt>
mov    %eax,-0x4(%rbp)
jmp    1280 <ESS_add_signing_cert+0x100>
mov    -0x20(%rbp),%rdi
call   1040 <ASN1_STRING_free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ESS_add_signing_cert>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rsi,%rdi
xor    %esi,%esi
call   1080 <i2d_ESS_SIGNING_CERT@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1208 <ESS_add_signing_cert+0x88>
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1080 <i2d_ESS_SIGNING_CERT@plt>
xor    %eax,%eax
call   1050 <ASN1_STRING_new@plt>
mov    %rax,%r15
test   %rax,%rax
je     121b <ESS_add_signing_cert+0x9b>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1090 <ASN1_STRING_set@plt>
test   %eax,%eax
je     121b <ESS_add_signing_cert+0x9b>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rcx
call   1070 <PKCS7_add_signed_attribute@plt>
jmp    123b <ESS_add_signing_cert+0xbb>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   10a0 <TSerror@plt>
xor    %r15d,%r15d
jmp    1229 <ESS_add_signing_cert+0xa9>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   10a0 <TSerror@plt>
mov    %r15,%rdi
call   1040 <ASN1_STRING_free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERR_R_MALLOC_FAILURE = global i32 0
@NID_id_smime_aa_signingCertificate = global i32 0
@V_ASN1_SEQUENCE = global i32 0
define i32 @ESS_add_signing_cert(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* null, i32** %6
store i8* null, i8** %8
%10 = load i32*, i32** %5
%11 = call i32 @i2d_ESS_SIGNING_CERT(i32* %10, i8** null)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* @ERR_R_MALLOC_FAILURE
%17 = call i32 @TSerror(i32 %16)
br label %41
18: ; preds = %2
%19 = load i8*, i8** %8
store i8* %19, i8** %7
%20 = load i32*, i32** %5
%21 = call i32 @i2d_ESS_SIGNING_CERT(i32* %20, i8** %7)
%22 = call i32* (...) @ASN1_STRING_new()
store i32* %22, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load i32*, i32** %6
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = call i32 @ASN1_STRING_set(i32* %25, i8* %26, i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %24, %18
%31 = load i32, i32* @ERR_R_MALLOC_FAILURE
%32 = call i32 @TSerror(i32 %31)
br label %41
33: ; preds = %24
%34 = load i8*, i8** %8
%35 = call i32 @free(i8* %34)
store i8* null, i8** %8
%36 = load i32*, i32** %4
%37 = load i32, i32* @NID_id_smime_aa_signingCertificate
%38 = load i32, i32* @V_ASN1_SEQUENCE
%39 = load i32*, i32** %6
%40 = call i32 @PKCS7_add_signed_attribute(i32* %36, i32 %37, i32 %38, i32* %39)
store i32 %40, i32* %3
br label %46
41: ; preds = %30, %15
%42 = load i32*, i32** %6
%43 = call i32 @ASN1_STRING_free(i32* %42)
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %41, %33
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@ERR_R_MALLOC_FAILURE = global i32 0
@NID_id_smime_aa_signingCertificate = global i32 0
@V_ASN1_SEQUENCE = global i32 0
define i32 @ESS_add_signing_cert(i32* %0, i32* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @i2d_ESS_SIGNING_CERT(i32* %1, i8** null)
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @ERR_R_MALLOC_FAILURE
%10 = tail call i32 @TSerror(i32 %9)
br label %26
11: ; preds = %2
store i8* %6, i8** %3
%12 = call i32 @i2d_ESS_SIGNING_CERT(i32* %1, i8** %3)
%13 = call i32* (...) @ASN1_STRING_new()
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = call i32 @ASN1_STRING_set(i32* %13, i8* %6, i32 %5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15, %11
%19 = load i32, i32* @ERR_R_MALLOC_FAILURE
%20 = call i32 @TSerror(i32 %19)
br label %26
21: ; preds = %15
%22 = call i32 @free(i8* %6)
%23 = load i32, i32* @NID_id_smime_aa_signingCertificate
%24 = load i32, i32* @V_ASN1_SEQUENCE
%25 = call i32 @PKCS7_add_signed_attribute(i32* %0, i32 %23, i32 %24, i32* %13)
br label %30
26: ; preds = %18, %8
%27 = phi i32* [ %13, %18 ], [ null, %8 ]
%28 = call i32 @ASN1_STRING_free(i32* %27)
%29 = call i32 @free(i8* %6)
br label %30
30: ; preds = %26, %21
%31 = phi i32 [ %25, %21 ], [ 0, %26 ]
ret i32 %31
}