#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*/ libcperciva_SHA256_Buf(void const *, size_t,
                                          unsigned char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int hashArray(const void *buf, size_t length, char *const keyID,
              const size_t keyIDLen) {
  if (keyIDLen == 0)
    return 0;
  if (keyIDLen < 65)
    return -1;
  unsigned char hash[32];
  libcperciva_SHA256_Buf(buf, length, hash);
  for (int kH = 0; kH < 32; kH++)
    sprintf(&(keyID[kH * 2]), "%02X", hash[kH]);
  return 0;
}


x86 assembly (clang, -O0):
<hashArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    114f <hashArray+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <hashArray+0xa1>
cmpq   $0x41,-0x28(%rbp)
jae    1166 <hashArray+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <hashArray+0xa1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <libcperciva_SHA256_Buf@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x20,-0x54(%rbp)
jge    11ba <hashArray+0x9a>
mov    -0x20(%rbp),%rdi
mov    -0x54(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x54(%rbp),%rax
lea    0xe5e(%rip),%rsi
movzbl -0x50(%rbp,%rax,1),%edx
call   1040 <sprintf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    117e <hashArray+0x5e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashArray>:
test   %rcx,%rcx
je     1179 <hashArray+0x59>
mov    $0xffffffff,%eax
cmp    $0x41,%rcx
jb     1178 <hashArray+0x58>
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r15
mov    %rsp,%rdx
call   1030 <libcperciva_SHA256_Buf@plt>
xor    %ebx,%ebx
lea    0xeb3(%rip),%r14
nopl   (%rax)
movzbl (%rsp,%rbx,1),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
add    $0x1,%rbx
add    $0x2,%r15
cmp    $0x20,%rbx
jne    1150 <hashArray+0x30>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define i32 @hashArray(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [32 x i8]
%11 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i64, i64* %9
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 0, i32* %5
br label %42
15: ; preds = %4
%16 = load i64, i64* %9
%17 = icmp ult i64 %16, 65
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -1, i32* %5
br label %42
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = load i64, i64* %7
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%23 = call i32 @libcperciva_SHA256_Buf(i8* %20, i64 %21, i8* %22)
store i32 0, i32* %11
br label %24
24: ; preds = %38, %19
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 32
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i8*, i8** %8
%29 = load i32, i32* %11
%30 = mul nsw i32 %29, 2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %36)
br label %38
38: ; preds = %27
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %24
41: ; preds = %24
store i32 0, i32* %5
br label %42
42: ; preds = %41, %18, %14
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define i32 @hashArray(i8* %0, i64 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = alloca [32 x i8]
%6 = icmp eq i64 %3, 0
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = icmp ult i64 %3, 65
br i1 %8, label %22, label %9
9: ; preds = %7
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%11 = call i32 @libcperciva_SHA256_Buf(i8* %0, i64 %1, i8* %10)
br label %13
12: ; preds = %13
br label %22
13: ; preds = %9, %13
%14 = phi i64 [ 0, %9 ], [ %20, %13 ]
%15 = shl nuw nsw i64 %14, 1
%16 = getelementptr inbounds i8, i8* %2, i64 %15
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %14
%18 = load i8, i8* %17
%19 = call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %18)
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, 32
br i1 %21, label %12, label %13
22: ; preds = %7, %4, %12
%23 = phi i32 [ 0, %12 ], [ 0, %4 ], [ -1, %7 ]
ret i32 %23
}