#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 */
scalar_t__ RAND_bytes(unsigned char *, int);
int /*<<< orphan*/ RSA_F_RSA_PADDING_ADD_SSLV23;
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 *, unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
                           const unsigned char *from, int flen) {
  int i, j;
  unsigned char *p;
  if (flen > (tlen - 11)) {
    RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
    return (0);
  }
  p = (unsigned char *)to;
  *(p++) = 0;
  *(p++) = 2;
  j = tlen - 3 - 8 - flen;
  if (RAND_bytes(p, j) <= 0)
    return (0);
  for (i = 0; i < j; i++) {
    if (*p == '\0')
      do {
        if (RAND_bytes(p, 1) <= 0)
          return (0);
      } while (*p == '\0');
    p++;
  }
  memset(p, 3, 8);
  p += 8;
  *(p++) = '\0';
  memcpy(p, from, (unsigned int)flen);
  return (1);
}


x86 assembly (clang, -O0):
<RSA_padding_add_SSLv23>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    118a <RSA_padding_add_SSLv23+0x4a>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1060 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    12af <RSA_padding_add_SSLv23+0x16f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x2,(%rax)
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
sub    $0x8,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <RAND_bytes@plt>
cmp    $0x0,%rax
jg     11e7 <RSA_padding_add_SSLv23+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    12af <RSA_padding_add_SSLv23+0x16f>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1267 <RSA_padding_add_SSLv23+0x127>
mov    -0x38(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    124d <RSA_padding_add_SSLv23+0x10d>
jmp    120f <RSA_padding_add_SSLv23+0xcf>
mov    -0x38(%rbp),%rdi
mov    $0x1,%esi
call   1030 <RAND_bytes@plt>
cmp    $0x0,%rax
jg     1233 <RSA_padding_add_SSLv23+0xf3>
movl   $0x0,-0x4(%rbp)
jmp    12af <RSA_padding_add_SSLv23+0x16f>
jmp    1238 <RSA_padding_add_SSLv23+0xf8>
mov    -0x38(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     120f <RSA_padding_add_SSLv23+0xcf>
jmp    124d <RSA_padding_add_SSLv23+0x10d>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <RSA_padding_add_SSLv23+0xae>
mov    -0x38(%rbp),%rdi
mov    $0x3,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RSA_padding_add_SSLv23>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
add    $0xfffffff5,%r12d
sub    %ecx,%r12d
jge    1172 <RSA_padding_add_SSLv23+0x32>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
call   1060 <RSAerr@plt>
xor    %eax,%eax
jmp    11f8 <RSA_padding_add_SSLv23+0xb8>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbx
movw   $0x200,(%rdi)
add    $0x2,%rbx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <RAND_bytes@plt>
test   %rax,%rax
jle    11c7 <RSA_padding_add_SSLv23+0x87>
test   %r12d,%r12d
jle    11cb <RSA_padding_add_SSLv23+0x8b>
xor    %ebp,%ebp
jmp    11b0 <RSA_padding_add_SSLv23+0x70>
add    $0x1,%rbx
add    $0x1,%ebp
cmp    %r12d,%ebp
je     11cb <RSA_padding_add_SSLv23+0x8b>
nopl   0x0(%rax)
cmpb   $0x0,(%rbx)
jne    119d <RSA_padding_add_SSLv23+0x5d>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <RAND_bytes@plt>
test   %rax,%rax
jg     11b0 <RSA_padding_add_SSLv23+0x70>
xor    %eax,%eax
jmp    11f8 <RSA_padding_add_SSLv23+0xb8>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movb   $0x0,0x8(%rbx)
add    $0x9,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RSA_F_RSA_PADDING_ADD_SSLV23 = global i32 0
@RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE = global i32 0
define i32 @RSA_padding_add_SSLv23(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 i32
%12 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i32, i32* %9
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 11
%16 = icmp sgt i32 %13, %15
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32, i32* @RSA_F_RSA_PADDING_ADD_SSLV23
%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 %77
21: ; preds = %4
%22 = load i8*, i8** %6
store i8* %22, i8** %12
%23 = load i8*, i8** %12
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %12
store i8 0, i8* %23
%25 = load i8*, i8** %12
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %12
store i8 2, i8* %25
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 3
%29 = sub nsw i32 %28, 8
%30 = load i32, i32* %9
%31 = sub nsw i32 %29, %30
store i32 %31, i32* %11
%32 = load i8*, i8** %12
%33 = load i32, i32* %11
%34 = call i64 @RAND_bytes(i8* %32, i32 %33)
%35 = icmp sle i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %21
store i32 0, i32* %5
br label %77
37: ; preds = %21
store i32 0, i32* %10
br label %38
38: ; preds = %63, %37
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %66
42: ; preds = %38
%43 = load i8*, i8** %12
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %60
47: ; preds = %42
br label %48
48: ; preds = %54, %47
%49 = load i8*, i8** %12
%50 = call i64 @RAND_bytes(i8* %49, i32 1)
%51 = icmp sle i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 0, i32* %5
br label %77
53: ; preds = %48
br label %54
54: ; preds = %53
%55 = load i8*, i8** %12
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 0
br i1 %58, label %48, label %59
59: ; preds = %54
br label %60
60: ; preds = %59, %42
%61 = load i8*, i8** %12
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %12
br label %63
63: ; preds = %60
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %38
66: ; preds = %38
%67 = load i8*, i8** %12
%68 = call i32 @memset(i8* %67, i32 3, i32 8)
%69 = load i8*, i8** %12
%70 = getelementptr inbounds i8, i8* %69, i64 8
store i8* %70, i8** %12
%71 = load i8*, i8** %12
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %12
store i8 0, i8* %71
%73 = load i8*, i8** %12
%74 = load i8*, i8** %8
%75 = load i32, i32* %9
%76 = call i32 @memcpy(i8* %73, i8* %74, i32 %75)
store i32 1, i32* %5
br label %77
77: ; preds = %66, %52, %36, %17
%78 = load i32, i32* %5
ret i32 %78
}

LLVM IR (-O2):
@RSA_F_RSA_PADDING_ADD_SSLV23 = global i32 0
@RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE = global i32 0
define i32 @RSA_padding_add_SSLv23(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = add nsw i32 %1, -11
%6 = icmp slt i32 %5, %3
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @RSA_F_RSA_PADDING_ADD_SSLV23
%9 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%10 = tail call i32 @RSAerr(i32 %8, i32 %9)
br label %40
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 2, i8* %12
%14 = sub nsw i32 %5, %3
%15 = tail call i64 @RAND_bytes(i8* %13, i32 %14)
%16 = icmp slt i64 %15, 1
br i1 %16, label %40, label %17
17: ; preds = %11
%18 = icmp sgt i32 %14, 0
br i1 %18, label %19, label %34
19: ; preds = %17, %30
%20 = phi i8* [ %31, %30 ], [ %13, %17 ]
%21 = phi i32 [ %32, %30 ], [ 0, %17 ]
%22 = load i8, i8* %20
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %19, %27
%25 = tail call i64 @RAND_bytes(i8* %20, i32 1)
%26 = icmp slt i64 %25, 1
br i1 %26, label %40, label %27
27: ; preds = %24
%28 = load i8, i8* %20
%29 = icmp eq i8 %28, 0
br i1 %29, label %24, label %30
30: ; preds = %27, %19
%31 = getelementptr inbounds i8, i8* %20, i64 1
%32 = add nuw nsw i32 %21, 1
%33 = icmp eq i32 %32, %14
br i1 %33, label %34, label %19
34: ; preds = %30, %17
%35 = phi i8* [ %13, %17 ], [ %31, %30 ]
%36 = tail call i32 @memset(i8* %35, i32 3, i32 8)
%37 = getelementptr inbounds i8, i8* %35, i64 8
%38 = getelementptr inbounds i8, i8* %35, i64 9
store i8 0, i8* %37
%39 = tail call i32 @memcpy(i8* %38, i8* %2, i32 %3)
br label %40
40: ; preds = %24, %11, %34, %7
%41 = phi i32 [ 0, %7 ], [ 1, %34 ], [ 0, %11 ], [ 0, %24 ]
ret i32 %41
}