#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;

/* Variables and functions */
int /*<<< orphan*/ NID_sha256;
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_rsa_pub_sign(void *data_buf, int buf_len, RSA *secure_pub_key) {
  int ret = -1;
  SHA256_CTX sha256;
  unsigned char hash[SHA256_DIGEST_LENGTH];
  SHA256_Init(&sha256);
  SHA256_Update(&sha256, data_buf, 256);
  SHA256_Final(hash, &sha256);
  if (RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, data_buf + 256,
                 SHA256_DIGEST_LENGTH, secure_pub_key) == 0)
    ret = 0;
  return ret;
}


x86 assembly (clang, -O0):
<check_rsa_pub_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <SHA256_Init@plt>
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdi
mov    $0x100,%edx
call   1060 <SHA256_Update@plt>
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <SHA256_Final@plt>
mov    -0x38(%rbp),%rsi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rcx
add    $0x100,%rcx
mov    0x2e0a(%rip),%rax
mov    (%rax),%r8d
mov    -0x18(%rbp),%r9
call   1040 <RSA_verify@plt>
cmp    $0x0,%rax
jne    11f3 <check_rsa_pub_sign+0xb3>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_rsa_pub_sign>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r15
mov    %rsp,%r13
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x2c(%rbp),%r12
mov    %r12,%rdi
call   1030 <SHA256_Init@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x100,%edx
call   1060 <SHA256_Update@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <SHA256_Final@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
add    $0x100,%r15
mov    %rbx,%rsi
mov    %r15,%rcx
mov    %edx,%r8d
mov    %r14,%r9
call   1040 <RSA_verify@plt>
neg    %rax
sbb    %eax,%eax
mov    %r13,%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_rsa_pub_sign(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 -1, i32* %7
%11 = load i32, i32* @SHA256_DIGEST_LENGTH
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = call i32 @SHA256_Init(i32* %8)
%16 = load i8*, i8** %4
%17 = call i32 @SHA256_Update(i32* %8, i8* %16, i32 256)
%18 = call i32 @SHA256_Final(i8* %14, i32* %8)
%19 = load i32, i32* @NID_sha256
%20 = load i32, i32* @SHA256_DIGEST_LENGTH
%21 = load i8*, i8** %4
%22 = getelementptr i8, i8* %21, i64 256
%23 = load i32, i32* @SHA256_DIGEST_LENGTH
%24 = load i32*, i32** %6
%25 = call i64 @RSA_verify(i32 %19, i8* %14, i32 %20, i8* %22, i32 %23, i32* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %3
store i32 0, i32* %7
br label %28
28: ; preds = %27, %3
%29 = load i32, i32* %7
%30 = load i8*, i8** %9
ret i32 %29
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
@NID_sha256 = global i32 0
define i32 @check_rsa_pub_sign(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @SHA256_DIGEST_LENGTH
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = call i32 @SHA256_Init(i32* %4)
%11 = call i32 @SHA256_Update(i32* %4, i8* %0, i32 256)
%12 = call i32 @SHA256_Final(i8* %9, i32* %4)
%13 = load i32, i32* @NID_sha256
%14 = load i32, i32* @SHA256_DIGEST_LENGTH
%15 = getelementptr i8, i8* %0, i64 256
%16 = call i64 @RSA_verify(i32 %13, i8* %9, i32 %14, i8* %15, i32 %14, i32* %2)
%17 = icmp ne i64 %16, 0
%18 = sext i1 %17 to i32
ret i32 %18
}