#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 */
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_bin2bn(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_bn2bin(int /*<<< orphan*/ *, unsigned char *);
int BN_num_bytes(int /*<<< orphan*/ *);
int pkcs1_v1_5_unpad(BIGNUM *src, BIGNUM *dst) {
  unsigned char srcbin[256] = {0};
  BN_bn2bin(src, srcbin + 256 - BN_num_bytes(src));
  int i;
  if (srcbin[i++] != 0)
    return -1;
  if (srcbin[i++] != 2)
    return -1;
  while (srcbin[i]) {
    i++;
    if (i >= 256)
      return -1;
  }
  i++;
  BN_bin2bn(&srcbin[i], 256 - i, dst);
  return 256 - i;
}


x86 assembly (clang, -O0):
<pkcs1_v1_5_unpad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <BN_num_bytes@plt>
mov    -0x138(%rbp),%rsi
mov    -0x130(%rbp),%rdi
movslq %eax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
call   1060 <BN_bn2bin@plt>
mov    -0x124(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x124(%rbp)
cltq
movzbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11dc <pkcs1_v1_5_unpad+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <pkcs1_v1_5_unpad+0x158>
mov    -0x124(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x124(%rbp)
cltq
movzbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x2,%eax
je     120c <pkcs1_v1_5_unpad+0xcc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <pkcs1_v1_5_unpad+0x158>
jmp    1211 <pkcs1_v1_5_unpad+0xd1>
movslq -0x124(%rbp),%rax
cmpb   $0x0,-0x120(%rbp,%rax,1)
je     1256 <pkcs1_v1_5_unpad+0x116>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
cmpl   $0x100,-0x124(%rbp)
jl     1251 <pkcs1_v1_5_unpad+0x111>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <pkcs1_v1_5_unpad+0x158>
jmp    1211 <pkcs1_v1_5_unpad+0xd1>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
lea    -0x120(%rbp),%rdi
add    %rax,%rdi
mov    $0x100,%esi
sub    -0x124(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <BN_bin2bn@plt>
mov    $0x100,%eax
sub    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkcs1_v1_5_unpad>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
call   1030 <BN_num_bytes@plt>
cltq
neg    %rax
lea    (%rsp,%rax,1),%rsi
add    $0x100,%rsi
mov    %rbx,%rdi
call   1040 <BN_bn2bin@plt>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @pkcs1_v1_5_unpad(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = bitcast [256 x i8]* %6 to i8*
%9 = load i32*, i32** %4
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds i8, i8* %10, i64 256
%12 = load i32*, i32** %4
%13 = call i32 @BN_num_bytes(i32* %12)
%14 = sext i32 %13 to i64
%15 = sub i64 0, %14
%16 = getelementptr inbounds i8, i8* %11, i64 %15
%17 = call i32 @BN_bn2bin(i32* %9, i8* %16)
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %2
store i32 -1, i32* %3
br label %61
26: ; preds = %2
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp ne i32 %32, 2
br i1 %33, label %34, label %35
34: ; preds = %26
store i32 -1, i32* %3
br label %61
35: ; preds = %26
br label %36
36: ; preds = %48, %35
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %36
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = icmp sge i32 %45, 256
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 -1, i32* %3
br label %61
48: ; preds = %42
br label %36
49: ; preds = %36
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %53
%55 = load i32, i32* %7
%56 = sub nsw i32 256, %55
%57 = load i32*, i32** %5
%58 = call i32 @BN_bin2bn(i8* %54, i32 %56, i32* %57)
%59 = load i32, i32* %7
%60 = sub nsw i32 256, %59
store i32 %60, i32* %3
br label %61
61: ; preds = %49, %47, %34, %25
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
define i32 @pkcs1_v1_5_unpad(i32* %0, i32* nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 256
%6 = tail call i32 @BN_num_bytes(i32* %0)
%7 = sext i32 %6 to i64
%8 = sub nsw i64 0, %7
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = call i32 @BN_bn2bin(i32* %0, i8* %9)
ret i32 -1
}