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

/* Variables and functions */
int /*<<< orphan*/ EVP_CIPHER_CTX_init(int /*<<< orphan*/ *);
scalar_t__ EVP_CIPHER_CTX_iv_length(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_CIPHER_CTX_key_length(int /*<<< orphan*/ *);
scalar_t__ EVP_CIPHER_CTX_rand_key(int /*<<< orphan*/ *, unsigned char *);
int /*<<< orphan*/ EVP_EncryptInit_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ const *,
                                      int /*<<< orphan*/ *, unsigned char *,
                                      unsigned char *);
int EVP_MAX_KEY_LENGTH;
int EVP_PKEY_encrypt_old(unsigned char *, unsigned char *, int /*<<< orphan*/,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ RAND_pseudo_bytes(unsigned char *, scalar_t__);
int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
                 unsigned char **ek, int *ekl, unsigned char *iv,
                 EVP_PKEY **pubk, int npubk) {
  unsigned char key[EVP_MAX_KEY_LENGTH];
  int i;
  if (type) {
    EVP_CIPHER_CTX_init(ctx);
    if (!EVP_EncryptInit_ex(ctx, type, NULL, NULL, NULL))
      return 0;
  }
  if ((npubk <= 0) || !pubk)
    return 1;
  if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0)
    return 0;
  if (EVP_CIPHER_CTX_iv_length(ctx))
    RAND_pseudo_bytes(iv, EVP_CIPHER_CTX_iv_length(ctx));
  if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv))
    return 0;
  for (i = 0; i < npubk; i++) {
    ekl[i] = EVP_PKEY_encrypt_old(ek[i], key, EVP_CIPHER_CTX_key_length(ctx),
                                  pubk[i]);
    if (ekl[i] <= 0)
      return (-1);
  }
  return (npubk);
}


x86 assembly (clang, -O0):
<EVP_SealInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120c <EVP_SealInit+0x9c>
mov    -0x10(%rbp),%rdi
call   1030 <EVP_CIPHER_CTX_init@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1070 <EVP_EncryptInit_ex@plt>
cmp    $0x0,%eax
jne    1207 <EVP_SealInit+0x97>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    135b <EVP_SealInit+0x1eb>
jmp    120c <EVP_SealInit+0x9c>
cmpl   $0x0,0x10(%rbp)
jle    1221 <EVP_SealInit+0xb1>
cmpq   $0x0,-0x38(%rbp)
jne    1234 <EVP_SealInit+0xc4>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    135b <EVP_SealInit+0x1eb>
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1080 <EVP_CIPHER_CTX_rand_key@plt>
cmp    $0x0,%rax
jg     125e <EVP_SealInit+0xee>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    135b <EVP_SealInit+0x1eb>
mov    -0x10(%rbp),%rdi
call   1040 <EVP_CIPHER_CTX_iv_length@plt>
cmp    $0x0,%rax
je     128e <EVP_SealInit+0x11e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <EVP_CIPHER_CTX_iv_length@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rsi
call   1060 <RAND_pseudo_bytes@plt>
mov    -0x58(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1070 <EVP_EncryptInit_ex@plt>
cmp    $0x0,%eax
jne    12c2 <EVP_SealInit+0x152>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    135b <EVP_SealInit+0x1eb>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    134e <EVP_SealInit+0x1de>
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <EVP_CIPHER_CTX_key_length@plt>
mov    -0x68(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
mov    -0x38(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
call   1050 <EVP_PKEY_encrypt_old@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jg     133b <EVP_SealInit+0x1cb>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    135b <EVP_SealInit+0x1eb>
jmp    1340 <EVP_SealInit+0x1d0>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    12c9 <EVP_SealInit+0x159>
mov    0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EVP_SealInit>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,-0x30(%rbp)
mov    %r8,%rbx
mov    %rcx,-0x40(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rdi,%r13
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %rsi,%rsi
je     11da <EVP_SealInit+0x6a>
mov    %rsi,%r15
mov    %r13,%rdi
call   1030 <EVP_CIPHER_CTX_init@plt>
xor    %r14d,%r14d
mov    %r13,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <EVP_EncryptInit_ex@plt>
test   %eax,%eax
je     129d <EVP_SealInit+0x12d>
mov    $0x1,%r14d
cmpq   $0x0,-0x30(%rbp)
je     129d <EVP_SealInit+0x12d>
mov    0x10(%rbp),%r15d
test   %r15d,%r15d
jle    129d <EVP_SealInit+0x12d>
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <EVP_CIPHER_CTX_rand_key@plt>
test   %rax,%rax
jle    1292 <EVP_SealInit+0x122>
mov    %r13,%rdi
call   1040 <EVP_CIPHER_CTX_iv_length@plt>
test   %rax,%rax
je     122c <EVP_SealInit+0xbc>
mov    %r13,%rdi
call   1040 <EVP_CIPHER_CTX_iv_length@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <RAND_pseudo_bytes@plt>
xor    %r14d,%r14d
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r12,%rcx
mov    %rbx,%r8
call   1070 <EVP_EncryptInit_ex@plt>
test   %eax,%eax
je     129d <EVP_SealInit+0x12d>
mov    %r15d,%r14d
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    -0x38(%rbp),%rax
mov    (%rax,%r15,8),%rbx
mov    %r13,%rdi
call   1090 <EVP_CIPHER_CTX_key_length@plt>
mov    -0x30(%rbp),%rcx
mov    (%rcx,%r15,8),%rcx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <EVP_PKEY_encrypt_old@plt>
mov    -0x40(%rbp),%rcx
mov    %eax,(%rcx,%r15,4)
test   %eax,%eax
jle    1297 <EVP_SealInit+0x127>
add    $0x1,%r15
cmp    %r15,%r14
jne    1250 <EVP_SealInit+0xe0>
mov    0x10(%rbp),%eax
mov    %eax,%r14d
jmp    129d <EVP_SealInit+0x12d>
xor    %r14d,%r14d
jmp    129d <EVP_SealInit+0x12d>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EVP_MAX_KEY_LENGTH = global i32 0
define i32 @EVP_SealInit(i32* %0, i32* %1, i8** %2, i32* %3, i8* %4, i32** %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8**
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32**
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
%19 = alloca i32
store i32* %0, i32** %9
store i32* %1, i32** %10
store i8** %2, i8*** %11
store i32* %3, i32** %12
store i8* %4, i8** %13
store i32** %5, i32*** %14
store i32 %6, i32* %15
%20 = load i32, i32* @EVP_MAX_KEY_LENGTH
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %16
%23 = alloca i8, i64 %21
store i64 %21, i64* %17
%24 = load i32*, i32** %10
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %35
26: ; preds = %7
%27 = load i32*, i32** %9
%28 = call i32 @EVP_CIPHER_CTX_init(i32* %27)
%29 = load i32*, i32** %9
%30 = load i32*, i32** %10
%31 = call i32 @EVP_EncryptInit_ex(i32* %29, i32* %30, i32* null, i8* null, i8* null)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %26
store i32 0, i32* %8
store i32 1, i32* %19
br label %98
34: ; preds = %26
br label %35
35: ; preds = %34, %7
%36 = load i32, i32* %15
%37 = icmp sle i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load i32**, i32*** %14
%40 = icmp ne i32** %39, null
br i1 %40, label %42, label %41
41: ; preds = %38, %35
store i32 1, i32* %8
store i32 1, i32* %19
br label %98
42: ; preds = %38
%43 = load i32*, i32** %9
%44 = call i64 @EVP_CIPHER_CTX_rand_key(i32* %43, i8* %23)
%45 = icmp sle i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 0, i32* %8
store i32 1, i32* %19
br label %98
47: ; preds = %42
%48 = load i32*, i32** %9
%49 = call i64 @EVP_CIPHER_CTX_iv_length(i32* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i8*, i8** %13
%53 = load i32*, i32** %9
%54 = call i64 @EVP_CIPHER_CTX_iv_length(i32* %53)
%55 = call i32 @RAND_pseudo_bytes(i8* %52, i64 %54)
br label %56
56: ; preds = %51, %47
%57 = load i32*, i32** %9
%58 = load i8*, i8** %13
%59 = call i32 @EVP_EncryptInit_ex(i32* %57, i32* null, i32* null, i8* %23, i8* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %62, label %61
61: ; preds = %56
store i32 0, i32* %8
store i32 1, i32* %19
br label %98
62: ; preds = %56
store i32 0, i32* %18
br label %63
63: ; preds = %93, %62
%64 = load i32, i32* %18
%65 = load i32, i32* %15
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %96
67: ; preds = %63
%68 = load i8**, i8*** %11
%69 = load i32, i32* %18
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = load i32*, i32** %9
%74 = call i32 @EVP_CIPHER_CTX_key_length(i32* %73)
%75 = load i32**, i32*** %14
%76 = load i32, i32* %18
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32*, i32** %75, i64 %77
%79 = load i32*, i32** %78
%80 = call i32 @EVP_PKEY_encrypt_old(i8* %72, i8* %23, i32 %74, i32* %79)
%81 = load i32*, i32** %12
%82 = load i32, i32* %18
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %81, i64 %83
store i32 %80, i32* %84
%85 = load i32*, i32** %12
%86 = load i32, i32* %18
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %85, i64 %87
%89 = load i32, i32* %88
%90 = icmp sle i32 %89, 0
br i1 %90, label %91, label %92
91: ; preds = %67
store i32 -1, i32* %8
store i32 1, i32* %19
br label %98
92: ; preds = %67
br label %93
93: ; preds = %92
%94 = load i32, i32* %18
%95 = add nsw i32 %94, 1
store i32 %95, i32* %18
br label %63
96: ; preds = %63
%97 = load i32, i32* %15
store i32 %97, i32* %8
store i32 1, i32* %19
br label %98
98: ; preds = %96, %91, %61, %46, %41, %33
%99 = load i8*, i8** %16
%100 = load i32, i32* %8
ret i32 %100
}

LLVM IR (-O2):
@EVP_MAX_KEY_LENGTH = global i32 0
define i32 @EVP_SealInit(i32* %0, i32* %1, i8** nocapture %2, i32* nocapture writeonly %3, i8* %4, i32** %5, i32 %6) {
%8 = load i32, i32* @EVP_MAX_KEY_LENGTH
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = icmp eq i32* %1, null
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = tail call i32 @EVP_CIPHER_CTX_init(i32* %0)
%14 = tail call i32 @EVP_EncryptInit_ex(i32* %0, i32* %1, i32* null, i8* null, i8* null)
%15 = icmp eq i32 %14, 0
br i1 %15, label %47, label %16
16: ; preds = %12, %7
%17 = icmp sgt i32 %6, 0
%18 = icmp ne i32** %5, null
%19 = and i1 %18, %17
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = call i64 @EVP_CIPHER_CTX_rand_key(i32* %0, i8* %10)
%22 = icmp slt i64 %21, 1
br i1 %22, label %47, label %23
23: ; preds = %20
%24 = call i64 @EVP_CIPHER_CTX_iv_length(i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i64 @EVP_CIPHER_CTX_iv_length(i32* %0)
%28 = call i32 @RAND_pseudo_bytes(i8* %4, i64 %27)
br label %29
29: ; preds = %26, %23
%30 = call i32 @EVP_EncryptInit_ex(i32* %0, i32* null, i32* null, i8* %10, i8* %4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %47, label %32
32: ; preds = %29
%33 = zext i32 %6 to i64
br label %36
34: ; preds = %36
%35 = icmp eq i64 %46, %33
br i1 %35, label %47, label %36
36: ; preds = %32, %34
%37 = phi i64 [ 0, %32 ], [ %46, %34 ]
%38 = getelementptr inbounds i8*, i8** %2, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @EVP_CIPHER_CTX_key_length(i32* %0)
%41 = getelementptr inbounds i32*, i32** %5, i64 %37
%42 = load i32*, i32** %41
%43 = call i32 @EVP_PKEY_encrypt_old(i8* %39, i8* %10, i32 %40, i32* %42)
%44 = getelementptr inbounds i32, i32* %3, i64 %37
store i32 %43, i32* %44
%45 = icmp slt i32 %43, 1
%46 = add nuw nsw i64 %37, 1
br i1 %45, label %47, label %34
47: ; preds = %36, %34, %29, %20, %16, %12
%48 = phi i32 [ 0, %12 ], [ 1, %16 ], [ 0, %20 ], [ 0, %29 ], [ -1, %36 ], [ %6, %34 ]
ret i32 %48
}