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


x86 assembly (clang, -O0):
<FIPS_ecdsa_sign>:
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    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%r8
lea    -0x3c(%rbp),%rcx
call   1040 <FIPS_digest@plt>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x3c(%rbp),%edx
call   1050 <FIPS_ecdsa_sign_digest@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,-0x28(%rbp)
mov    -0x3c(%rbp),%esi
call   1030 <OPENSSL_cleanse@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FIPS_ecdsa_sign>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r8
mov    %rdi,%r14
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x14(%rbp),%rcx
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rbx,%rdx
call   1040 <FIPS_digest@plt>
mov    -0x14(%rbp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <FIPS_ecdsa_sign_digest@plt>
mov    %rax,%r14
mov    -0x14(%rbp),%esi
mov    %rbx,%rdi
call   1030 <OPENSSL_cleanse@plt>
mov    %r14,%rax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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