#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 */

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ sha(char *, unsigned char *, size_t);
__attribute__((warn_unused_result)) int
d0_longhash_destructive(unsigned char *convbuf, size_t sz,
                        unsigned char *outbuf, size_t outbuflen) {
  size_t n, i;
  char shabuf[32];
  n = outbuflen;
  while (n > 32) {
    memcpy(outbuf, sha(shabuf, convbuf, sz), 32);
    outbuf += 32;
    n -= 32;
    for (i = 0; i < sz; ++i)
      if (++convbuf[i])
        break;
  }
  memcpy(outbuf, sha(shabuf, convbuf, sz), n);
  return 1;
}


x86 assembly (clang, -O0):
<d0_longhash_destructive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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)
cmpq   $0x20,-0x28(%rbp)
jbe    11da <d0_longhash_destructive+0xba>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <sha@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
mov    $0x20,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
sub    $0x20,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d5 <d0_longhash_destructive+0xb5>
mov    -0x8(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    (%rcx,%rdx,1),%al
add    $0x1,%al
mov    %al,(%rcx,%rdx,1)
cmp    $0x0,%al
je     11bf <d0_longhash_destructive+0x9f>
jmp    11d5 <d0_longhash_destructive+0xb5>
jmp    11c4 <d0_longhash_destructive+0xa4>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1194 <d0_longhash_destructive+0x74>
jmp    1140 <d0_longhash_destructive+0x20>
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <sha@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
call   1030 <memcpy@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d0_longhash_destructive>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
cmp    $0x21,%rcx
jb     11a6 <d0_longhash_destructive+0x86>
mov    %rsp,%r13
jmp    115a <d0_longhash_destructive+0x3a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x20,%r15
cmp    $0x20,%r14
jbe    11a6 <d0_longhash_destructive+0x86>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <sha@plt>
mov    $0x20,%edx
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <memcpy@plt>
add    $0xffffffffffffffe0,%r14
test   %rbx,%rbx
je     1150 <d0_longhash_destructive+0x30>
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nop
addb   $0x1,-0x1(%r12,%rax,1)
jne    1150 <d0_longhash_destructive+0x30>
lea    0x1(%rax),%rcx
cmp    %rbx,%rax
mov    %rcx,%rax
jb     1190 <d0_longhash_destructive+0x70>
jmp    1150 <d0_longhash_destructive+0x30>
mov    %rsp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <sha@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <memcpy@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @d0_longhash_destructive(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca [32 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%12 = load i64, i64* %8
store i64 %12, i64* %9
br label %13
13: ; preds = %43, %4
%14 = load i64, i64* %9
%15 = icmp ugt i64 %14, 32
br i1 %15, label %16, label %44
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = call i32 @sha(i8* %18, i8* %19, i64 %20)
%22 = call i32 @memcpy(i8* %17, i32 %21, i64 32)
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 32
store i8* %24, i8** %7
%25 = load i64, i64* %9
%26 = sub i64 %25, 32
store i64 %26, i64* %9
store i64 0, i64* %10
br label %27
27: ; preds = %40, %16
%28 = load i64, i64* %10
%29 = load i64, i64* %6
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = load i64, i64* %10
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = add i8 %35, 1
store i8 %36, i8* %34
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31
br label %43
39: ; preds = %31
br label %40
40: ; preds = %39
%41 = load i64, i64* %10
%42 = add i64 %41, 1
store i64 %42, i64* %10
br label %27
43: ; preds = %38, %27
br label %13
44: ; preds = %13
%45 = load i8*, i8** %7
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%47 = load i8*, i8** %5
%48 = load i64, i64* %6
%49 = call i32 @sha(i8* %46, i8* %47, i64 %48)
%50 = load i64, i64* %9
%51 = call i32 @memcpy(i8* %45, i32 %49, i64 %50)
ret i32 1
}

LLVM IR (-O2):
define i32 @d0_longhash_destructive(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = icmp ugt i64 %3, 32
br i1 %7, label %8, label %28
8: ; preds = %4
%9 = icmp eq i64 %1, 0
br label %10
10: ; preds = %8, %26
%11 = phi i64 [ %3, %8 ], [ %16, %26 ]
%12 = phi i8* [ %2, %8 ], [ %15, %26 ]
%13 = call i32 @sha(i8* %6, i8* %0, i64 %1)
%14 = call i32 @memcpy(i8* %12, i32 %13, i64 32)
%15 = getelementptr inbounds i8, i8* %12, i64 32
%16 = add i64 %11, -32
br i1 %9, label %26, label %17
17: ; preds = %10, %17
%18 = phi i64 [ %23, %17 ], [ 0, %10 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = add i8 %20, 1
store i8 %21, i8* %19
%22 = icmp eq i8 %21, 0
%23 = add nuw i64 %18, 1
%24 = icmp ult i64 %23, %1
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %17, label %26
26: ; preds = %17, %10
%27 = icmp ugt i64 %16, 32
br i1 %27, label %10, label %28
28: ; preds = %26, %4
%29 = phi i8* [ %2, %4 ], [ %15, %26 ]
%30 = phi i64 [ %3, %4 ], [ %16, %26 ]
%31 = call i32 @sha(i8* %6, i8* %0, i64 %1)
%32 = call i32 @memcpy(i8* %29, i32 %31, i64 %30)
ret i32 1
}