#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*/ SHA384(unsigned char const *, size_t, unsigned char *);
size_t SHA384_DIGEST_LENGTH;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(void *);
void *malloc(size_t);
int /*<<< orphan*/ memcpy(void *, unsigned char *, size_t);
unsigned char *hash(const unsigned char *str, size_t len) {
  int j, i = (len / SHA384_DIGEST_LENGTH) + 1;
  unsigned char *digest =
      (unsigned char *)calloc(i * SHA384_DIGEST_LENGTH, sizeof(char));
  SHA384(str, len, digest);
  for (j = 1; j < i; ++j) {
    SHA384(digest + (SHA384_DIGEST_LENGTH * (j - 1)), SHA384_DIGEST_LENGTH,
           digest + (SHA384_DIGEST_LENGTH * j));
  }
  void *p = malloc(len * 4);
  void *x = malloc(len * 2);
  void *q = malloc(len / 2);
  void *r = malloc(len);
  memcpy(((char *)p) + len, digest, len);
  memcpy(((char *)x), digest, len);
  memcpy(q, digest, len / 2);
  memcpy(r, digest, len);
  free(p);
  free(x);
  free(q);
  free(r);
  return digest;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e7d(%rip),%rcx
xor    %edx,%edx
divq   (%rcx)
add    $0x1,%rax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
mov    0x2e66(%rip),%rcx
imul   (%rcx),%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <SHA384@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    120e <hash+0xbe>
mov    -0x20(%rbp),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   %rcx,%rax
add    %rax,%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
mov    0x2dfb(%rip),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
imul   %rcx,%rax
add    %rax,%rdx
call   1060 <SHA384@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ae <hash+0x5e>
mov    -0x10(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
shr    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
add    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
shr    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e7d(%rip),%r12
mov    (%r12),%rdi
mov    %rsi,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     1188 <hash+0x38>
mov    %r15,%rax
xor    %edx,%edx
div    %rdi
mov    %rax,%rbp
jmp    1191 <hash+0x41>
mov    %r15d,%eax
xor    %edx,%edx
div    %edi
mov    %eax,%ebp
add    $0x1,%ebp
imul   %ebp,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1060 <SHA384@plt>
cmp    $0x2,%ebp
jl     11ed <hash+0x9d>
mov    %ebp,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    0x1(%rbx),%rbp
mov    (%r12),%rsi
mov    %rsi,%rdi
imul   %rbx,%rdi
add    %r13,%rdi
mov    %rsi,%rdx
imul   %rbp,%rdx
add    %r13,%rdx
call   1060 <SHA384@plt>
add    $0x2,%rbx
cmp    %r14,%rbx
mov    %rbp,%rbx
jne    11c0 <hash+0x70>
lea    0x0(,%r15,4),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x10(%rsp)
lea    (%r15,%r15,1),%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %r15,%r14
shr    %r14
mov    %r14,%rdi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    (%rbx,%r15,1),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1050 <memcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA384_DIGEST_LENGTH = global i64 0
define i8* @hash(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%12 = load i64, i64* %4
%13 = load i64, i64* @SHA384_DIGEST_LENGTH
%14 = udiv i64 %12, %13
%15 = add i64 %14, 1
%16 = trunc i64 %15 to i32
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = load i64, i64* @SHA384_DIGEST_LENGTH
%20 = mul i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @calloc(i32 %21, i32 1)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %7
%24 = load i8*, i8** %3
%25 = load i64, i64* %4
%26 = load i8*, i8** %7
%27 = call i32 @SHA384(i8* %24, i64 %25, i8* %26)
store i32 1, i32* %5
br label %28
28: ; preds = %48, %2
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %51
32: ; preds = %28
%33 = load i8*, i8** %7
%34 = load i64, i64* @SHA384_DIGEST_LENGTH
%35 = load i32, i32* %5
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 %34, %37
%39 = getelementptr inbounds i8, i8* %33, i64 %38
%40 = load i64, i64* @SHA384_DIGEST_LENGTH
%41 = load i8*, i8** %7
%42 = load i64, i64* @SHA384_DIGEST_LENGTH
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = mul i64 %42, %44
%46 = getelementptr inbounds i8, i8* %41, i64 %45
%47 = call i32 @SHA384(i8* %39, i64 %40, i8* %46)
br label %48
48: ; preds = %32
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %28
51: ; preds = %28
%52 = load i64, i64* %4
%53 = mul i64 %52, 4
%54 = call i8* @malloc(i64 %53)
store i8* %54, i8** %8
%55 = load i64, i64* %4
%56 = mul i64 %55, 2
%57 = call i8* @malloc(i64 %56)
store i8* %57, i8** %9
%58 = load i64, i64* %4
%59 = udiv i64 %58, 2
%60 = call i8* @malloc(i64 %59)
store i8* %60, i8** %10
%61 = load i64, i64* %4
%62 = call i8* @malloc(i64 %61)
store i8* %62, i8** %11
%63 = load i8*, i8** %8
%64 = load i64, i64* %4
%65 = getelementptr inbounds i8, i8* %63, i64 %64
%66 = load i8*, i8** %7
%67 = load i64, i64* %4
%68 = call i32 @memcpy(i8* %65, i8* %66, i64 %67)
%69 = load i8*, i8** %9
%70 = load i8*, i8** %7
%71 = load i64, i64* %4
%72 = call i32 @memcpy(i8* %69, i8* %70, i64 %71)
%73 = load i8*, i8** %10
%74 = load i8*, i8** %7
%75 = load i64, i64* %4
%76 = udiv i64 %75, 2
%77 = call i32 @memcpy(i8* %73, i8* %74, i64 %76)
%78 = load i8*, i8** %11
%79 = load i8*, i8** %7
%80 = load i64, i64* %4
%81 = call i32 @memcpy(i8* %78, i8* %79, i64 %80)
%82 = load i8*, i8** %8
%83 = call i32 @free(i8* %82)
%84 = load i8*, i8** %9
%85 = call i32 @free(i8* %84)
%86 = load i8*, i8** %10
%87 = call i32 @free(i8* %86)
%88 = load i8*, i8** %11
%89 = call i32 @free(i8* %88)
%90 = load i8*, i8** %7
ret i8* %90
}

LLVM IR (-O2):
@SHA384_DIGEST_LENGTH = global i64 0
define i8* @hash(i8* %0, i64 %1) {
%3 = load i64, i64* @SHA384_DIGEST_LENGTH
%4 = udiv i64 %1, %3
%5 = trunc i64 %4 to i32
%6 = add i32 %5, 1
%7 = trunc i64 %3 to i32
%8 = mul i32 %6, %7
%9 = tail call i64 @calloc(i32 %8, i32 1)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @SHA384(i8* %0, i64 %1, i8* %10)
%12 = icmp sgt i32 %6, 1
br i1 %12, label %13, label %26
13: ; preds = %2
%14 = zext i32 %6 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 1, %13 ], [ %24, %15 ]
%17 = load i64, i64* @SHA384_DIGEST_LENGTH
%18 = add nsw i64 %16, -1
%19 = mul i64 %17, %18
%20 = getelementptr inbounds i8, i8* %10, i64 %19
%21 = mul i64 %17, %16
%22 = getelementptr inbounds i8, i8* %10, i64 %21
%23 = tail call i32 @SHA384(i8* %20, i64 %17, i8* %22)
%24 = add nuw nsw i64 %16, 1
%25 = icmp eq i64 %24, %14
br i1 %25, label %26, label %15
26: ; preds = %15, %2
%27 = shl i64 %1, 2
%28 = tail call i8* @malloc(i64 %27)
%29 = shl i64 %1, 1
%30 = tail call i8* @malloc(i64 %29)
%31 = lshr i64 %1, 1
%32 = tail call i8* @malloc(i64 %31)
%33 = tail call i8* @malloc(i64 %1)
%34 = getelementptr inbounds i8, i8* %28, i64 %1
%35 = tail call i32 @memcpy(i8* %34, i8* %10, i64 %1)
%36 = tail call i32 @memcpy(i8* %30, i8* %10, i64 %1)
%37 = tail call i32 @memcpy(i8* %32, i8* %10, i64 %31)
%38 = tail call i32 @memcpy(i8* %33, i8* %10, i64 %1)
%39 = tail call i32 @free(i8* %28)
%40 = tail call i32 @free(i8* %30)
%41 = tail call i32 @free(i8* %32)
%42 = tail call i32 @free(i8* %33)
ret i8* %10
}