#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*/ X509;
typedef int /*<<< orphan*/ PKCS7_SIGNER_INFO;
typedef int /*<<< orphan*/ PKCS7;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ EVP_MD;

/* Variables and functions */
int /*<<< orphan*/ PKCS7_SIGNER_INFO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *PKCS7_SIGNER_INFO_new();
int /*<<< orphan*/ PKCS7_SIGNER_INFO_set(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ const *);
int /*<<< orphan*/ PKCS7_add_signer(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
                                       const EVP_MD *dgst) {
  PKCS7_SIGNER_INFO *si;
  if ((si = PKCS7_SIGNER_INFO_new()) == NULL)
    goto err;
  if (!PKCS7_SIGNER_INFO_set(si, x509, pkey, dgst))
    goto err;
  if (!PKCS7_add_signer(p7, si))
    goto err;
  return (si);
err:
  PKCS7_SIGNER_INFO_free(si);
  return (NULL);
}


x86 assembly (clang, -O0):
<PKCS7_add_signature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x0,%al
call   1040 <PKCS7_SIGNER_INFO_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1172 <PKCS7_add_signature+0x32>
jmp    11bd <PKCS7_add_signature+0x7d>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <PKCS7_SIGNER_INFO_set@plt>
cmp    $0x0,%eax
jne    1195 <PKCS7_add_signature+0x55>
jmp    11bd <PKCS7_add_signature+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <PKCS7_add_signer@plt>
cmp    $0x0,%eax
jne    11b0 <PKCS7_add_signature+0x70>
jmp    11bd <PKCS7_add_signature+0x7d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <PKCS7_add_signature+0x8e>
mov    -0x30(%rbp),%rdi
call   1060 <PKCS7_SIGNER_INFO_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS7_add_signature>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <PKCS7_SIGNER_INFO_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1188 <PKCS7_add_signature+0x48>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1050 <PKCS7_SIGNER_INFO_set@plt>
test   %eax,%eax
je     1188 <PKCS7_add_signature+0x48>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <PKCS7_add_signer@plt>
test   %eax,%eax
jne    1192 <PKCS7_add_signature+0x52>
mov    %rbx,%rdi
call   1060 <PKCS7_SIGNER_INFO_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @PKCS7_add_signature(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%11 = call i32* (...) @PKCS7_SIGNER_INFO_new()
store i32* %11, i32** %10
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %4
br label %30
14: ; preds = %4
%15 = load i32*, i32** %10
%16 = load i32*, i32** %7
%17 = load i32*, i32** %8
%18 = load i32*, i32** %9
%19 = call i32 @PKCS7_SIGNER_INFO_set(i32* %15, i32* %16, i32* %17, i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %14
br label %30
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = load i32*, i32** %10
%25 = call i32 @PKCS7_add_signer(i32* %23, i32* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
br label %30
28: ; preds = %22
%29 = load i32*, i32** %10
store i32* %29, i32** %5
br label %33
30: ; preds = %27, %21, %13
%31 = load i32*, i32** %10
%32 = call i32 @PKCS7_SIGNER_INFO_free(i32* %31)
store i32* null, i32** %5
br label %33
33: ; preds = %30, %28
%34 = load i32*, i32** %5
ret i32* %34
}

LLVM IR (-O2):
define i32* @PKCS7_add_signature(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = tail call i32* (...) @PKCS7_SIGNER_INFO_new()
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32 @PKCS7_SIGNER_INFO_set(i32* %5, i32* %1, i32* %2, i32* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @PKCS7_add_signer(i32* %0, i32* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10, %7, %4
%14 = tail call i32 @PKCS7_SIGNER_INFO_free(i32* %5)
br label %15
15: ; preds = %10, %13
%16 = phi i32* [ null, %13 ], [ %5, %10 ]
ret i32* %16
}