#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*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ M_ASN1_OCTET_STRING_free(TYPE_1__ *);
int /*<<< orphan*/ OPENSSL_cleanse(unsigned char *, unsigned int);
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*/ 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((unsigned int)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:
  if (sig != NULL)
    M_ASN1_OCTET_STRING_free(sig);
  if (s != NULL) {
    OPENSSL_cleanse(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   1050 <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   10b0 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    131c <RSA_verify_ASN1_OCTET_STRING+0x18c>
mov    -0x24(%rbp),%edi
call   10a0 <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   10b0 <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   1090 <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   1060 <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   1080 <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   10b0 <RSAerr@plt>
jmp    12dd <RSA_verify_ASN1_OCTET_STRING+0x14d>
movl   $0x1,-0x38(%rbp)
jmp    12e2 <RSA_verify_ASN1_OCTET_STRING+0x152>
cmpq   $0x0,-0x50(%rbp)
je     12f6 <RSA_verify_ASN1_OCTET_STRING+0x166>
mov    -0x50(%rbp),%rdi
call   1040 <M_ASN1_OCTET_STRING_free@plt>
cmpq   $0x0,-0x40(%rbp)
je     1316 <RSA_verify_ASN1_OCTET_STRING+0x186>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <OPENSSL_cleanse@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,%r13d
mov    %rcx,%rbx
mov    %edx,%r12d
mov    %rsi,%r15
mov    %r9,%rdi
call   1050 <RSA_size@plt>
cmp    %r13d,%eax
jne    123b <RSA_verify_ASN1_OCTET_STRING+0xab>
mov    %r13d,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     124d <RSA_verify_ASN1_OCTET_STRING+0xbd>
mov    %rax,%r14
mov    0x2de2(%rip),%rax
mov    (%rax),%r8d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1090 <RSA_public_decrypt@plt>
test   %eax,%eax
jle    1268 <RSA_verify_ASN1_OCTET_STRING+0xd8>
mov    %r14,(%rsp)
mov    %eax,%edx
xor    %ebp,%ebp
mov    %rsp,%rsi
xor    %edi,%edi
call   1060 <d2i_ASN1_OCTET_STRING@plt>
test   %rax,%rax
je     1279 <RSA_verify_ASN1_OCTET_STRING+0xe9>
mov    %rax,%rbx
cmp    %r12d,0x8(%rax)
jne    1220 <RSA_verify_ASN1_OCTET_STRING+0x90>
mov    (%rbx),%esi
mov    %r15,%rdi
mov    %r12d,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     126c <RSA_verify_ASN1_OCTET_STRING+0xdc>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
call   10b0 <RSAerr@plt>
xor    %ebp,%ebp
jmp    1271 <RSA_verify_ASN1_OCTET_STRING+0xe1>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    0x2d9d(%rip),%rax
jmp    125d <RSA_verify_ASN1_OCTET_STRING+0xcd>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
call   10b0 <RSAerr@plt>
xor    %ebp,%ebp
jmp    128c <RSA_verify_ASN1_OCTET_STRING+0xfc>
xor    %ebp,%ebp
jmp    1279 <RSA_verify_ASN1_OCTET_STRING+0xe9>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <M_ASN1_OCTET_STRING_free@plt>
mov    %r14,%rdi
mov    %r13d,%esi
call   1070 <OPENSSL_cleanse@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 %93
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 = icmp ne %struct.TYPE_4__* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%81 = call i32 @M_ASN1_OCTET_STRING_free(%struct.TYPE_4__* %80)
br label %82
82: ; preds = %79, %76
%83 = load i8*, i8** %16
%84 = icmp ne i8* %83, null
br i1 %84, label %85, label %91
85: ; preds = %82
%86 = load i8*, i8** %16
%87 = load i32, i32* %12
%88 = call i32 @OPENSSL_cleanse(i8* %86, i32 %87)
%89 = load i8*, i8** %16
%90 = call i32 @free(i8* %89)
br label %91
91: ; preds = %85, %82
%92 = load i32, i32* %15
store i32 %92, i32* %7
br label %93
93: ; preds = %91, %24
%94 = load i32, i32* %7
ret i32 %94
}

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 %44, 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 %48, 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 %48, 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 %41, 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 %41
41: ; preds = %32, %37
%42 = phi i32 [ 0, %37 ], [ 1, %32 ]
%43 = call i32 @M_ASN1_OCTET_STRING_free(%struct.TYPE_4__* %25)
br label %48
44: ; preds = %16
%45 = load i32, i32* @RSA_F_RSA_VERIFY_ASN1_OCTET_STRING
%46 = load i32, i32* @ERR_R_MALLOC_FAILURE
%47 = tail call i32 @RSAerr(i32 %45, i32 %46)
br label %52
48: ; preds = %23, %19, %41
%49 = phi i32 [ %42, %41 ], [ 0, %19 ], [ 0, %23 ]
%50 = call i32 @OPENSSL_cleanse(i8* %17, i32 %4)
%51 = call i32 @free(i8* %17)
br label %52
52: ; preds = %44, %48, %12
%53 = phi i32 [ 0, %12 ], [ %49, %48 ], [ 0, %44 ]
ret i32 %53
}