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

/* Variables and functions */
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ FIPS_digest(unsigned char const *, size_t, unsigned char *,
                               unsigned int *, int /*<<< orphan*/ const *);
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(EC_KEY *key, const unsigned char *msg, size_t msglen,
                      const EVP_MD *mhash, ECDSA_SIG *s) {
  int ret = -1;
  unsigned char dig[EVP_MAX_MD_SIZE];
  unsigned int dlen;
  FIPS_digest(msg, msglen, dig, &dlen, mhash);
  ret = FIPS_ecdsa_verify_digest(key, dig, dlen, s);
  OPENSSL_cleanse(dig, dlen);
  return ret;
}


x86 assembly (clang, -O0):
<FIPS_ecdsa_verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%r8
lea    -0x44(%rbp),%rcx
call   1050 <FIPS_digest@plt>
mov    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1040 <FIPS_ecdsa_verify_digest@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,-0x2c(%rbp)
mov    -0x44(%rbp),%esi
call   1030 <OPENSSL_cleanse@plt>
mov    -0x2c(%rbp),%eax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FIPS_ecdsa_verify>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r8
mov    %rdi,%r15
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x1c(%rbp),%rcx
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rbx,%rdx
call   1050 <FIPS_digest@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(i32* %0, i8* %1, i64 %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 -1, i32* %11
%15 = load i32, i32* @EVP_MAX_MD_SIZE
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %12
%18 = alloca i8, i64 %16
store i64 %16, i64* %13
%19 = load i8*, i8** %7
%20 = load i64, i64* %8
%21 = load i32*, i32** %9
%22 = call i32 @FIPS_digest(i8* %19, i64 %20, i8* %18, i32* %14, i32* %21)
%23 = load i32*, i32** %6
%24 = load i32, i32* %14
%25 = load i32*, i32** %10
%26 = call i32 @FIPS_ecdsa_verify_digest(i32* %23, i8* %18, i32 %24, i32* %25)
store i32 %26, i32* %11
%27 = load i32, i32* %14
%28 = call i32 @OPENSSL_cleanse(i8* %18, i32 %27)
%29 = load i32, i32* %11
%30 = load i8*, i8** %12
ret i32 %29
}

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