// File: dguglielmi[P]dlan-linux-software/common/hptools.cpp
// Function: (anonymous namespace)::sha256_done((anonymous namespace)::sha256_state*, unsigned char*)
void sha256_done(sha256_state * md, unsigned char *out)
{
    int i;

    /* increase the length of the message */
    md->length += md->curlen * 8;

    /* append the '1' bit */
    md->buf[md->curlen++] = (unsigned char)0x80;

    /* if the length is currently above 56 bytes we append zeros
     * then compress.  Then we can fall back to padding zeros and length
     * encoding like normal.
     */
    if (md->curlen > 56) {
        while (md->curlen < 64) {
            md->buf[md->curlen++] = (unsigned char)0;
        }
        sha256_compress(md, md->buf);
        md->curlen = 0;
    }

    /* pad upto 56 bytes of zeroes */
    while (md->curlen < 56) {
        md->buf[md->curlen++] = (unsigned char)0;
    }

    /* store length */
    STORE64H(md->length, md->buf+56);
    sha256_compress(md, md->buf);

    /* copy output */
    for (i = 0; i < 8; i++) {
        STORE32H(md->state[i], out+(4*i));
    }
#ifdef LTC_CLEAN_STACK
    memset(md, 0, sizeof(sha256_state));
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x28(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x28(%rdx)
movl %ecx, %ecx
movb $-0x80, 0x2c(%rax,%rcx)
movq -0x8(%rbp), %rax
cmpl $0x38, 0x28(%rax)
jbe 0x2a800
jmp 0x2a7be
movq -0x8(%rbp), %rax
cmpl $0x40, 0x28(%rax)
jae 0x2a7e4
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x28(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x28(%rdx)
movl %ecx, %ecx
movb $0x0, 0x2c(%rax,%rcx)
jmp 0x2a7be
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x2c, %rsi
callq 0x2c3d0
movq -0x8(%rbp), %rax
movl $0x0, 0x28(%rax)
jmp 0x2a802
movq -0x8(%rbp), %rax
cmpl $0x38, 0x28(%rax)
jae 0x2a828
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x28(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x28(%rdx)
movl %ecx, %ecx
movb $0x0, 0x2c(%rax,%rcx)
jmp 0x2a802
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x38, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x64(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x30, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x65(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x28, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x66(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x67(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x68(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x10, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x69(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x8, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x6a(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x6b(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x2c, %rsi
callq 0x2c3d0
movl $0x0, -0x14(%rbp)
cmpl $0x8, -0x14(%rbp)
jge 0x2a9bc
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x2(%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x3(%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2a90c
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)