#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*/ CMS_ContentInfo;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
scalar_t__ CMS_EncryptedData_set1_key(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      unsigned char const *, size_t);
int /*<<< orphan*/ CMS_F_CMS_ENCRYPTEDDATA_DECRYPT;
int /*<<< orphan*/ CMS_R_TYPE_NOT_ENCRYPTED_DATA;
int /*<<< orphan*/ *CMS_dataInit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ CMS_get0_type(int /*<<< orphan*/ *);
int /*<<< orphan*/ CMSerr(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ NID_pkcs7_encrypted;
scalar_t__ OBJ_obj2nid(int /*<<< orphan*/);
int /*<<< orphan*/ check_content(int /*<<< orphan*/ *);
int cms_copy_content(int /*<<< orphan*/ *, int /*<<< orphan*/ *, unsigned int);
int /*<<< orphan*/ do_free_upto(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, const unsigned char *key,
                              size_t keylen, BIO *dcont, BIO *out,
                              unsigned int flags) {
  BIO *cont;
  int r;
  if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted) {
    CMSerr(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT, CMS_R_TYPE_NOT_ENCRYPTED_DATA);
    return 0;
  }
  if (!dcont && !check_content(cms))
    return 0;
  if (CMS_EncryptedData_set1_key(cms, NULL, key, keylen) <= 0)
    return 0;
  cont = CMS_dataInit(cms, dcont);
  if (!cont)
    return 0;
  r = cms_copy_content(out, cont, flags);
  do_free_upto(cont, dcont);
  return r;
}


x86 assembly (clang, -O0):
<CMS_EncryptedData_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <CMS_get0_type@plt>
mov    %eax,%edi
call   1030 <OBJ_obj2nid@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11e3 <CMS_EncryptedData_decrypt+0x63>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1040 <CMSerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1285 <CMS_EncryptedData_decrypt+0x105>
cmpq   $0x0,-0x28(%rbp)
jne    120c <CMS_EncryptedData_decrypt+0x8c>
mov    -0x10(%rbp),%rdi
call   1070 <check_content@plt>
cmp    $0x0,%eax
jne    120c <CMS_EncryptedData_decrypt+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    1285 <CMS_EncryptedData_decrypt+0x105>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <CMS_EncryptedData_set1_key@plt>
cmp    $0x0,%rax
jg     1237 <CMS_EncryptedData_decrypt+0xb7>
movl   $0x0,-0x4(%rbp)
jmp    1285 <CMS_EncryptedData_decrypt+0x105>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <CMS_dataInit@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    125f <CMS_EncryptedData_decrypt+0xdf>
movl   $0x0,-0x4(%rbp)
jmp    1285 <CMS_EncryptedData_decrypt+0x105>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1080 <cms_copy_content@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <do_free_upto@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CMS_EncryptedData_decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
call   10a0 <CMS_get0_type@plt>
mov    %eax,%edi
call   1030 <OBJ_obj2nid@plt>
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
jne    120d <CMS_EncryptedData_decrypt+0x8d>
test   %r12,%r12
jne    11c6 <CMS_EncryptedData_decrypt+0x46>
mov    %rbp,%rdi
call   1070 <check_content@plt>
test   %eax,%eax
je     1224 <CMS_EncryptedData_decrypt+0xa4>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1090 <CMS_EncryptedData_set1_key@plt>
test   %rax,%rax
jle    1224 <CMS_EncryptedData_decrypt+0xa4>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1060 <CMS_dataInit@plt>
test   %rax,%rax
je     1224 <CMS_EncryptedData_decrypt+0xa4>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   1080 <cms_copy_content@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <do_free_upto@plt>
mov    %ebp,%eax
jmp    1226 <CMS_EncryptedData_decrypt+0xa6>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
call   1040 <CMSerr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NID_pkcs7_encrypted = global i64 0
@CMS_F_CMS_ENCRYPTEDDATA_DECRYPT = global i32 0
@CMS_R_TYPE_NOT_ENCRYPTED_DATA = global i32 0
define i32 @CMS_EncryptedData_decrypt(i32* %0, i8* %1, i64 %2, i32* %3, i32* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
store i32* %0, i32** %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32 %5, i32* %13
%16 = load i32*, i32** %8
%17 = call i32 @CMS_get0_type(i32* %16)
%18 = call i64 @OBJ_obj2nid(i32 %17)
%19 = load i64, i64* @NID_pkcs7_encrypted
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %6
%22 = load i32, i32* @CMS_F_CMS_ENCRYPTEDDATA_DECRYPT
%23 = load i32, i32* @CMS_R_TYPE_NOT_ENCRYPTED_DATA
%24 = call i32 @CMSerr(i32 %22, i32 %23)
store i32 0, i32* %7
br label %56
25: ; preds = %6
%26 = load i32*, i32** %11
%27 = icmp ne i32* %26, null
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = load i32*, i32** %8
%30 = call i32 @check_content(i32* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
store i32 0, i32* %7
br label %56
33: ; preds = %28, %25
%34 = load i32*, i32** %8
%35 = load i8*, i8** %9
%36 = load i64, i64* %10
%37 = call i64 @CMS_EncryptedData_set1_key(i32* %34, i32* null, i8* %35, i64 %36)
%38 = icmp sle i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 0, i32* %7
br label %56
40: ; preds = %33
%41 = load i32*, i32** %8
%42 = load i32*, i32** %11
%43 = call i32* @CMS_dataInit(i32* %41, i32* %42)
store i32* %43, i32** %14
%44 = load i32*, i32** %14
%45 = icmp ne i32* %44, null
br i1 %45, label %47, label %46
46: ; preds = %40
store i32 0, i32* %7
br label %56
47: ; preds = %40
%48 = load i32*, i32** %12
%49 = load i32*, i32** %14
%50 = load i32, i32* %13
%51 = call i32 @cms_copy_content(i32* %48, i32* %49, i32 %50)
store i32 %51, i32* %15
%52 = load i32*, i32** %14
%53 = load i32*, i32** %11
%54 = call i32 @do_free_upto(i32* %52, i32* %53)
%55 = load i32, i32* %15
store i32 %55, i32* %7
br label %56
56: ; preds = %47, %46, %39, %32, %21
%57 = load i32, i32* %7
ret i32 %57
}

LLVM IR (-O2):
@NID_pkcs7_encrypted = global i64 0
@CMS_F_CMS_ENCRYPTEDDATA_DECRYPT = global i32 0
@CMS_R_TYPE_NOT_ENCRYPTED_DATA = global i32 0
define i32 @CMS_EncryptedData_decrypt(i32* %0, i8* %1, i64 %2, i32* %3, i32* %4, i32 %5) {
%7 = tail call i32 @CMS_get0_type(i32* %0)
%8 = tail call i64 @OBJ_obj2nid(i32 %7)
%9 = load i64, i64* @NID_pkcs7_encrypted
%10 = icmp eq i64 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i32, i32* @CMS_F_CMS_ENCRYPTEDDATA_DECRYPT
%13 = load i32, i32* @CMS_R_TYPE_NOT_ENCRYPTED_DATA
%14 = tail call i32 @CMSerr(i32 %12, i32 %13)
br label %29
15: ; preds = %6
%16 = icmp eq i32* %3, null
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = tail call i32 @check_content(i32* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %17, %15
%21 = tail call i64 @CMS_EncryptedData_set1_key(i32* %0, i32* null, i8* %1, i64 %2)
%22 = icmp slt i64 %21, 1
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = tail call i32* @CMS_dataInit(i32* %0, i32* %3)
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = tail call i32 @cms_copy_content(i32* %4, i32* %24, i32 %5)
%28 = tail call i32 @do_free_upto(i32* %24, i32* %3)
br label %29
29: ; preds = %23, %20, %17, %26, %11
%30 = phi i32 [ 0, %11 ], [ %27, %26 ], [ 0, %17 ], [ 0, %20 ], [ 0, %23 ]
ret i32 %30
}