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

/* Variables and functions */
int /*<<< orphan*/ CMS_ContentInfo_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *CMS_ContentInfo_new();
unsigned int CMS_DETACHED;
int /*<<< orphan*/ CMS_EncryptedData_set1_key(int /*<<< orphan*/ *,
                                              int /*<<< orphan*/ const *,
                                              unsigned char const *, size_t);
int /*<<< orphan*/ CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT;
unsigned int CMS_PARTIAL;
int /*<<< orphan*/ CMS_R_NO_CIPHER;
unsigned int CMS_STREAM;
scalar_t__ CMS_final(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *, unsigned int);
int /*<<< orphan*/ CMS_set_detached(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ CMSerr(int /*<<< orphan*/, int /*<<< orphan*/);
CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
                                           const unsigned char *key,
                                           size_t keylen, unsigned int flags) {
  CMS_ContentInfo *cms;
  if (!cipher) {
    CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER);
    return NULL;
  }
  cms = CMS_ContentInfo_new();
  if (!cms)
    return NULL;
  if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen))
    return NULL;
  if (!(flags & CMS_DETACHED))
    CMS_set_detached(cms, 0);
  if ((flags & (CMS_STREAM | CMS_PARTIAL)) || CMS_final(cms, in, NULL, flags))
    return cms;
  CMS_ContentInfo_free(cms);
  return NULL;
}


x86 assembly (clang, -O0):
<CMS_EncryptedData_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <CMS_EncryptedData_encrypt+0x4b>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    1275 <CMS_EncryptedData_encrypt+0x115>
mov    $0x0,%al
call   1060 <CMS_ContentInfo_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ce <CMS_EncryptedData_encrypt+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    1275 <CMS_EncryptedData_encrypt+0x115>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <CMS_EncryptedData_set1_key@plt>
cmp    $0x0,%eax
jne    11f9 <CMS_EncryptedData_encrypt+0x99>
movq   $0x0,-0x8(%rbp)
jmp    1275 <CMS_EncryptedData_encrypt+0x115>
mov    -0x2c(%rbp),%eax
mov    0x2df5(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1219 <CMS_EncryptedData_encrypt+0xb9>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    -0x2c(%rbp),%eax
mov    0x2db5(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d8c(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1257 <CMS_EncryptedData_encrypt+0xf7>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edx
call   1070 <CMS_final@plt>
cmp    $0x0,%rax
je     1264 <CMS_EncryptedData_encrypt+0x104>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1275 <CMS_EncryptedData_encrypt+0x115>
mov    -0x38(%rbp),%rdi
call   1080 <CMS_ContentInfo_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CMS_EncryptedData_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11ef <CMS_EncryptedData_encrypt+0x8f>
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <CMS_ContentInfo_new@plt>
test   %rax,%rax
je     1206 <CMS_EncryptedData_encrypt+0xa6>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
call   1050 <CMS_EncryptedData_set1_key@plt>
test   %eax,%eax
je     1206 <CMS_EncryptedData_encrypt+0xa6>
mov    0x2e4e(%rip),%rax
test   %r15d,(%rax)
jne    11b9 <CMS_EncryptedData_encrypt+0x59>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    0x2e18(%rip),%rax
mov    0x2df1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
test   %r15d,%ecx
jne    1208 <CMS_EncryptedData_encrypt+0xa8>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %r15d,%ecx
call   1070 <CMS_final@plt>
test   %rax,%rax
jne    1208 <CMS_EncryptedData_encrypt+0xa8>
mov    %rbx,%rdi
call   1080 <CMS_ContentInfo_free@plt>
jmp    1206 <CMS_EncryptedData_encrypt+0xa6>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT = global i32 0
@CMS_R_NO_CIPHER = global i32 0
@CMS_DETACHED = global i32 0
@CMS_STREAM = global i32 0
@CMS_PARTIAL = global i32 0
define i32* @CMS_EncryptedData_encrypt(i32* %0, i32* %1, i8* %2, i64 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32*
store i32* %0, i32** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i32 %4, i32* %11
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %19, label %15
15: ; preds = %5
%16 = load i32, i32* @CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT
%17 = load i32, i32* @CMS_R_NO_CIPHER
%18 = call i32 @CMSerr(i32 %16, i32 %17)
store i32* null, i32** %6
br label %58
19: ; preds = %5
%20 = call i32* (...) @CMS_ContentInfo_new()
store i32* %20, i32** %12
%21 = load i32*, i32** %12
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %19
store i32* null, i32** %6
br label %58
24: ; preds = %19
%25 = load i32*, i32** %12
%26 = load i32*, i32** %8
%27 = load i8*, i8** %9
%28 = load i64, i64* %10
%29 = call i32 @CMS_EncryptedData_set1_key(i32* %25, i32* %26, i8* %27, i64 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %24
store i32* null, i32** %6
br label %58
32: ; preds = %24
%33 = load i32, i32* %11
%34 = load i32, i32* @CMS_DETACHED
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = load i32*, i32** %12
%39 = call i32 @CMS_set_detached(i32* %38, i32 0)
br label %40
40: ; preds = %37, %32
%41 = load i32, i32* %11
%42 = load i32, i32* @CMS_STREAM
%43 = load i32, i32* @CMS_PARTIAL
%44 = or i32 %42, %43
%45 = and i32 %41, %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %53, label %47
47: ; preds = %40
%48 = load i32*, i32** %12
%49 = load i32*, i32** %7
%50 = load i32, i32* %11
%51 = call i64 @CMS_final(i32* %48, i32* %49, i32* null, i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %47, %40
%54 = load i32*, i32** %12
store i32* %54, i32** %6
br label %58
55: ; preds = %47
%56 = load i32*, i32** %12
%57 = call i32 @CMS_ContentInfo_free(i32* %56)
store i32* null, i32** %6
br label %58
58: ; preds = %55, %53, %31, %23, %15
%59 = load i32*, i32** %6
ret i32* %59
}

LLVM IR (-O2):
@CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT = global i32 0
@CMS_R_NO_CIPHER = global i32 0
@CMS_DETACHED = global i32 0
@CMS_STREAM = global i32 0
@CMS_PARTIAL = global i32 0
define i32* @CMS_EncryptedData_encrypt(i32* %0, i32* %1, i8* %2, i64 %3, i32 %4) {
%6 = icmp eq i32* %1, null
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = load i32, i32* @CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT
%9 = load i32, i32* @CMS_R_NO_CIPHER
%10 = tail call i32 @CMSerr(i32 %8, i32 %9)
br label %34
11: ; preds = %5
%12 = tail call i32* (...) @CMS_ContentInfo_new()
%13 = icmp eq i32* %12, null
br i1 %13, label %34, label %14
14: ; preds = %11
%15 = tail call i32 @CMS_EncryptedData_set1_key(i32* %12, i32* %1, i8* %2, i64 %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %34, label %17
17: ; preds = %14
%18 = load i32, i32* @CMS_DETACHED
%19 = and i32 %18, %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @CMS_set_detached(i32* %12, i32 0)
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* @CMS_STREAM
%25 = load i32, i32* @CMS_PARTIAL
%26 = or i32 %25, %24
%27 = and i32 %26, %4
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = tail call i64 @CMS_final(i32* %12, i32* %0, i32* null, i32 %4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @CMS_ContentInfo_free(i32* %12)
br label %34
34: ; preds = %23, %29, %14, %11, %32, %7
%35 = phi i32* [ null, %32 ], [ null, %7 ], [ null, %11 ], [ null, %14 ], [ %12, %29 ], [ %12, %23 ]
ret i32* %35
}