#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*/ X509_SIG;

/* Variables and functions */
int /*<<< orphan*/ OPENSSL_cleanse(unsigned char *, int);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
int i2d_X509_SIG(int /*<<< orphan*/ *, unsigned char **);
int /*<<< orphan*/ memcmp(unsigned char const *, unsigned char *, int);
int rsa_check_digestinfo(X509_SIG *sig, const unsigned char *dinfo,
                         int dinfolen) {
  unsigned char *der = NULL;
  int derlen;
  int ret = 0;
  derlen = i2d_X509_SIG(sig, &der);
  if (derlen <= 0)
    return 0;
  if (derlen == dinfolen && !memcmp(dinfo, der, derlen))
    ret = 1;
  OPENSSL_cleanse(der, derlen);
  OPENSSL_free(der);
  return ret;
}


x86 assembly (clang, -O0):
<rsa_check_digestinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <i2d_X509_SIG@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jg     1188 <rsa_check_digestinfo+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11cf <rsa_check_digestinfo+0x8f>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b4 <rsa_check_digestinfo+0x74>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    11b4 <rsa_check_digestinfo+0x74>
movl   $0x1,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <OPENSSL_cleanse@plt>
mov    -0x28(%rbp),%rdi
call   1060 <OPENSSL_free@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_check_digestinfo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
movq   $0x0,(%rsp)
mov    %rsp,%rsi
call   1030 <i2d_X509_SIG@plt>
test   %eax,%eax
jle    1197 <rsa_check_digestinfo+0x57>
mov    %eax,%ebx
xor    %ebp,%ebp
cmp    %r14d,%eax
jne    1181 <rsa_check_digestinfo+0x41>
mov    (%rsp),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
call   1050 <memcmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    (%rsp),%rdi
mov    %ebx,%esi
call   1040 <OPENSSL_cleanse@plt>
mov    (%rsp),%rdi
call   1060 <OPENSSL_free@plt>
jmp    1199 <rsa_check_digestinfo+0x59>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rsa_check_digestinfo(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* null, i8** %8
store i32 0, i32* %10
%11 = load i32*, i32** %5
%12 = call i32 @i2d_X509_SIG(i32* %11, i8** %8)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %34
16: ; preds = %3
%17 = load i32, i32* %9
%18 = load i32, i32* %7
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = load i8*, i8** %8
%23 = load i32, i32* %9
%24 = call i32 @memcmp(i8* %21, i8* %22, i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %20
store i32 1, i32* %10
br label %27
27: ; preds = %26, %20, %16
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = call i32 @OPENSSL_cleanse(i8* %28, i32 %29)
%31 = load i8*, i8** %8
%32 = call i32 @OPENSSL_free(i8* %31)
%33 = load i32, i32* %10
store i32 %33, i32* %4
br label %34
34: ; preds = %27, %15
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @rsa_check_digestinfo(i32* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = call i32 @i2d_X509_SIG(i32* %0, i8** %4)
%7 = icmp slt i32 %6, 1
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = icmp eq i32 %6, %2
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = load i8*, i8** %4
%12 = call i32 @memcmp(i8* %1, i8* %11, i32 %2)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ 0, %8 ], [ %14, %10 ]
%17 = load i8*, i8** %4
%18 = call i32 @OPENSSL_cleanse(i8* %17, i32 %6)
%19 = load i8*, i8** %4
%20 = call i32 @OPENSSL_free(i8* %19)
br label %21
21: ; preds = %3, %15
%22 = phi i32 [ %16, %15 ], [ 0, %3 ]
ret i32 %22
}