#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 /*<<< orphan*/ *FIPS_ecdsa_sign_digest(int /*<<< orphan*/ *,
                                           unsigned char *, unsigned int);
int /*<<< orphan*/ OPENSSL_cleanse(unsigned char *, unsigned int);
ECDSA_SIG *FIPS_ecdsa_sign_ctx(EC_KEY *key, EVP_MD_CTX *ctx) {
  ECDSA_SIG *s;
  unsigned char dig[EVP_MAX_MD_SIZE];
  unsigned int dlen;
  FIPS_digestfinal(ctx, dig, &dlen);
  s = FIPS_ecdsa_sign_digest(key, dig, dlen);
  OPENSSL_cleanse(dig, dlen);
  return s;
}


x86 assembly (clang, -O0):
<FIPS_ecdsa_sign_ctx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2c(%rbp),%rdx
call   1050 <FIPS_digestfinal@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%edx
call   1040 <FIPS_ecdsa_sign_digest@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%esi
call   1030 <OPENSSL_cleanse@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FIPS_ecdsa_sign_ctx>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x14(%rbp),%rdx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1050 <FIPS_digestfinal@plt>
mov    -0x14(%rbp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <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_ctx(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = load i32, i32* @EVP_MAX_MD_SIZE
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32*, i32** %4
%14 = call i32 @FIPS_digestfinal(i32* %13, i8* %12, i32* %8)
%15 = load i32*, i32** %3
%16 = load i32, i32* %8
%17 = call i32* @FIPS_ecdsa_sign_digest(i32* %15, i8* %12, i32 %16)
store i32* %17, i32** %5
%18 = load i32, i32* %8
%19 = call i32 @OPENSSL_cleanse(i8* %12, i32 %18)
%20 = load i32*, i32** %5
%21 = load i8*, i8** %6
ret i32* %20
}

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