#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_MD_CTX;
typedef int /*<<< orphan*/ EC_KEY;
typedef int /*<<< orphan*/ ECDSA_SIG;

/* Variables and functions */
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ FIPS_digestfinal(int /*<<< orphan*/ *, unsigned char *,
                                    unsigned int *);
int FIPS_ecdsa_verify_digest(int /*<<< orphan*/ *, unsigned char *,
                             unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ OPENSSL_cleanse(unsigned char *, unsigned int);
int FIPS_ecdsa_verify_ctx(EC_KEY *key, EVP_MD_CTX *ctx, ECDSA_SIG *s) {
  int ret = -1;
  unsigned char dig[EVP_MAX_MD_SIZE];
  unsigned int dlen;
  FIPS_digestfinal(ctx, dig, &dlen);
  ret = FIPS_ecdsa_verify_digest(key, dig, dlen, s);
  OPENSSL_cleanse(dig, dlen);
  return ret;
}


x86 assembly (clang, -O0):
<FIPS_ecdsa_verify_ctx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x34(%rbp),%rdx
call   1050 <FIPS_digestfinal@plt>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <FIPS_ecdsa_verify_digest@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x1c(%rbp)
mov    -0x34(%rbp),%esi
call   1030 <OPENSSL_cleanse@plt>
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FIPS_ecdsa_verify_ctx>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r15
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x1c(%rbp),%rdx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1050 <FIPS_digestfinal@plt>
mov    -0x1c(%rbp),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rcx
call   1040 <FIPS_ecdsa_verify_digest@plt>
mov    %eax,%r14d
mov    -0x1c(%rbp),%esi
mov    %rbx,%rdi
call   1030 <OPENSSL_cleanse@plt>
mov    %r14d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EVP_MAX_MD_SIZE = global i32 0
define i32 @FIPS_ecdsa_verify_ctx(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 -1, i32* %7
%11 = load i32, i32* @EVP_MAX_MD_SIZE
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i32*, i32** %5
%16 = call i32 @FIPS_digestfinal(i32* %15, i8* %14, i32* %10)
%17 = load i32*, i32** %4
%18 = load i32, i32* %10
%19 = load i32*, i32** %6
%20 = call i32 @FIPS_ecdsa_verify_digest(i32* %17, i8* %14, i32 %18, i32* %19)
store i32 %20, i32* %7
%21 = load i32, i32* %10
%22 = call i32 @OPENSSL_cleanse(i8* %14, i32 %21)
%23 = load i32, i32* %7
%24 = load i8*, i8** %8
ret i32 %23
}

LLVM IR (-O2):
@EVP_MAX_MD_SIZE = global i32 0
define i32 @FIPS_ecdsa_verify_ctx(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = load i32, i32* @EVP_MAX_MD_SIZE
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast i32* %4 to i8*
%9 = call i32 @FIPS_digestfinal(i32* %1, i8* %7, i32* %4)
%10 = load i32, i32* %4
%11 = call i32 @FIPS_ecdsa_verify_digest(i32* %0, i8* %7, i32 %10, i32* %2)
%12 = load i32, i32* %4
%13 = call i32 @OPENSSL_cleanse(i8* %7, i32 %12)
ret i32 %11
}