// File: lianxings[P]ftp_benchmark/WjCryptLib_Md5.cc
// Function: Md5Finalise(Md5Context*, MD5_HASH*)
void Md5Finalise (
        Md5Context*         Context,        // [in out]
        MD5_HASH*           Digest          // [in]
) {
    uint32_t    used;
    uint32_t    free;

    used = Context->lo & 0x3f;

    Context->buffer[used++] = 0x80;

    free = 64 - used;

    if(free < 8)
    {
        memset( &Context->buffer[used], 0, free );
        TransformFunction( Context, Context->buffer, 64 );
        used = 0;
        free = 64;
    }

    memset( &Context->buffer[used], 0, free - 8 );

    Context->lo <<= 3;
    Context->buffer[56] = (uint8_t)( Context->lo );
    Context->buffer[57] = (uint8_t)( Context->lo >> 8 );
    Context->buffer[58] = (uint8_t)( Context->lo >> 16 );
    Context->buffer[59] = (uint8_t)( Context->lo >> 24 );
    Context->buffer[60] = (uint8_t)( Context->hi );
    Context->buffer[61] = (uint8_t)( Context->hi >> 8 );
    Context->buffer[62] = (uint8_t)( Context->hi >> 16 );
    Context->buffer[63] = (uint8_t)( Context->hi >> 24 );

    TransformFunction( Context, Context->buffer, 64 );

    Digest->bytes[0]  = (uint8_t)( Context->a );
    Digest->bytes[1]  = (uint8_t)( Context->a >> 8 );
    Digest->bytes[2]  = (uint8_t)( Context->a >> 16 );
    Digest->bytes[3]  = (uint8_t)( Context->a >> 24 );
    Digest->bytes[4]  = (uint8_t)( Context->b );
    Digest->bytes[5]  = (uint8_t)( Context->b >> 8 );
    Digest->bytes[6]  = (uint8_t)( Context->b >> 16 );
    Digest->bytes[7]  = (uint8_t)( Context->b >> 24 );
    Digest->bytes[8]  = (uint8_t)( Context->c );
    Digest->bytes[9]  = (uint8_t)( Context->c >> 8 );
    Digest->bytes[10] = (uint8_t)( Context->c >> 16 );
    Digest->bytes[11] = (uint8_t)( Context->c >> 24 );
    Digest->bytes[12] = (uint8_t)( Context->d );
    Digest->bytes[13] = (uint8_t)( Context->d >> 8 );
    Digest->bytes[14] = (uint8_t)( Context->d >> 16 );
    Digest->bytes[15] = (uint8_t)( Context->d >> 24 );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x3f, %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movl %ecx, %ecx
movb $-0x80, 0x18(%rax,%rcx)
movl $0x40, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $0x8, -0x18(%rbp)
jae 0x1b781
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movl -0x18(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x4250
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x18, %rsi
movl $0x40, %edx
callq 0x1a350
movl $0x0, -0x14(%rbp)
movl $0x40, -0x18(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movl -0x18(%rbp), %eax
subl $0x8, %eax
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x4250
movq -0x8(%rbp), %rax
movl (%rax), %ecx
shll $0x3, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x50(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x51(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x52(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl $0x18, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x53(%rax)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x54(%rax)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x55(%rax)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x56(%rax)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
shrl $0x18, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x57(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x18, %rsi
movl $0x40, %edx
callq 0x1a350
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x18, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x5(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x6(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x18, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x7(%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
shrl $0x18, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xb(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xc(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xd(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xe(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x18, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xf(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)