#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ data;
  scalar_t__ length;
};
typedef int /*<<< orphan*/ RSA;
typedef TYPE_1__ ASN1_OCTET_STRING;

/* Variables and functions */
int /*<<< orphan*/ ASN1_OCTET_STRING_free(TYPE_1__ *);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ RSA_F_RSA_VERIFY_ASN1_OCTET_STRING;
int /*<<< orphan*/ RSA_PKCS1_PADDING;
int /*<<< orphan*/ RSA_R_BAD_SIGNATURE;
int /*<<< orphan*/ RSA_R_WRONG_SIGNATURE_LENGTH;
int RSA_public_decrypt(int, unsigned char *, unsigned char *,
                       int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ RSA_size(int /*<<< orphan*/ *);
int /*<<< orphan*/ RSAerr(int /*<<< orphan*/, int /*<<< orphan*/);
TYPE_1__ *d2i_ASN1_OCTET_STRING(int /*<<< orphan*/ *, unsigned char const **,
                                long);
int /*<<< orphan*/ explicit_bzero(unsigned char *, unsigned int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(unsigned int);
scalar_t__ memcmp(unsigned char const *, int /*<<< orphan*/, unsigned int);
int RSA_verify_ASN1_OCTET_STRING(int dtype, const unsigned char *m,
                                 unsigned int m_len, unsigned char *sigbuf,
                                 unsigned int siglen, RSA *rsa) {
  int i, ret = 0;
  unsigned char *s;
  const unsigned char *p;
  ASN1_OCTET_STRING *sig = NULL;
  if (siglen != (unsigned int)RSA_size(rsa)) {
    RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, RSA_R_WRONG_SIGNATURE_LENGTH);
    return 0;
  }
  s = malloc(siglen);
  if (s == NULL) {
    RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE);
    goto err;
  }
  i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING);
  if (i <= 0)
    goto err;
  p = s;
  sig = d2i_ASN1_OCTET_STRING(NULL, &p, (long)i);
  if (sig == NULL)
    goto err;
  if ((unsigned int)sig->length != m_len || memcmp(m, sig->data, m_len) != 0) {
    RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, RSA_R_BAD_SIGNATURE);
  } else
    ret = 1;
err:
  ASN1_OCTET_STRING_free(sig);
  if (s != NULL) {
    explicit_bzero(s, (unsigned int)siglen);
    free(s);
  }
  return ret;
}


x86 assembly (clang, -O0):
<RSA_verify_ASN1_OCTET_STRING>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <RSA_size@plt>
mov    %rax,%rcx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
je     11fd <RSA_verify_ASN1_OCTET_STRING+0x6d>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   10a0 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <RSA_verify_ASN1_OCTET_STRING+0x181>
mov    -0x24(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1230 <RSA_verify_ASN1_OCTET_STRING+0xa0>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
call   10a0 <RSAerr@plt>
jmp    12e2 <RSA_verify_ASN1_OCTET_STRING+0x152>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    0x2d72(%rip),%rax
mov    (%rax),%r8d
call   1080 <RSA_public_decrypt@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jg     1260 <RSA_verify_ASN1_OCTET_STRING+0xd0>
jmp    12e2 <RSA_verify_ASN1_OCTET_STRING+0x152>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
movslq -0x34(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x48(%rbp),%rsi
call   1050 <d2i_ASN1_OCTET_STRING@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    128d <RSA_verify_ASN1_OCTET_STRING+0xfd>
jmp    12e2 <RSA_verify_ASN1_OCTET_STRING+0x152>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rax
cmp    -0x14(%rbp),%eax
jne    12ba <RSA_verify_ASN1_OCTET_STRING+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     12d6 <RSA_verify_ASN1_OCTET_STRING+0x146>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
call   10a0 <RSAerr@plt>
jmp    12dd <RSA_verify_ASN1_OCTET_STRING+0x14d>
movl   $0x1,-0x38(%rbp)
jmp    12e2 <RSA_verify_ASN1_OCTET_STRING+0x152>
mov    -0x50(%rbp),%rdi
call   1060 <ASN1_OCTET_STRING_free@plt>
cmpq   $0x0,-0x40(%rbp)
je     130b <RSA_verify_ASN1_OCTET_STRING+0x17b>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10b0 <explicit_bzero@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RSA_verify_ASN1_OCTET_STRING>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbp
mov    %r8d,%r12d
mov    %rcx,%rbx
mov    %edx,%r13d
mov    %rsi,%r15
mov    %r9,%rdi
call   1040 <RSA_size@plt>
cmp    %r12d,%eax
jne    1246 <RSA_verify_ASN1_OCTET_STRING+0xb6>
mov    %r12d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1262 <RSA_verify_ASN1_OCTET_STRING+0xd2>
mov    %rax,%r14
mov    0x2de2(%rip),%rax
mov    (%rax),%r8d
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1080 <RSA_public_decrypt@plt>
test   %eax,%eax
jle    1285 <RSA_verify_ASN1_OCTET_STRING+0xf5>
mov    %r15,%rbx
mov    %r14,(%rsp)
mov    %eax,%edx
xor    %r15d,%r15d
mov    %rsp,%rsi
xor    %edi,%edi
call   1050 <d2i_ASN1_OCTET_STRING@plt>
test   %rax,%rax
je     1288 <RSA_verify_ASN1_OCTET_STRING+0xf8>
mov    %rax,%rbp
cmp    %r13d,0x8(%rax)
jne    122d <RSA_verify_ASN1_OCTET_STRING+0x9d>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
mov    %r13d,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
je     12b7 <RSA_verify_ASN1_OCTET_STRING+0x127>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
call   10a0 <RSAerr@plt>
jmp    128a <RSA_verify_ASN1_OCTET_STRING+0xfa>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
call   10a0 <RSAerr@plt>
xor    %r15d,%r15d
jmp    12a5 <RSA_verify_ASN1_OCTET_STRING+0x115>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
call   10a0 <RSAerr@plt>
xor    %r15d,%r15d
xor    %edi,%edi
call   1060 <ASN1_OCTET_STRING_free@plt>
jmp    12a5 <RSA_verify_ASN1_OCTET_STRING+0x115>
xor    %r15d,%r15d
xor    %ebp,%ebp
mov    %rbp,%rdi
call   1060 <ASN1_OCTET_STRING_free@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   10b0 <explicit_bzero@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r15d
jmp    128a <RSA_verify_ASN1_OCTET_STRING+0xfa>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i64 }
@RSA_F_RSA_VERIFY_ASN1_OCTET_STRING = global i32 0
@RSA_R_WRONG_SIGNATURE_LENGTH = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@RSA_PKCS1_PADDING = global i32 0
@RSA_R_BAD_SIGNATURE = global i32 0
define i32 @RSA_verify_ASN1_OCTET_STRING(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca %struct.TYPE_4__*
store i32 %0, i32* %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32* %5, i32** %13
store i32 0, i32* %15
store %struct.TYPE_4__* null, %struct.TYPE_4__** %18
%19 = load i32, i32* %12
%20 = load i32*, i32** %13
%21 = call i64 @RSA_size(i32* %20)
%22 = trunc i64 %21 to i32
%23 = icmp ne i32 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %6
%25 = load i32, i32* @RSA_F_RSA_VERIFY_ASN1_OCTET_STRING
%26 = load i32, i32* @RSA_R_WRONG_SIGNATURE_LENGTH
%27 = call i32 @RSAerr(i32 %25, i32 %26)
store i32 0, i32* %7
br label %89
28: ; preds = %6
%29 = load i32, i32* %12
%30 = call i8* @malloc(i32 %29)
store i8* %30, i8** %16
%31 = load i8*, i8** %16
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @RSA_F_RSA_VERIFY_ASN1_OCTET_STRING
%35 = load i32, i32* @ERR_R_MALLOC_FAILURE
%36 = call i32 @RSAerr(i32 %34, i32 %35)
br label %76
37: ; preds = %28
%38 = load i32, i32* %12
%39 = load i8*, i8** %11
%40 = load i8*, i8** %16
%41 = load i32*, i32** %13
%42 = load i32, i32* @RSA_PKCS1_PADDING
%43 = call i32 @RSA_public_decrypt(i32 %38, i8* %39, i8* %40, i32* %41, i32 %42)
store i32 %43, i32* %14
%44 = load i32, i32* %14
%45 = icmp sle i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %37
br label %76
47: ; preds = %37
%48 = load i8*, i8** %16
store i8* %48, i8** %17
%49 = load i32, i32* %14
%50 = sext i32 %49 to i64
%51 = call %struct.TYPE_4__* @d2i_ASN1_OCTET_STRING(i32* null, i8** %17, i64 %50)
store %struct.TYPE_4__* %51, %struct.TYPE_4__** %18
%52 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%53 = icmp eq %struct.TYPE_4__* %52, null
br i1 %53, label %54, label %55
54: ; preds = %47
br label %76
55: ; preds = %47
%56 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%57 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %56, i32 0, i32 1
%58 = load i64, i64* %57
%59 = trunc i64 %58 to i32
%60 = load i32, i32* %10
%61 = icmp ne i32 %59, %60
br i1 %61, label %70, label %62
62: ; preds = %55
%63 = load i8*, i8** %9
%64 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%65 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = load i32, i32* %10
%68 = call i64 @memcmp(i8* %63, i32 %66, i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %62, %55
%71 = load i32, i32* @RSA_F_RSA_VERIFY_ASN1_OCTET_STRING
%72 = load i32, i32* @RSA_R_BAD_SIGNATURE
%73 = call i32 @RSAerr(i32 %71, i32 %72)
br label %75
74: ; preds = %62
store i32 1, i32* %15
br label %75
75: ; preds = %74, %70
br label %76
76: ; preds = %75, %54, %46, %33
%77 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%78 = call i32 @ASN1_OCTET_STRING_free(%struct.TYPE_4__* %77)
%79 = load i8*, i8** %16
%80 = icmp ne i8* %79, null
br i1 %80, label %81, label %87
81: ; preds = %76
%82 = load i8*, i8** %16
%83 = load i32, i32* %12
%84 = call i32 @explicit_bzero(i8* %82, i32 %83)
%85 = load i8*, i8** %16
%86 = call i32 @free(i8* %85)
br label %87
87: ; preds = %81, %76
%88 = load i32, i32* %15
store i32 %88, i32* %7
br label %89
89: ; preds = %87, %24
%90 = load i32, i32* %7
ret i32 %90
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i64 }
@RSA_F_RSA_VERIFY_ASN1_OCTET_STRING = global i32 0
@RSA_R_WRONG_SIGNATURE_LENGTH = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@RSA_PKCS1_PADDING = global i32 0
@RSA_R_BAD_SIGNATURE = global i32 0
define i32 @RSA_verify_ASN1_OCTET_STRING(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4, i32* %5) {
%7 = alloca i8*
%8 = bitcast i8** %7 to i8*
%9 = tail call i64 @RSA_size(i32* %5)
%10 = trunc i64 %9 to i32
%11 = icmp eq i32 %10, %4
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = load i32, i32* @RSA_F_RSA_VERIFY_ASN1_OCTET_STRING
%14 = load i32, i32* @RSA_R_WRONG_SIGNATURE_LENGTH
%15 = tail call i32 @RSAerr(i32 %13, i32 %14)
br label %52
16: ; preds = %6
%17 = tail call i8* @malloc(i32 %4)
%18 = icmp eq i8* %17, null
br i1 %18, label %41, label %19
19: ; preds = %16
%20 = load i32, i32* @RSA_PKCS1_PADDING
%21 = tail call i32 @RSA_public_decrypt(i32 %4, i8* %3, i8* %17, i32* %5, i32 %20)
%22 = icmp slt i32 %21, 1
br i1 %22, label %46, label %23
23: ; preds = %19
store i8* %17, i8** %7
%24 = zext i32 %21 to i64
%25 = call %struct.TYPE_4__* @d2i_ASN1_OCTET_STRING(i32* null, i8** %7, i64 %24)
%26 = icmp eq %struct.TYPE_4__* %25, null
br i1 %26, label %46, label %27
27: ; preds = %23
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i64 0, i32 1
%29 = load i64, i64* %28
%30 = trunc i64 %29 to i32
%31 = icmp eq i32 %30, %2
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @memcmp(i8* %1, i32 %34, i32 %2)
%36 = icmp eq i64 %35, 0
br i1 %36, label %46, label %37
37: ; preds = %32, %27
%38 = load i32, i32* @RSA_F_RSA_VERIFY_ASN1_OCTET_STRING
%39 = load i32, i32* @RSA_R_BAD_SIGNATURE
%40 = call i32 @RSAerr(i32 %38, i32 %39)
br label %46
41: ; preds = %16
%42 = load i32, i32* @RSA_F_RSA_VERIFY_ASN1_OCTET_STRING
%43 = load i32, i32* @ERR_R_MALLOC_FAILURE
%44 = tail call i32 @RSAerr(i32 %42, i32 %43)
%45 = tail call i32 @ASN1_OCTET_STRING_free(%struct.TYPE_4__* null)
br label %52
46: ; preds = %32, %37, %23, %19
%47 = phi i32 [ 1, %32 ], [ 0, %37 ], [ 0, %23 ], [ 0, %19 ]
%48 = phi %struct.TYPE_4__* [ %25, %32 ], [ %25, %37 ], [ null, %23 ], [ null, %19 ]
%49 = call i32 @ASN1_OCTET_STRING_free(%struct.TYPE_4__* %48)
%50 = call i32 @explicit_bzero(i8* %17, i32 %4)
%51 = call i32 @free(i8* %17)
br label %52
52: ; preds = %41, %46, %12
%53 = phi i32 [ 0, %12 ], [ %47, %46 ], [ 0, %41 ]
ret i32 %53
}