#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*/ RSA;

/* Variables and functions */
int /*<<< orphan*/ RSA_NO_PADDING;
int /*<<< orphan*/ RSA_PKCS1_PADDING;
int RSA_public_encrypt(int, unsigned char *, unsigned char *,
                       int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *createRSAWithFilename(unsigned char *, int);
int public_encrypt(unsigned char *data, int data_len, unsigned char *filename,
                   unsigned char *encrypted, int pad) {
  RSA *rsa = createRSAWithFilename(filename, 1);
  int result;
  if (pad)
    result =
        RSA_public_encrypt(data_len, data, encrypted, rsa, RSA_PKCS1_PADDING);
  else
    result = RSA_public_encrypt(data_len, data, encrypted, rsa, RSA_NO_PADDING);
  return result;
}


x86 assembly (clang, -O0):
<public_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <createRSAWithFilename@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     117d <public_encrypt+0x5d>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    0x2e63(%rip),%rax
mov    (%rax),%r8d
call   1030 <RSA_public_encrypt@plt>
mov    %eax,-0x34(%rbp)
jmp    119e <public_encrypt+0x7e>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    0x2e55(%rip),%rax
mov    (%rax),%r8d
call   1030 <RSA_public_encrypt@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<public_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    %rdx,%rdi
mov    $0x1,%esi
call   1040 <createRSAWithFilename@plt>
test   %ebx,%ebx
jne    114c <public_encrypt+0x2c>
mov    0x2e9e(%rip),%rcx
jmp    1153 <public_encrypt+0x33>
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%r8d
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <RSA_public_encrypt@plt>

LLVM IR (-O0):
@RSA_PKCS1_PADDING = global i32 0
@RSA_NO_PADDING = global i32 0
define i32 @public_encrypt(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%13 = load i8*, i8** %8
%14 = call i32* @createRSAWithFilename(i8* %13, i32 1)
store i32* %14, i32** %11
%15 = load i32, i32* %10
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %5
%18 = load i32, i32* %7
%19 = load i8*, i8** %6
%20 = load i8*, i8** %9
%21 = load i32*, i32** %11
%22 = load i32, i32* @RSA_PKCS1_PADDING
%23 = call i32 @RSA_public_encrypt(i32 %18, i8* %19, i8* %20, i32* %21, i32 %22)
store i32 %23, i32* %12
br label %31
24: ; preds = %5
%25 = load i32, i32* %7
%26 = load i8*, i8** %6
%27 = load i8*, i8** %9
%28 = load i32*, i32** %11
%29 = load i32, i32* @RSA_NO_PADDING
%30 = call i32 @RSA_public_encrypt(i32 %25, i8* %26, i8* %27, i32* %28, i32 %29)
store i32 %30, i32* %12
br label %31
31: ; preds = %24, %17
%32 = load i32, i32* %12
ret i32 %32
}

LLVM IR (-O2):
@RSA_PKCS1_PADDING = global i32 0
@RSA_NO_PADDING = global i32 0
define i32 @public_encrypt(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = tail call i32* @createRSAWithFilename(i8* %2, i32 1)
%7 = icmp eq i32 %4, 0
%8 = load i32, i32* @RSA_NO_PADDING
%9 = load i32, i32* @RSA_PKCS1_PADDING
%10 = select i1 %7, i32 %8, i32 %9
%11 = tail call i32 @RSA_public_encrypt(i32 %1, i8* %0, i8* %3, i32* %6, i32 %10)
ret i32 %11
}