#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*/ SHA256_CTX;
typedef int /*<<< orphan*/ RSA;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ *BIO_new_mem_buf(void *, int);
int /*<<< orphan*/ NID_sha256;
int /*<<< orphan*/ *PEM_read_bio_RSA_PUBKEY(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *);
scalar_t__ RSA_verify(int /*<<< orphan*/, unsigned char *, int, void *, int,
                      int /*<<< orphan*/ *);
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ SHA256_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Update(int /*<<< orphan*/ *, void *, int);
int check_blob_sign(void *data_buf, int buf_len) {
  int ret = -1;
  SHA256_CTX sha256;
  unsigned char hash[SHA256_DIGEST_LENGTH];
  BIO *bio = NULL;
  RSA *rsa = NULL;
  SHA256_Init(&sha256);
  SHA256_Update(&sha256, data_buf + 256 + 2 * SHA256_DIGEST_LENGTH,
                buf_len - 256 - 2 * SHA256_DIGEST_LENGTH);
  SHA256_Final(hash, &sha256);
  bio = BIO_new_mem_buf(data_buf, 256);
  rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL);
  if (RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH,
                 data_buf + 256 + SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH,
                 rsa) == 0)
    ret = 0;
  return ret;
}


x86 assembly (clang, -O0):
<check_blob_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <SHA256_Init@plt>
mov    -0x8(%rbp),%rsi
add    $0x100,%rsi
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cltq
add    %rax,%rsi
mov    -0xc(%rbp),%edx
sub    $0x100,%edx
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
sub    %eax,%edx
lea    -0x14(%rbp),%rdi
call   1080 <SHA256_Update@plt>
mov    -0x40(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <SHA256_Final@plt>
mov    -0x8(%rbp),%rdi
mov    $0x100,%esi
call   1040 <BIO_new_mem_buf@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1050 <PEM_read_bio_RSA_PUBKEY@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,-0x38(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rcx
add    $0x100,%rcx
mov    0x2d8b(%rip),%rax
movslq (%rax),%rax
add    %rax,%rcx
mov    0x2d7e(%rip),%rax
mov    (%rax),%r8d
mov    -0x38(%rbp),%r9
call   1060 <RSA_verify@plt>
cmp    $0x0,%rax
jne    127f <check_blob_sign+0x11f>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_blob_sign>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,-0x30(%rbp)
mov    0x2e5f(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    -0x34(%rbp),%r12
mov    %r12,%rdi
call   1030 <SHA256_Init@plt>
movslq 0x0(%r13),%rax
lea    (%r14,%rax,2),%rsi
add    $0x100,%rsi
add    %rax,%rax
sub    %eax,%ebx
add    $0xffffff00,%ebx
mov    %r12,%rdi
mov    %ebx,%edx
call   1080 <SHA256_Update@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <SHA256_Final@plt>
mov    %r14,%rdi
mov    $0x100,%esi
call   1040 <BIO_new_mem_buf@plt>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <PEM_read_bio_RSA_PUBKEY@plt>
mov    0x2de5(%rip),%rcx
mov    (%rcx),%edi
movslq 0x0(%r13),%rdx
lea    (%r14,%rdx,1),%rcx
add    $0x100,%rcx
mov    %r15,%rsi
mov    %edx,%r8d
mov    %rax,%r9
call   1060 <RSA_verify@plt>
neg    %rax
sbb    %eax,%eax
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
@NID_sha256 = global i32 0
define i32 @check_blob_sign(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
%11 = load i32, i32* @SHA256_DIGEST_LENGTH
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
store i32* null, i32** %9
store i32* null, i32** %10
%15 = call i32 @SHA256_Init(i32* %6)
%16 = load i8*, i8** %3
%17 = getelementptr i8, i8* %16, i64 256
%18 = load i32, i32* @SHA256_DIGEST_LENGTH
%19 = mul nsw i32 2, %18
%20 = sext i32 %19 to i64
%21 = getelementptr i8, i8* %17, i64 %20
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 256
%24 = load i32, i32* @SHA256_DIGEST_LENGTH
%25 = mul nsw i32 2, %24
%26 = sub nsw i32 %23, %25
%27 = call i32 @SHA256_Update(i32* %6, i8* %21, i32 %26)
%28 = call i32 @SHA256_Final(i8* %14, i32* %6)
%29 = load i8*, i8** %3
%30 = call i32* @BIO_new_mem_buf(i8* %29, i32 256)
store i32* %30, i32** %9
%31 = load i32*, i32** %9
%32 = call i32* @PEM_read_bio_RSA_PUBKEY(i32* %31, i32* null, i32* null, i32* null)
store i32* %32, i32** %10
%33 = load i32, i32* @NID_sha256
%34 = load i32, i32* @SHA256_DIGEST_LENGTH
%35 = load i8*, i8** %3
%36 = getelementptr i8, i8* %35, i64 256
%37 = load i32, i32* @SHA256_DIGEST_LENGTH
%38 = sext i32 %37 to i64
%39 = getelementptr i8, i8* %36, i64 %38
%40 = load i32, i32* @SHA256_DIGEST_LENGTH
%41 = load i32*, i32** %10
%42 = call i64 @RSA_verify(i32 %33, i8* %14, i32 %34, i8* %39, i32 %40, i32* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %2
store i32 0, i32* %5
br label %45
45: ; preds = %44, %2
%46 = load i32, i32* %5
%47 = load i8*, i8** %7
ret i32 %46
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
@NID_sha256 = global i32 0
define i32 @check_blob_sign(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @SHA256_DIGEST_LENGTH
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i32 @SHA256_Init(i32* %3)
%10 = getelementptr i8, i8* %0, i64 256
%11 = load i32, i32* @SHA256_DIGEST_LENGTH
%12 = shl nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr i8, i8* %10, i64 %13
%15 = add nsw i32 %1, -256
%16 = sub i32 %15, %12
%17 = call i32 @SHA256_Update(i32* %3, i8* %14, i32 %16)
%18 = call i32 @SHA256_Final(i8* %8, i32* %3)
%19 = call i32* @BIO_new_mem_buf(i8* %0, i32 256)
%20 = call i32* @PEM_read_bio_RSA_PUBKEY(i32* %19, i32* null, i32* null, i32* null)
%21 = load i32, i32* @NID_sha256
%22 = load i32, i32* @SHA256_DIGEST_LENGTH
%23 = sext i32 %22 to i64
%24 = getelementptr i8, i8* %10, i64 %23
%25 = call i64 @RSA_verify(i32 %21, i8* %8, i32 %22, i8* %24, i32 %22, i32* %20)
%26 = icmp ne i64 %25, 0
%27 = sext i1 %26 to i32
ret i32 %27
}