#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*/ memcpy(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
                                 unsigned char *from, int flen) {
  int j;
  unsigned char *p;
  if (flen > (tlen - 11))
    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, (unsigned int)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
sub    $0xb,%ecx
cmp    %ecx,%eax
jle    1153 <RSA_padding_add_PKCS1_type_1+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <RSA_padding_add_PKCS1_type_1+0xb6>
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    %esi,%ebp
lea    -0xb(%rbp),%ecx
xor    %eax,%eax
cmp    %r15d,%ecx
jl     1177 <RSA_padding_add_PKCS1_type_1+0x57>
mov    %rdx,%r14
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):
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 = sub nsw i32 %13, 11
%15 = icmp sgt i32 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 0, i32* %5
br label %40
17: ; preds = %4
%18 = load i8*, i8** %6
store i8* %18, i8** %11
%19 = load i8*, i8** %11
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %11
store i8 0, i8* %19
%21 = load i8*, i8** %11
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %11
store i8 1, i8* %21
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 3
%25 = load i32, i32* %9
%26 = sub nsw i32 %24, %25
store i32 %26, i32* %10
%27 = load i8*, i8** %11
%28 = load i32, i32* %10
%29 = call i32 @memset(i8* %27, i32 255, i32 %28)
%30 = load i32, i32* %10
%31 = load i8*, i8** %11
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %11
store i8 0, i8* %34
%36 = load i8*, i8** %11
%37 = load i8*, i8** %8
%38 = load i32, i32* %9
%39 = call i32 @memcpy(i8* %36, i8* %37, i32 %38)
store i32 1, i32* %5
br label %40
40: ; preds = %17, %16
%41 = load i32, i32* %5
ret i32 %41
}

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