#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*/ sha2_chain(unsigned char *, unsigned char *);
int sha2_chain_byte(unsigned char *output_bytes, unsigned output_size,
                    unsigned *chain_status, unsigned char *chain) {
  unsigned counter = chain_status[0];
  for (unsigned i = 0; i < output_size; i++) {
    if ((32) <= counter) {
      sha2_chain(chain, chain);
      counter = 0;
    }
    output_bytes[i] = chain[counter++];
  }
  chain_status[0] = counter;
  return 0;
}


x86 assembly (clang, -O0):
<sha2_chain_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1191 <sha2_chain_byte+0x81>
mov    $0x20,%eax
cmp    -0x24(%rbp),%eax
ja     1165 <sha2_chain_byte+0x55>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <sha2_chain@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1137 <sha2_chain_byte+0x27>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha2_chain_byte>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    (%rdx),%eax
test   %esi,%esi
je     115c <sha2_chain_byte+0x4c>
mov    %rcx,%r13
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
jmp    1148 <sha2_chain_byte+0x38>
nop
mov    %eax,%ecx
add    $0x1,%eax
movzbl 0x0(%r13,%rcx,1),%ecx
mov    %cl,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     115c <sha2_chain_byte+0x4c>
cmp    $0x20,%eax
jb     1130 <sha2_chain_byte+0x20>
mov    %r13,%rdi
mov    %r13,%rsi
call   1030 <sha2_chain@plt>
xor    %eax,%eax
jmp    1130 <sha2_chain_byte+0x20>
mov    %eax,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @sha2_chain_byte(i8* %0, i32 %1, i32* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%11 = load i32*, i32** %7
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
store i32 %13, i32* %9
store i32 0, i32* %10
br label %14
14: ; preds = %36, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %6
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i32, i32* %9
%20 = icmp ule i32 32, %19
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = load i8*, i8** %8
%24 = call i32 @sha2_chain(i8* %22, i8* %23)
store i32 0, i32* %9
br label %25
25: ; preds = %21, %18
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = add i32 %27, 1
store i32 %28, i32* %9
%29 = zext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %5
%33 = load i32, i32* %10
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %25
%37 = load i32, i32* %10
%38 = add i32 %37, 1
store i32 %38, i32* %10
br label %14
39: ; preds = %14
%40 = load i32, i32* %9
%41 = load i32*, i32** %7
%42 = getelementptr inbounds i32, i32* %41, i64 0
store i32 %40, i32* %42
ret i32 0
}

LLVM IR (-O2):
define i32 @sha2_chain_byte(i8* nocapture writeonly %0, i32 %1, i32* nocapture %2, i8* %3) {
%5 = load i32, i32* %2
%6 = icmp eq i32 %1, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = zext i32 %1 to i64
br label %11
9: ; preds = %17, %4
%10 = phi i32 [ %5, %4 ], [ %19, %17 ]
store i32 %10, i32* %2
ret i32 0
11: ; preds = %7, %17
%12 = phi i64 [ 0, %7 ], [ %24, %17 ]
%13 = phi i32 [ %5, %7 ], [ %19, %17 ]
%14 = icmp ugt i32 %13, 31
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @sha2_chain(i8* %3, i8* %3)
br label %17
17: ; preds = %15, %11
%18 = phi i32 [ 0, %15 ], [ %13, %11 ]
%19 = add nuw nsw i32 %18, 1
%20 = zext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %3, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %22, i8* %23
%24 = add nuw nsw i64 %12, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %9, label %11
}