#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*/ TS_F_ESS_ADD_SIGNING_CERT;
int /*<<< orphan*/ TSerr(int /*<<< orphan*/, 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))) {
    TSerr(TS_F_ESS_ADD_SIGNING_CERT, 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)) {
    TSerr(TS_F_ESS_ADD_SIGNING_CERT, 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   1090 <i2d_ESS_SIGNING_CERT@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11e2 <ESS_add_signing_cert+0x62>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
call   1040 <TSerr@plt>
jmp    1279 <ESS_add_signing_cert+0xf9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <i2d_ESS_SIGNING_CERT@plt>
mov    $0x0,%al
call   1060 <ASN1_STRING_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1225 <ESS_add_signing_cert+0xa5>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   10a0 <ASN1_STRING_set@plt>
cmp    $0x0,%eax
jne    1241 <ESS_add_signing_cert+0xc1>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
call   1040 <TSerr@plt>
jmp    1279 <ESS_add_signing_cert+0xf9>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
call   1080 <PKCS7_add_signed_attribute@plt>
mov    %eax,-0x4(%rbp)
jmp    1292 <ESS_add_signing_cert+0x112>
mov    -0x20(%rbp),%rdi
call   1050 <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   1090 <i2d_ESS_SIGNING_CERT@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1070 <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   1090 <i2d_ESS_SIGNING_CERT@plt>
xor    %eax,%eax
call   1060 <ASN1_STRING_new@plt>
mov    %rax,%r15
test   %rax,%rax
je     1224 <ESS_add_signing_cert+0xa4>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   10a0 <ASN1_STRING_set@plt>
test   %eax,%eax
je     1224 <ESS_add_signing_cert+0xa4>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rcx
call   1080 <PKCS7_add_signed_attribute@plt>
jmp    124d <ESS_add_signing_cert+0xcd>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
call   1040 <TSerr@plt>
xor    %r15d,%r15d
jmp    123b <ESS_add_signing_cert+0xbb>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
call   1040 <TSerr@plt>
mov    %r15,%rdi
call   1050 <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):
@TS_F_ESS_ADD_SIGNING_CERT = global i32 0
@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 %19, label %15
15: ; preds = %2
%16 = load i32, i32* @TS_F_ESS_ADD_SIGNING_CERT
%17 = load i32, i32* @ERR_R_MALLOC_FAILURE
%18 = call i32 @TSerr(i32 %16, i32 %17)
br label %43
19: ; preds = %2
%20 = load i8*, i8** %8
store i8* %20, i8** %7
%21 = load i32*, i32** %5
%22 = call i32 @i2d_ESS_SIGNING_CERT(i32* %21, i8** %7)
%23 = call i32* (...) @ASN1_STRING_new()
store i32* %23, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i32*, i32** %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = call i32 @ASN1_STRING_set(i32* %26, i8* %27, i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %25, %19
%32 = load i32, i32* @TS_F_ESS_ADD_SIGNING_CERT
%33 = load i32, i32* @ERR_R_MALLOC_FAILURE
%34 = call i32 @TSerr(i32 %32, i32 %33)
br label %43
35: ; preds = %25
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
store i8* null, i8** %8
%38 = load i32*, i32** %4
%39 = load i32, i32* @NID_id_smime_aa_signingCertificate
%40 = load i32, i32* @V_ASN1_SEQUENCE
%41 = load i32*, i32** %6
%42 = call i32 @PKCS7_add_signed_attribute(i32* %38, i32 %39, i32 %40, i32* %41)
store i32 %42, i32* %3
br label %48
43: ; preds = %31, %15
%44 = load i32*, i32** %6
%45 = call i32 @ASN1_STRING_free(i32* %44)
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %43, %35
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@TS_F_ESS_ADD_SIGNING_CERT = global i32 0
@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 %12
8: ; preds = %2
%9 = load i32, i32* @TS_F_ESS_ADD_SIGNING_CERT
%10 = load i32, i32* @ERR_R_MALLOC_FAILURE
%11 = tail call i32 @TSerr(i32 %9, i32 %10)
br label %28
12: ; preds = %2
store i8* %6, i8** %3
%13 = call i32 @i2d_ESS_SIGNING_CERT(i32* %1, i8** %3)
%14 = call i32* (...) @ASN1_STRING_new()
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = call i32 @ASN1_STRING_set(i32* %14, i8* %6, i32 %5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16, %12
%20 = load i32, i32* @TS_F_ESS_ADD_SIGNING_CERT
%21 = load i32, i32* @ERR_R_MALLOC_FAILURE
%22 = call i32 @TSerr(i32 %20, i32 %21)
br label %28
23: ; preds = %16
%24 = call i32 @free(i8* %6)
%25 = load i32, i32* @NID_id_smime_aa_signingCertificate
%26 = load i32, i32* @V_ASN1_SEQUENCE
%27 = call i32 @PKCS7_add_signed_attribute(i32* %0, i32 %25, i32 %26, i32* %14)
br label %32
28: ; preds = %19, %8
%29 = phi i32* [ %14, %19 ], [ null, %8 ]
%30 = call i32 @ASN1_STRING_free(i32* %29)
%31 = call i32 @free(i8* %6)
br label %32
32: ; preds = %28, %23
%33 = phi i32 [ %27, %23 ], [ 0, %28 ]
ret i32 %33
}