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

/* Variables and functions */
int /*<<< orphan*/ RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1;
int RSA_PKCS1_PADDING_SIZE;
int /*<<< orphan*/ RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
int /*<<< orphan*/ RSAerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
                                 const unsigned char *from, int flen) {
  int j;
  unsigned char *p;
  if (flen > (tlen - RSA_PKCS1_PADDING_SIZE)) {
    RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,
           RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
    return 0;
  }
  p = (unsigned char *)to;
  *(p++) = 0;
  *(p++) = 1;
  j = tlen - 3 - flen;
  memset(p, 0xff, j);
  p += j;
  *(p++) = '\0';
  memcpy(p, from, flen);
  return 1;
}


x86 assembly (clang, -O0):
<RSA_padding_add_PKCS1_type_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    0x2e85(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jle    1180 <RSA_padding_add_PKCS1_type_1+0x50>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1203 <RSA_padding_add_PKCS1_type_1+0xd3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x1,(%rax)
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    $0xff,%esi
call   1030 <memset@plt>
mov    -0x28(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RSA_padding_add_PKCS1_type_1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    0x2e97(%rip),%rax
mov    %esi,%ecx
sub    (%rax),%ecx
cmp    %r15d,%ecx
jge    1165 <RSA_padding_add_PKCS1_type_1+0x35>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
xor    %eax,%eax
jmp    11a8 <RSA_padding_add_PKCS1_type_1+0x78>
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
movw   $0x100,(%rdi)
add    $0x2,%rdi
sub    %r15d,%ebp
add    $0xfffffffd,%ebp
mov    $0xff,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
movslq %ebp,%rax
lea    (%rbx,%rax,1),%rdi
add    $0x3,%rdi
movb   $0x0,0x2(%rbx,%rax,1)
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RSA_PKCS1_PADDING_SIZE = global i32 0
@RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 = global i32 0
@RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE = global i32 0
define i32 @RSA_padding_add_PKCS1_type_1(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i32, i32* %9
%13 = load i32, i32* %7
%14 = load i32, i32* @RSA_PKCS1_PADDING_SIZE
%15 = sub nsw i32 %13, %14
%16 = icmp sgt i32 %12, %15
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32, i32* @RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1
%19 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%20 = call i32 @RSAerr(i32 %18, i32 %19)
store i32 0, i32* %5
br label %44
21: ; preds = %4
%22 = load i8*, i8** %6
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %11
store i8 0, i8* %23
%25 = load i8*, i8** %11
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %11
store i8 1, i8* %25
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 3
%29 = load i32, i32* %9
%30 = sub nsw i32 %28, %29
store i32 %30, i32* %10
%31 = load i8*, i8** %11
%32 = load i32, i32* %10
%33 = call i32 @memset(i8* %31, i32 255, i32 %32)
%34 = load i32, i32* %10
%35 = load i8*, i8** %11
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %11
%38 = load i8*, i8** %11
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %11
store i8 0, i8* %38
%40 = load i8*, i8** %11
%41 = load i8*, i8** %8
%42 = load i32, i32* %9
%43 = call i32 @memcpy(i8* %40, i8* %41, i32 %42)
store i32 1, i32* %5
br label %44
44: ; preds = %21, %17
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
@RSA_PKCS1_PADDING_SIZE = global i32 0
@RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 = global i32 0
@RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE = global i32 0
define i32 @RSA_padding_add_PKCS1_type_1(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = load i32, i32* @RSA_PKCS1_PADDING_SIZE
%6 = sub nsw i32 %1, %5
%7 = icmp slt i32 %6, %3
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i32, i32* @RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1
%10 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%11 = tail call i32 @RSAerr(i32 %9, i32 %10)
br label %22
12: ; preds = %4
%13 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %0
%14 = getelementptr inbounds i8, i8* %0, i64 2
store i8 1, i8* %13
%15 = add nsw i32 %1, -3
%16 = sub i32 %15, %3
%17 = tail call i32 @memset(i8* %14, i32 255, i32 %16)
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 0, i8* %19
%21 = tail call i32 @memcpy(i8* %20, i8* %2, i32 %3)
br label %22
22: ; preds = %12, %8
%23 = phi i32 [ 0, %8 ], [ 1, %12 ]
ret i32 %23
}