#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*/ EVP_PKEY;
typedef int /*<<< orphan*/ EVP_MD_CTX;

/* Variables and functions */
int EVP_DigestVerifyFinal(int /*<<< orphan*/ *, unsigned char *, size_t);
int EVP_DigestVerifyInit(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                         int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/ *);
int EVP_DigestVerifyUpdate(int /*<<< orphan*/ *, void *, size_t);
int /*<<< orphan*/ *EVP_MD_CTX_create();
int /*<<< orphan*/ EVP_MD_CTX_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_sha224();
int PICA_signverify(EVP_PKEY *pubkey, void **datapointers, size_t *datalengths,
                    unsigned char *sig, size_t siglen) {
  EVP_MD_CTX *mdctx = NULL;
  int ret = 0;
  mdctx = EVP_MD_CTX_create();
  if (!mdctx)
    return 0;
  ret = EVP_DigestVerifyInit(mdctx, NULL, EVP_sha224(), NULL, pubkey);
  if (ret != 1)
    goto signverify_exit;
  while (*datapointers) {
    ret = EVP_DigestVerifyUpdate(mdctx, *datapointers, *datalengths);
    if (ret != 1)
      goto signverify_exit;
    datapointers++;
    datalengths++;
  }
  ret = EVP_DigestVerifyFinal(mdctx, sig, siglen);
  if (ret != 1)
    ret = 0;
signverify_exit:
  EVP_MD_CTX_destroy(mdctx);
  return ret;
}


x86 assembly (clang, -O0):
<PICA_signverify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    $0x0,%al
call   1080 <EVP_MD_CTX_create@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ad <PICA_signverify+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    1276 <PICA_signverify+0x116>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1030 <EVP_sha224@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
call   1040 <EVP_DigestVerifyInit@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
je     11e4 <PICA_signverify+0x84>
jmp    1267 <PICA_signverify+0x107>
jmp    11e9 <PICA_signverify+0x89>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     123d <PICA_signverify+0xdd>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
call   1060 <EVP_DigestVerifyUpdate@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
je     1220 <PICA_signverify+0xc0>
jmp    1267 <PICA_signverify+0x107>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11e9 <PICA_signverify+0x89>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <EVP_DigestVerifyFinal@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
je     1262 <PICA_signverify+0x102>
movl   $0x0,-0x3c(%rbp)
jmp    1267 <PICA_signverify+0x107>
mov    -0x38(%rbp),%rdi
call   1050 <EVP_MD_CTX_destroy@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PICA_signverify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,(%rsp)
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <EVP_MD_CTX_create@plt>
test   %rax,%rax
je     1203 <PICA_signverify+0xa3>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <EVP_sha224@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <EVP_DigestVerifyInit@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
jne    11fb <PICA_signverify+0x9b>
mov    %rbx,%r14
mov    0x0(%r13),%rsi
test   %rsi,%rsi
je     11df <PICA_signverify+0x7f>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,1),%rdx
mov    %r15,%rdi
call   1060 <EVP_DigestVerifyUpdate@plt>
cmp    $0x1,%eax
jne    11f9 <PICA_signverify+0x99>
mov    0x8(%r13,%rbx,1),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11c0 <PICA_signverify+0x60>
mov    %r15,%rdi
mov    (%rsp),%rsi
mov    %r14,%rdx
call   1070 <EVP_DigestVerifyFinal@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
sete   %bpl
jmp    11fb <PICA_signverify+0x9b>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <EVP_MD_CTX_destroy@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @PICA_signverify(i32* %0, i8** %1, i64* %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32
store i32* %0, i32** %7
store i8** %1, i8*** %8
store i64* %2, i64** %9
store i8* %3, i8** %10
store i64 %4, i64* %11
store i32* null, i32** %12
store i32 0, i32* %13
%14 = call i32* (...) @EVP_MD_CTX_create()
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %5
store i32 0, i32* %6
br label %59
18: ; preds = %5
%19 = load i32*, i32** %12
%20 = call i32 (...) @EVP_sha224()
%21 = load i32*, i32** %7
%22 = call i32 @EVP_DigestVerifyInit(i32* %19, i32* null, i32 %20, i32* null, i32* %21)
store i32 %22, i32* %13
%23 = load i32, i32* %13
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %18
br label %55
26: ; preds = %18
br label %27
27: ; preds = %41, %26
%28 = load i8**, i8*** %8
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i32*, i32** %12
%33 = load i8**, i8*** %8
%34 = load i8*, i8** %33
%35 = load i64*, i64** %9
%36 = load i64, i64* %35
%37 = call i32 @EVP_DigestVerifyUpdate(i32* %32, i8* %34, i64 %36)
store i32 %37, i32* %13
%38 = load i32, i32* %13
%39 = icmp ne i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %31
br label %55
41: ; preds = %31
%42 = load i8**, i8*** %8
%43 = getelementptr inbounds i8*, i8** %42, i32 1
store i8** %43, i8*** %8
%44 = load i64*, i64** %9
%45 = getelementptr inbounds i64, i64* %44, i32 1
store i64* %45, i64** %9
br label %27
46: ; preds = %27
%47 = load i32*, i32** %12
%48 = load i8*, i8** %10
%49 = load i64, i64* %11
%50 = call i32 @EVP_DigestVerifyFinal(i32* %47, i8* %48, i64 %49)
store i32 %50, i32* %13
%51 = load i32, i32* %13
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %54
53: ; preds = %46
store i32 0, i32* %13
br label %54
54: ; preds = %53, %46
br label %55
55: ; preds = %54, %40, %25
%56 = load i32*, i32** %12
%57 = call i32 @EVP_MD_CTX_destroy(i32* %56)
%58 = load i32, i32* %13
store i32 %58, i32* %6
br label %59
59: ; preds = %55, %17
%60 = load i32, i32* %6
ret i32 %60
}

LLVM IR (-O2):
define i32 @PICA_signverify(i32* %0, i8** nocapture %1, i64* nocapture %2, i8* %3, i64 %4) {
%6 = tail call i32* (...) @EVP_MD_CTX_create()
%7 = icmp eq i32* %6, null
br i1 %7, label %34, label %8
8: ; preds = %5
%9 = tail call i32 (...) @EVP_sha224()
%10 = tail call i32 @EVP_DigestVerifyInit(i32* %6, i32* null, i32 %9, i32* null, i32* %0)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = load i8*, i8** %1
%14 = icmp eq i8* %13, null
br i1 %14, label %27, label %15
15: ; preds = %12, %22
%16 = phi i8* [ %25, %22 ], [ %13, %12 ]
%17 = phi i8** [ %23, %22 ], [ %1, %12 ]
%18 = phi i64* [ %24, %22 ], [ %2, %12 ]
%19 = load i64, i64* %18
%20 = tail call i32 @EVP_DigestVerifyUpdate(i32* %6, i8* %16, i64 %19)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %31
22: ; preds = %15
%23 = getelementptr inbounds i8*, i8** %17, i64 1
%24 = getelementptr inbounds i64, i64* %18, i64 1
%25 = load i8*, i8** %23
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %15
27: ; preds = %22, %12
%28 = tail call i32 @EVP_DigestVerifyFinal(i32* %6, i8* %3, i64 %4)
%29 = icmp eq i32 %28, 1
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %15, %8, %27
%32 = phi i32 [ %10, %8 ], [ %30, %27 ], [ %20, %15 ]
%33 = tail call i32 @EVP_MD_CTX_destroy(i32* %6)
br label %34
34: ; preds = %5, %31
%35 = phi i32 [ %32, %31 ], [ 0, %5 ]
ret i32 %35
}