// File: dguglielmi[P]dlan-linux-software/common/hptools.cpp
// Function: (anonymous namespace)::md5_done((anonymous namespace)::md5_state*, unsigned char*)
void md5_done(md5_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;
        }
        md5_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 */
    STORE64L(md->length, md->buf+56);
    md5_compress(md, md->buf);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%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 0x18(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x18(%rdx)
movl %ecx, %ecx
movb $-0x80, 0x1c(%rax,%rcx)
movq -0x8(%rbp), %rax
cmpl $0x38, 0x18(%rax)
jbe 0x2a200
jmp 0x2a1be
movq -0x8(%rbp), %rax
cmpl $0x40, 0x18(%rax)
jae 0x2a1e4
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x18(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x18(%rdx)
movl %ecx, %ecx
movb $0x0, 0x1c(%rax,%rcx)
jmp 0x2a1be
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x1c, %rsi
callq 0x2ac00
movq -0x8(%rbp), %rax
movl $0x0, 0x18(%rax)
jmp 0x2a202
movq -0x8(%rbp), %rax
cmpl $0x38, 0x18(%rax)
jae 0x2a228
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rdx
movl 0x18(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x18(%rdx)
movl %ecx, %ecx
movb $0x0, 0x1c(%rax,%rcx)
jmp 0x2a202
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x38, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x5b(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x30, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x5a(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x28, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x59(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x58(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x57(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x10, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x56(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x8, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x55(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
andq $0xff, %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x54(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x1c, %rsi
callq 0x2ac00
movl $0x0, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jge 0x2a3bc
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, 0x3(%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, 0x2(%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, 0x1(%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, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2a30c
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)