#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_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_X931(unsigned char *to, int tlen, const unsigned char *from,
                         int flen) {
  int j;
  unsigned char *p;
  j = tlen - flen - 2;
  if (j < 0) {
    RSAerror(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    1176 <RSA_padding_add_X931+0x46>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1050 <RSAerror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <RSA_padding_add_X931+0xf4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    119f <RSA_padding_add_X931+0x6f>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x6a,(%rax)
jmp    11f5 <RSA_padding_add_X931+0xc5>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x6b,(%rax)
cmpl   $0x1,-0x28(%rbp)
jle    11e3 <RSA_padding_add_X931+0xb3>
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     1155 <RSA_padding_add_X931+0x25>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1050 <RSAerror@plt>
mov    $0xffffffff,%eax
jmp    11a8 <RSA_padding_add_X931+0x78>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbx
cmp    $0x2,%ebp
jne    1168 <RSA_padding_add_X931+0x38>
movb   $0x6a,(%rbx)
jmp    118c <RSA_padding_add_X931+0x5c>
movb   $0x6b,(%rbx)
add    $0x1,%rbx
cmp    $0x4,%ebp
jb     1189 <RSA_padding_add_X931+0x59>
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_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 %21
18: ; preds = %4
%19 = load i32, i32* @RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
%20 = call i32 @RSAerror(i32 %19)
store i32 -1, i32* %5
br label %56
21: ; preds = %4
%22 = load i8*, i8** %6
store i8* %22, i8** %11
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %11
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %11
store i8 106, i8* %26
br label %46
28: ; preds = %21
%29 = load i8*, i8** %11
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %11
store i8 107, i8* %29
%31 = load i32, i32* %10
%32 = icmp sgt i32 %31, 1
br i1 %32, label %33, label %43
33: ; preds = %28
%34 = load i8*, i8** %11
%35 = load i32, i32* %10
%36 = sub nsw i32 %35, 1
%37 = call i32 @memset(i8* %34, i32 187, i32 %36)
%38 = load i32, i32* %10
%39 = sub nsw i32 %38, 1
%40 = load i8*, i8** %11
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %11
br label %43
43: ; preds = %33, %28
%44 = load i8*, i8** %11
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %11
store i8 -70, i8* %44
br label %46
46: ; preds = %43, %25
%47 = load i8*, i8** %11
%48 = load i8*, i8** %8
%49 = load i32, i32* %9
%50 = call i32 @memcpy(i8* %47, i8* %48, i32 %49)
%51 = load i32, i32* %9
%52 = load i8*, i8** %11
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %11
%55 = load i8*, i8** %11
store i8 -52, i8* %55
store i32 1, i32* %5
br label %56
56: ; preds = %46, %18
%57 = load i32, i32* %5
ret i32 %57
}

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