#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 RSA_PKCS1_PADDING_SIZE;
int /*<<< orphan*/ RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
int /*<<< orphan*/ RSAerror(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)) {
    RSAerror(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    0x2e8d(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jle    1177 <RSA_padding_add_PKCS1_type_1+0x47>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1050 <RSAerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fa <RSA_padding_add_PKCS1_type_1+0xca>
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    0x2e9f(%rip),%rax
mov    %esi,%ecx
sub    (%rax),%ecx
cmp    %r15d,%ecx
jge    115c <RSA_padding_add_PKCS1_type_1+0x2c>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
call   1050 <RSAerror@plt>
xor    %eax,%eax
jmp    119f <RSA_padding_add_PKCS1_type_1+0x6f>
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_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 %20
17: ; preds = %4
%18 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%19 = call i32 @RSAerror(i32 %18)
store i32 0, i32* %5
br label %43
20: ; preds = %4
%21 = load i8*, i8** %6
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %11
store i8 0, i8* %22
%24 = load i8*, i8** %11
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %11
store i8 1, i8* %24
%26 = load i32, i32* %7
%27 = sub nsw i32 %26, 3
%28 = load i32, i32* %9
%29 = sub nsw i32 %27, %28
store i32 %29, i32* %10
%30 = load i8*, i8** %11
%31 = load i32, i32* %10
%32 = call i32 @memset(i8* %30, i32 255, i32 %31)
%33 = load i32, i32* %10
%34 = load i8*, i8** %11
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %11
%37 = load i8*, i8** %11
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %11
store i8 0, i8* %37
%39 = load i8*, i8** %11
%40 = load i8*, i8** %8
%41 = load i32, i32* %9
%42 = call i32 @memcpy(i8* %39, i8* %40, i32 %41)
store i32 1, i32* %5
br label %43
43: ; preds = %20, %17
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
@RSA_PKCS1_PADDING_SIZE = 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 %11
8: ; preds = %4
%9 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%10 = tail call i32 @RSAerror(i32 %9)
br label %21
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %0
%13 = getelementptr inbounds i8, i8* %0, i64 2
store i8 1, i8* %12
%14 = add nsw i32 %1, -3
%15 = sub i32 %14, %3
%16 = tail call i32 @memset(i8* %13, i32 255, i32 %15)
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %18
%20 = tail call i32 @memcpy(i8* %19, i8* %2, i32 %3)
br label %21
21: ; preds = %11, %8
%22 = phi i32 [ 0, %8 ], [ 1, %11 ]
ret i32 %22
}