// File: calebstewart[P]md5/md5.cpp
// Function: MD5::finalize(unsigned char*)
void MD5::finalize(unsigned char *result)
{
  unsigned long used, free;

  used = this->lo & 0x3f;

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

  free = 64 - used;

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

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

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

  this->process(this->buffer, 64);

  result[0] = this->a;
  result[1] = this->a >> 8;
  result[2] = this->a >> 16;
  result[3] = this->a >> 24;
  result[4] = this->b;
  result[5] = this->b >> 8;
  result[6] = this->b >> 16;
  result[7] = this->b >> 24;
  result[8] = this->c;
  result[9] = this->c >> 8;
  result[10] = this->c >> 16;
  result[11] = this->c >> 24;
  result[12] = this->d;
  result[13] = this->d >> 8;
  result[14] = this->d >> 16;
  result[15] = this->d >> 24;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq (%rax), %rcx
andq $0x3f, %rcx
movq %rcx, -0x18(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x18(%rbp)
movb $-0x80, 0x30(%rax,%rcx)
movl $0x40, %eax
subq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x8, -0x20(%rbp)
jae 0x2bc7
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
addq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
xorl %esi, %esi
callq 0x1030
movq -0x28(%rbp), %rdi
movq %rdi, %rsi
addq $0x30, %rsi
movl $0x40, %edx
callq 0x1390
movq $0x0, -0x18(%rbp)
movq $0x40, -0x20(%rbp)
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
addq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
subq $0x8, %rdx
xorl %esi, %esi
callq 0x1030
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
shlq $0x3, %rax
movq %rax, (%rdi)
movq (%rdi), %rax
movb %al, 0x68(%rdi)
movq (%rdi), %rax
shrq $0x8, %rax
movb %al, 0x69(%rdi)
movq (%rdi), %rax
shrq $0x10, %rax
movb %al, 0x6a(%rdi)
movq (%rdi), %rax
shrq $0x18, %rax
movb %al, 0x6b(%rdi)
movq 0x8(%rdi), %rax
movb %al, 0x6c(%rdi)
movq 0x8(%rdi), %rax
shrq $0x8, %rax
movb %al, 0x6d(%rdi)
movq 0x8(%rdi), %rax
shrq $0x10, %rax
movb %al, 0x6e(%rdi)
movq 0x8(%rdi), %rax
shrq $0x18, %rax
movb %al, 0x6f(%rdi)
movq %rdi, %rsi
addq $0x30, %rsi
movl $0x40, %edx
callq 0x1390
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, (%rcx)
movq 0x10(%rax), %rcx
shrq $0x8, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x1(%rcx)
movq 0x10(%rax), %rcx
shrq $0x10, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x2(%rcx)
movq 0x10(%rax), %rcx
shrq $0x18, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x3(%rcx)
movq 0x18(%rax), %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x4(%rcx)
movq 0x18(%rax), %rcx
shrq $0x8, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x5(%rcx)
movq 0x18(%rax), %rcx
shrq $0x10, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x6(%rcx)
movq 0x18(%rax), %rcx
shrq $0x18, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x7(%rcx)
movq 0x20(%rax), %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x8(%rcx)
movq 0x20(%rax), %rcx
shrq $0x8, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0x9(%rcx)
movq 0x20(%rax), %rcx
shrq $0x10, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0xa(%rcx)
movq 0x20(%rax), %rcx
shrq $0x18, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0xb(%rcx)
movq 0x28(%rax), %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0xc(%rcx)
movq 0x28(%rax), %rcx
shrq $0x8, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0xd(%rcx)
movq 0x28(%rax), %rcx
shrq $0x10, %rcx
movb %cl, %dl
movq -0x10(%rbp), %rcx
movb %dl, 0xe(%rcx)
movq 0x28(%rax), %rax
shrq $0x18, %rax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xf(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)