#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ const uint8_t;

/* Variables and functions */
int /*<<< orphan*/ RIPEMD160(int /*<<< orphan*/ const *, int,
                             int /*<<< orphan*/ const *);
int RIPEMD160_DIGEST_LENGTH;
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int);
int fdh(const uint8_t *message, size_t len, uint8_t *hash, size_t dsize) {
  size_t count = dsize;
  uint8_t buf[RIPEMD160_DIGEST_LENGTH];
  size_t residue = dsize % RIPEMD160_DIGEST_LENGTH;
  RIPEMD160(message, len, buf);
  memcpy(hash, buf, residue);
  count -= residue;
  hash += residue;
  while (count >= RIPEMD160_DIGEST_LENGTH) {
    RIPEMD160(buf, RIPEMD160_DIGEST_LENGTH, hash);
    memcpy(buf, hash, RIPEMD160_DIGEST_LENGTH);
    hash += RIPEMD160_DIGEST_LENGTH;
    count -= RIPEMD160_DIGEST_LENGTH;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fdh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e80(%rip),%rcx
movslq (%rcx),%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
mov    -0x48(%rbp),%rdx
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%esi
call   1040 <RIPEMD160@plt>
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e21(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     1244 <fdh+0x124>
mov    -0x48(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1040 <RIPEMD160@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    0x2dc7(%rip),%rax
movslq (%rax),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    11cc <fdh+0xac>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdh>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,%rbx
mov    0x2ebd(%rip),%r15
movslq (%r15),%rcx
mov    %ecx,%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r13,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     116e <fdh+0x4e>
mov    %r13,%rax
xor    %edx,%edx
div    %rcx
mov    %rdx,%r12
jmp    1178 <fdh+0x58>
mov    %r13d,%eax
xor    %edx,%edx
div    %ecx
mov    %edx,%r12d
mov    %r14,%rdx
call   1040 <RIPEMD160@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <memcpy@plt>
sub    %r12,%r13
movslq (%r15),%rsi
cmp    %rsi,%r13
jb     11c8 <fdh+0xa8>
lea    (%rbx,%r12,4),%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <RIPEMD160@plt>
mov    (%r15),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
movslq (%r15),%rsi
lea    (%rbx,%rsi,4),%rbx
sub    %rsi,%r13
cmp    %rsi,%r13
jae    11a0 <fdh+0x80>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RIPEMD160_DIGEST_LENGTH = global i32 0
define i32 @fdh(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
store i64 %3, i64* %8
%13 = load i64, i64* %8
store i64 %13, i64* %9
%14 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i32, i64 %15
store i64 %15, i64* %11
%18 = load i64, i64* %8
%19 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%20 = sext i32 %19 to i64
%21 = urem i64 %18, %20
store i64 %21, i64* %12
%22 = load i32*, i32** %5
%23 = load i64, i64* %6
%24 = trunc i64 %23 to i32
%25 = call i32 @RIPEMD160(i32* %22, i32 %24, i32* %17)
%26 = load i32*, i32** %7
%27 = load i64, i64* %12
%28 = trunc i64 %27 to i32
%29 = call i32 @memcpy(i32* %26, i32* %17, i32 %28)
%30 = load i64, i64* %12
%31 = load i64, i64* %9
%32 = sub i64 %31, %30
store i64 %32, i64* %9
%33 = load i64, i64* %12
%34 = load i32*, i32** %7
%35 = getelementptr inbounds i32, i32* %34, i64 %33
store i32* %35, i32** %7
br label %36
36: ; preds = %41, %4
%37 = load i64, i64* %9
%38 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%39 = sext i32 %38 to i64
%40 = icmp uge i64 %37, %39
br i1 %40, label %41, label %56
41: ; preds = %36
%42 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%43 = load i32*, i32** %7
%44 = call i32 @RIPEMD160(i32* %17, i32 %42, i32* %43)
%45 = load i32*, i32** %7
%46 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%47 = call i32 @memcpy(i32* %17, i32* %45, i32 %46)
%48 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%49 = load i32*, i32** %7
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i32, i32* %49, i64 %50
store i32* %51, i32** %7
%52 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%53 = sext i32 %52 to i64
%54 = load i64, i64* %9
%55 = sub i64 %54, %53
store i64 %55, i64* %9
br label %36
56: ; preds = %36
%57 = load i8*, i8** %10
ret i32 0
}

LLVM IR (-O2):
@RIPEMD160_DIGEST_LENGTH = global i32 0
define i32 @fdh(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%6 = zext i32 %5 to i64
%7 = alloca i32, i64 %6
%8 = sext i32 %5 to i64
%9 = urem i64 %3, %8
%10 = trunc i64 %1 to i32
%11 = call i32 @RIPEMD160(i32* %0, i32 %10, i32* %7)
%12 = trunc i64 %9 to i32
%13 = call i32 @memcpy(i32* %2, i32* %7, i32 %12)
%14 = sub i64 %3, %9
%15 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%16 = sext i32 %15 to i64
%17 = icmp ult i64 %14, %16
br i1 %17, label %32, label %18
18: ; preds = %4
%19 = getelementptr inbounds i32, i32* %2, i64 %9
br label %20
20: ; preds = %18, %20
%21 = phi i32 [ %27, %20 ], [ %15, %18 ]
%22 = phi i32* [ %29, %20 ], [ %19, %18 ]
%23 = phi i64 [ %30, %20 ], [ %14, %18 ]
%24 = call i32 @RIPEMD160(i32* %7, i32 %21, i32* %22)
%25 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%26 = call i32 @memcpy(i32* %7, i32* %22, i32 %25)
%27 = load i32, i32* @RIPEMD160_DIGEST_LENGTH
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %22, i64 %28
%30 = sub i64 %23, %28
%31 = icmp ult i64 %30, %28
br i1 %31, label %32, label %20
32: ; preds = %20, %4
ret i32 0
}