#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;

/* Variables and functions */
int /*<<< orphan*/ EVP_F_EVP_PKEY_ENCRYPT_OLD;
scalar_t__ EVP_PKEY_RSA;
int /*<<< orphan*/ EVP_PKEY_get0_RSA(int /*<<< orphan*/ *);
scalar_t__ EVP_PKEY_id(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_R_PUBLIC_KEY_NOT_RSA;
int /*<<< orphan*/ EVPerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ RSA_PKCS1_PADDING;
int RSA_public_encrypt(int, unsigned char const *, unsigned char *,
                       int /*<<< orphan*/, int /*<<< orphan*/);
int EVP_PKEY_encrypt_old(unsigned char *ek, const unsigned char *key,
                         int key_len, EVP_PKEY *pubk) {
  int ret = 0;
  if (EVP_PKEY_id(pubk) != EVP_PKEY_RSA) {
    EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, EVP_R_PUBLIC_KEY_NOT_RSA);
    goto err;
  }
  ret = RSA_public_encrypt(key_len, key, ek, EVP_PKEY_get0_RSA(pubk),
                           RSA_PKCS1_PADDING);
err:
  return ret;
}


x86 assembly (clang, -O0):
<EVP_PKEY_encrypt_old>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <EVP_PKEY_id@plt>
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
je     1193 <EVP_PKEY_encrypt_old+0x53>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1040 <EVPerr@plt>
jmp    11d1 <EVP_PKEY_encrypt_old+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <EVP_PKEY_get0_RSA@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    0x2dfa(%rip),%rax
mov    (%rax),%r8d
call   1030 <RSA_public_encrypt@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EVP_PKEY_encrypt_old>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rcx,%rdi
call   1060 <EVP_PKEY_id@plt>
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%rax
jne    1191 <EVP_PKEY_encrypt_old+0x51>
mov    %rbx,%rdi
call   1050 <EVP_PKEY_get0_RSA@plt>
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%r8d
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <RSA_public_encrypt@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
call   1040 <EVPerr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EVP_PKEY_RSA = global i64 0
@EVP_F_EVP_PKEY_ENCRYPT_OLD = global i32 0
@EVP_R_PUBLIC_KEY_NOT_RSA = global i32 0
@RSA_PKCS1_PADDING = global i32 0
define i32 @EVP_PKEY_encrypt_old(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
%10 = load i32*, i32** %8
%11 = call i64 @EVP_PKEY_id(i32* %10)
%12 = load i64, i64* @EVP_PKEY_RSA
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32, i32* @EVP_F_EVP_PKEY_ENCRYPT_OLD
%16 = load i32, i32* @EVP_R_PUBLIC_KEY_NOT_RSA
%17 = call i32 @EVPerr(i32 %15, i32 %16)
br label %26
18: ; preds = %4
%19 = load i32, i32* %7
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = load i32*, i32** %8
%23 = call i32 @EVP_PKEY_get0_RSA(i32* %22)
%24 = load i32, i32* @RSA_PKCS1_PADDING
%25 = call i32 @RSA_public_encrypt(i32 %19, i8* %20, i8* %21, i32 %23, i32 %24)
store i32 %25, i32* %9
br label %26
26: ; preds = %18, %14
%27 = load i32, i32* %9
ret i32 %27
}

LLVM IR (-O2):
@EVP_PKEY_RSA = global i64 0
@EVP_F_EVP_PKEY_ENCRYPT_OLD = global i32 0
@EVP_R_PUBLIC_KEY_NOT_RSA = global i32 0
@RSA_PKCS1_PADDING = global i32 0
define i32 @EVP_PKEY_encrypt_old(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = tail call i64 @EVP_PKEY_id(i32* %3)
%6 = load i64, i64* @EVP_PKEY_RSA
%7 = icmp eq i64 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @EVP_F_EVP_PKEY_ENCRYPT_OLD
%10 = load i32, i32* @EVP_R_PUBLIC_KEY_NOT_RSA
%11 = tail call i32 @EVPerr(i32 %9, i32 %10)
br label %16
12: ; preds = %4
%13 = tail call i32 @EVP_PKEY_get0_RSA(i32* %3)
%14 = load i32, i32* @RSA_PKCS1_PADDING
%15 = tail call i32 @RSA_public_encrypt(i32 %2, i8* %1, i8* %0, i32 %13, i32 %14)
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ 0, %8 ], [ %15, %12 ]
ret i32 %17
}