// File: jeffchan[P]blockchain-parser/BitcoinAddress.cpp
// Function: RIPEMD160::computeRIPEMD160(void const*, unsigned int, unsigned char*)
void computeRIPEMD160(const void *_message,uint32_t length,uint8_t hashcode[20])
/*
 * returns RMD(message)
 * message should be a string terminated by '\0'
 */
{
	const uint8_t *message = (const uint8_t *)_message;
	uint32_t         MDbuf[RMDsize/32];   /* contains (A, B, C, D(, E))   */
	uint32_t         X[16];               /* current 16-word chunk        */

	/* initialize */
	MDinit(MDbuf);

	/* process message in 16-word chunks */
	for (uint32_t nbytes=length; nbytes > 63; nbytes-=64) 
	{
		for (uint32_t i=0; i<16; i++) 
		{
			X[i] = BYTES_TO_DWORD(message);
			message += 4;
		}
		compress(MDbuf, X);
	}	/* length mod 64 bytes left */

	/* finish: */
	MDfinish(MDbuf, message, length, 0);

	for (uint32_t i=0; i<RMDsize/8; i+=4) 
	{
		hashcode[i]   = (uint8_t)(MDbuf[i>>2]);         /* implicit cast to uint8_t  */
		hashcode[i+1] = (uint8_t)(MDbuf[i>>2] >>  8);  /*  extracts the 8 least  */
		hashcode[i+2] = (uint8_t)(MDbuf[i>>2] >> 16);  /*  significant bits.     */
		hashcode[i+3] = (uint8_t)(MDbuf[i>>2] >> 24);
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3270
movl -0xc(%rbp), %eax
movl %eax, -0x84(%rbp)
cmpl $0x3f, -0x84(%rbp)
jbe 0x65a6
movl $0x0, -0x88(%rbp)
cmpl $0x10, -0x88(%rbp)
jae 0x6585
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %ecx
shll $0x18, %ecx
movq -0x20(%rbp), %rax
movzbl 0x2(%rax), %eax
shll $0x10, %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x8, %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
orl %eax, %ecx
movl -0x88(%rbp), %eax
movl %ecx, -0x80(%rbp,%rax,4)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x6527
leaq -0x40(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x32b0
movl -0x84(%rbp), %eax
subl $0x40, %eax
movl %eax, -0x84(%rbp)
jmp 0x6510
leaq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xc(%rbp), %edx
xorl %ecx, %ecx
callq 0x63e0
movl $0x0, -0x8c(%rbp)
cmpl $0x14, -0x8c(%rbp)
jae 0x6673
movl -0x8c(%rbp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl -0x40(%rbp,%rax,4), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x8c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x8c(%rbp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl -0x40(%rbp,%rax,4), %eax
shrl $0x8, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x8c(%rbp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl -0x40(%rbp,%rax,4), %eax
shrl $0x10, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x8c(%rbp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl -0x40(%rbp,%rax,4), %eax
shrl $0x18, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x8c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x8c(%rbp)
jmp 0x65c2
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)