#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_PKCS1_PADDING;
int /*<<< orphan*/ RSA_public_encrypt(int, char *, char *, int /*<<< orphan*/ *,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ *createRSA(char *, int);
void encrypt_for_client(char *buffer, char *pubkey) {
  if (pubkey[0] == '\0')
    return;
  RSA *rsa = createRSA(pubkey, 1);
  char encrypted[256];
  RSA_public_encrypt(256, buffer, encrypted, rsa, RSA_PKCS1_PADDING);
  for (int i = 0; i < 256; ++i)
    buffer[i] = encrypted[i];
}


x86 assembly (clang, -O0):
<encrypt_for_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1148 <encrypt_for_client+0x28>
jmp    11c7 <encrypt_for_client+0xa7>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <createRSA@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x120(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    0x2e68(%rip),%rax
mov    (%rax),%r8d
mov    $0x100,%edi
call   1030 <RSA_public_encrypt@plt>
movl   $0x0,-0x124(%rbp)
cmpl   $0x100,-0x124(%rbp)
jge    11c7 <encrypt_for_client+0xa7>
movslq -0x124(%rbp),%rax
mov    -0x120(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x124(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1187 <encrypt_for_client+0x67>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_for_client>:
push   %r14
push   %rbx
sub    $0x108,%rsp
cmpb   $0x0,(%rsi)
je     117f <encrypt_for_client+0x4f>
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    $0x1,%esi
call   1050 <createRSA@plt>
mov    0x2e82(%rip),%rcx
mov    (%rcx),%r8d
mov    %rsp,%r14
mov    $0x100,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <RSA_public_encrypt@plt>
mov    $0x100,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RSA_PKCS1_PADDING = global i32 0
define void @encrypt_for_client(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %37
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32* @createRSA(i8* %15, i32 1)
store i32* %16, i32** %5
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = load i32, i32* @RSA_PKCS1_PADDING
%21 = call i32 @RSA_public_encrypt(i32 256, i8* %17, i8* %18, i32* %19, i32 %20)
store i32 0, i32* %7
br label %22
22: ; preds = %34, %14
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 256
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %3
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %25
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %22
37: ; preds = %13, %22
ret void
}

LLVM IR (-O2):
@RSA_PKCS1_PADDING = global i32 0
define void @encrypt_for_client(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = tail call i32* @createRSA(i8* %1, i32 1)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @RSA_PKCS1_PADDING
%11 = call i32 @RSA_public_encrypt(i32 256, i8* %0, i8* %9, i32* %8, i32 %10)
br label %12
12: ; preds = %2, %6
ret void
}