// File: msotoodeh[P]asymmetric-passwords/common/curve25519/sha512.c
// Function: SHA512_Final
void SHA512_Final (unsigned char *md, SHA512_CTX *c)
{
    unsigned char *p=(unsigned char *)c->u.p;
    size_t n=c->num;

    p[n]=0x80;  /* There always is a room for one */
    n++;
    if (n > (SHA512_CBLOCK-16))
        mem_fill (p+n,0,SHA512_CBLOCK-n), n=0,
        SHA512_Transform (c,p);

    mem_fill (p+n,0,SHA512_CBLOCK-16-n);
#ifdef  ECP_CONFIG_BIG_ENDIAN
    c->u.d[SHA_LBLOCK-2] = c->Nh;
    c->u.d[SHA_LBLOCK-1] = c->Nl;
#else
    p[SHA512_CBLOCK-1]  = (unsigned char)(c->Nl);
    p[SHA512_CBLOCK-2]  = (unsigned char)(c->Nl>>8);
    p[SHA512_CBLOCK-3]  = (unsigned char)(c->Nl>>16);
    p[SHA512_CBLOCK-4]  = (unsigned char)(c->Nl>>24);
    p[SHA512_CBLOCK-5]  = (unsigned char)(c->Nl>>32);
    p[SHA512_CBLOCK-6]  = (unsigned char)(c->Nl>>40);
    p[SHA512_CBLOCK-7]  = (unsigned char)(c->Nl>>48);
    p[SHA512_CBLOCK-8]  = (unsigned char)(c->Nl>>56);
    p[SHA512_CBLOCK-9]  = (unsigned char)(c->Nh);
    p[SHA512_CBLOCK-10] = (unsigned char)(c->Nh>>8);
    p[SHA512_CBLOCK-11] = (unsigned char)(c->Nh>>16);
    p[SHA512_CBLOCK-12] = (unsigned char)(c->Nh>>24);
    p[SHA512_CBLOCK-13] = (unsigned char)(c->Nh>>32);
    p[SHA512_CBLOCK-14] = (unsigned char)(c->Nh>>40);
    p[SHA512_CBLOCK-15] = (unsigned char)(c->Nh>>48);
    p[SHA512_CBLOCK-16] = (unsigned char)(c->Nh>>56);
#endif

    SHA512_Transform (c,p);

    if (md) for (n=0; n < SHA512_DIGEST_LENGTH/8; n++)
    {
        M64 m;
        m.u64 = c->h[n];
        *(md++) = m.u8.b7;
        *(md++) = m.u8.b6;
        *(md++) = m.u8.b5;
        *(md++) = m.u8.b4;
        *(md++) = m.u8.b3;
        *(md++) = m.u8.b2;
        *(md++) = m.u8.b1;
        *(md++) = m.u8.b0;
    }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x18(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movl 0xd0(%rax), %eax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movb $-0x80, (%rax,%rcx)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
cmpq $0x70, 0x8(%rsp)
jbe 0x40bd73
movq 0x10(%rsp), %rdi
addq 0x8(%rsp), %rdi
movl $0x80, %edx
subq 0x8(%rsp), %rdx
xorl %esi, %esi
callq 0x401060
movq $0x0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x40c010
movq 0x10(%rsp), %rdi
addq 0x8(%rsp), %rdi
movl $0x70, %edx
subq 0x8(%rsp), %rdx
xorl %esi, %esi
callq 0x401060
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x7f(%rax)
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
shrq $0x8, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x7e(%rax)
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
shrq $0x10, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x7d(%rax)
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
shrq $0x18, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x7c(%rax)
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
shrq $0x20, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x7b(%rax)
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
shrq $0x28, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x7a(%rax)
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
shrq $0x30, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x79(%rax)
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rax
shrq $0x38, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x78(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x77(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
shrq $0x8, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x76(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
shrq $0x10, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x75(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
shrq $0x18, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x74(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
shrq $0x20, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x73(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
shrq $0x28, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x72(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
shrq $0x30, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x71(%rax)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
shrq $0x38, %rax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x70(%rax)
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x40c010
cmpq $0x0, 0x20(%rsp)
je 0x40c004
movq $0x0, 0x8(%rsp)
cmpq $0x8, 0x8(%rsp)
jae 0x40c002
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, (%rsp)
movb 0x7(%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movb 0x6(%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movb 0x5(%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movb 0x4(%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movb 0x3(%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movb 0x2(%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movb 0x1(%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movb (%rsp), %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x40bf1a
jmp 0x40c004
addq $0x28, %rsp
retq
nopl (%rax)