#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_X931;
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_X931(unsigned char *to, int tlen, const unsigned char *from,
                         int flen) {
  int j;
  unsigned char *p;
  j = tlen - flen - 2;
  if (j < 0) {
    RSAerr(RSA_F_RSA_PADDING_ADD_X931, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
    return -1;
  }
  p = (unsigned char *)to;
  if (j == 0)
    *p++ = 0x6A;
  else {
    *p++ = 0x6B;
    if (j > 1) {
      memset(p, 0xBB, j - 1);
      p += j - 1;
    }
    *p++ = 0xBA;
  }
  memcpy(p, from, flen);
  p += flen;
  *p = 0xCC;
  return 1;
}


x86 assembly (clang, -O0):
<RSA_padding_add_X931>:
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    -0x14(%rbp),%eax
sub    -0x24(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    117f <RSA_padding_add_X931+0x4f>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <RSA_padding_add_X931+0xfd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    11a8 <RSA_padding_add_X931+0x78>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x6a,(%rax)
jmp    11fe <RSA_padding_add_X931+0xce>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x6b,(%rax)
cmpl   $0x1,-0x28(%rbp)
jle    11ec <RSA_padding_add_X931+0xbc>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%edx
sub    $0x1,%edx
mov    $0xbb,%esi
call   1030 <memset@plt>
mov    -0x28(%rbp),%ecx
sub    $0x1,%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   $0xba,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0xcc,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RSA_padding_add_X931>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
sub    %ecx,%ebp
cmp    $0x1,%ebp
jg     115e <RSA_padding_add_X931+0x2e>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
mov    $0xffffffff,%eax
jmp    11b1 <RSA_padding_add_X931+0x81>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbx
cmp    $0x2,%ebp
jne    1171 <RSA_padding_add_X931+0x41>
movb   $0x6a,(%rbx)
jmp    1195 <RSA_padding_add_X931+0x65>
movb   $0x6b,(%rbx)
add    $0x1,%rbx
cmp    $0x4,%ebp
jb     1192 <RSA_padding_add_X931+0x62>
add    $0xfffffffd,%ebp
mov    %rbx,%rdi
mov    $0xbb,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
add    %rbp,%rbx
movb   $0xba,(%rbx)
lea    0x1(%rbx),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
movslq %r15d,%rax
movb   $0xcc,0x1(%rbx,%rax,1)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RSA_F_RSA_PADDING_ADD_X931 = global i32 0
@RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE = global i32 0
define i32 @RSA_padding_add_X931(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* %7
%13 = load i32, i32* %9
%14 = sub nsw i32 %12, %13
%15 = sub nsw i32 %14, 2
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %4
%19 = load i32, i32* @RSA_F_RSA_PADDING_ADD_X931
%20 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%21 = call i32 @RSAerr(i32 %19, i32 %20)
store i32 -1, i32* %5
br label %57
22: ; preds = %4
%23 = load i8*, i8** %6
store i8* %23, i8** %11
%24 = load i32, i32* %10
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %11
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %11
store i8 106, i8* %27
br label %47
29: ; preds = %22
%30 = load i8*, i8** %11
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %11
store i8 107, i8* %30
%32 = load i32, i32* %10
%33 = icmp sgt i32 %32, 1
br i1 %33, label %34, label %44
34: ; preds = %29
%35 = load i8*, i8** %11
%36 = load i32, i32* %10
%37 = sub nsw i32 %36, 1
%38 = call i32 @memset(i8* %35, i32 187, i32 %37)
%39 = load i32, i32* %10
%40 = sub nsw i32 %39, 1
%41 = load i8*, i8** %11
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %11
br label %44
44: ; preds = %34, %29
%45 = load i8*, i8** %11
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %11
store i8 -70, i8* %45
br label %47
47: ; preds = %44, %26
%48 = load i8*, i8** %11
%49 = load i8*, i8** %8
%50 = load i32, i32* %9
%51 = call i32 @memcpy(i8* %48, i8* %49, i32 %50)
%52 = load i32, i32* %9
%53 = load i8*, i8** %11
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8, i8* %53, i64 %54
store i8* %55, i8** %11
%56 = load i8*, i8** %11
store i8 -52, i8* %56
store i32 1, i32* %5
br label %57
57: ; preds = %47, %18
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
@RSA_F_RSA_PADDING_ADD_X931 = global i32 0
@RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE = global i32 0
define i32 @RSA_padding_add_X931(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = sub nsw i32 %1, %3
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @RSA_F_RSA_PADDING_ADD_X931
%9 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%10 = tail call i32 @RSAerr(i32 %8, i32 %9)
br label %30
11: ; preds = %4
%12 = icmp eq i32 %5, 2
br i1 %12, label %13, label %14
13: ; preds = %11
store i8 106, i8* %0
br label %24
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %0, i64 1
store i8 107, i8* %0
%16 = icmp ugt i32 %5, 3
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = add nsw i32 %5, -3
%19 = tail call i32 @memset(i8* %15, i32 187, i32 %18)
%20 = zext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %15, i64 %20
br label %22
22: ; preds = %17, %14
%23 = phi i8* [ %21, %17 ], [ %15, %14 ]
store i8 -70, i8* %23
br label %24
24: ; preds = %22, %13
%25 = phi i8* [ %0, %13 ], [ %23, %22 ]
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = tail call i32 @memcpy(i8* %26, i8* %2, i32 %3)
%28 = sext i32 %3 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 -52, i8* %29
br label %30
30: ; preds = %24, %7
%31 = phi i32 [ -1, %7 ], [ 1, %24 ]
ret i32 %31
}