#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 uint8_t;

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ libcperciva_SHA256_Buf(void const *, size_t, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
const char *IDForBuf(const void *buf, size_t length) {
  uint8_t hash[32];
  libcperciva_SHA256_Buf(buf, length, hash);
  char *id = (char *)calloc(65, sizeof(char));
  for (int kH = 0; kH < 32; kH++)
    sprintf(&(id[kH * 2]), "%02X", hash[kH]);
  return id;
}


x86 assembly (clang, -O0):
<IDForBuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1030 <libcperciva_SHA256_Buf@plt>
mov    $0x41,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
cmpl   $0x20,-0x9c(%rbp)
jge    11c7 <IDForBuf+0x97>
mov    -0x98(%rbp),%rdi
mov    -0x9c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x9c(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edx
lea    0xe52(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1177 <IDForBuf+0x47>
mov    -0x98(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IDForBuf>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsp,%rdx
call   1030 <libcperciva_SHA256_Buf@plt>
mov    $0x41,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xea1(%rip),%r14
nop
lea    (%r15,%rbx,1),%rdi
mov    (%rsp,%rbx,2),%edx
mov    %r14,%rsi
call   1050 <sprintf@plt>
add    $0x2,%rbx
cmp    $0x40,%rbx
jne    1160 <IDForBuf+0x30>
mov    %r15,%rax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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