#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)) {
    flags &= ~CMS_STREAM;
    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    1287 <CMS_EncryptedData_encrypt+0x127>
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    1287 <CMS_EncryptedData_encrypt+0x127>
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    1287 <CMS_EncryptedData_encrypt+0x127>
mov    -0x2c(%rbp),%eax
mov    0x2df5(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    122b <CMS_EncryptedData_encrypt+0xcb>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    -0x2c(%rbp),%eax
mov    0x2da3(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d7a(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1269 <CMS_EncryptedData_encrypt+0x109>
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     1276 <CMS_EncryptedData_encrypt+0x116>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1287 <CMS_EncryptedData_encrypt+0x127>
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     1205 <CMS_EncryptedData_encrypt+0xa5>
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     121c <CMS_EncryptedData_encrypt+0xbc>
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     121c <CMS_EncryptedData_encrypt+0xbc>
mov    0x2e46(%rip),%rax
test   %r15d,(%rax)
jne    11cf <CMS_EncryptedData_encrypt+0x6f>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <CMS_set_detached@plt>
mov    0x2e02(%rip),%rax
mov    0x2ddb(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
test   %r15d,%ecx
jne    121e <CMS_EncryptedData_encrypt+0xbe>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %r15d,%ecx
call   1070 <CMS_final@plt>
test   %rax,%rax
jne    121e <CMS_EncryptedData_encrypt+0xbe>
mov    %rbx,%rdi
call   1080 <CMS_ContentInfo_free@plt>
jmp    121c <CMS_EncryptedData_encrypt+0xbc>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    0x2db3(%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 %62
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 %62
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 %62
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 %44, label %37
37: ; preds = %32
%38 = load i32, i32* @CMS_STREAM
%39 = xor i32 %38, -1
%40 = load i32, i32* %11
%41 = and i32 %40, %39
store i32 %41, i32* %11
%42 = load i32*, i32** %12
%43 = call i32 @CMS_set_detached(i32* %42, i32 0)
br label %44
44: ; preds = %37, %32
%45 = load i32, i32* %11
%46 = load i32, i32* @CMS_STREAM
%47 = load i32, i32* @CMS_PARTIAL
%48 = or i32 %46, %47
%49 = and i32 %45, %48
%50 = icmp ne i32 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %44
%52 = load i32*, i32** %12
%53 = load i32*, i32** %7
%54 = load i32, i32* %11
%55 = call i64 @CMS_final(i32* %52, i32* %53, i32* null, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %51, %44
%58 = load i32*, i32** %12
store i32* %58, i32** %6
br label %62
59: ; preds = %51
%60 = load i32*, i32** %12
%61 = call i32 @CMS_ContentInfo_free(i32* %60)
store i32* null, i32** %6
br label %62
62: ; preds = %59, %57, %31, %23, %15
%63 = load i32*, i32** %6
ret i32* %63
}

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 %38
11: ; preds = %5
%12 = tail call i32* (...) @CMS_ContentInfo_new()
%13 = icmp eq i32* %12, null
br i1 %13, label %38, 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 %38, 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 %26
21: ; preds = %17
%22 = load i32, i32* @CMS_STREAM
%23 = xor i32 %22, -1
%24 = and i32 %23, %4
%25 = tail call i32 @CMS_set_detached(i32* %12, i32 0)
br label %26
26: ; preds = %21, %17
%27 = phi i32 [ %4, %17 ], [ %24, %21 ]
%28 = load i32, i32* @CMS_STREAM
%29 = load i32, i32* @CMS_PARTIAL
%30 = or i32 %29, %28
%31 = and i32 %30, %27
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %26
%34 = tail call i64 @CMS_final(i32* %12, i32* %0, i32* null, i32 %27)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = tail call i32 @CMS_ContentInfo_free(i32* %12)
br label %38
38: ; preds = %26, %33, %14, %11, %36, %7
%39 = phi i32* [ null, %36 ], [ null, %7 ], [ null, %11 ], [ null, %14 ], [ %12, %33 ], [ %12, %26 ]
ret i32* %39
}