#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*/ blocks(unsigned long long *, unsigned char const *,
                          unsigned long long);
int /*<<< orphan*/ store64_bigendian(unsigned char *, unsigned long long);
int crypto_hash_sha512_tinynacl(unsigned char *o, const unsigned char *m,
                                unsigned long long n) {
  long long i;
  unsigned char x[256];
  unsigned long long b = n;
  unsigned long long h[8] = {0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
                             0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
                             0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
                             0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL};
  blocks(h, m, n);
  m += n;
  n &= 127;
  m -= n;
  for (i = 0; i < sizeof x; ++i)
    x[i] = 0;
  for (i = 0; i < n; ++i)
    x[i] = m[i];
  x[n] = 128;
  n = 256 - 128 * (n < 112);
  x[n - 9] = b >> 61;
  store64_bigendian(x + n - 8, b << 3);
  blocks(h, x, n);
  for (i = 0; i < 8; ++i)
    store64_bigendian(o + 8 * i, h[i]);
  return 0;
}


x86 assembly (clang, -O0):
<crypto_hash_sha512_tinynacl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x170(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    -0x170(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <blocks@plt>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
and    $0x7f,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x100,-0x20(%rbp)
jae    11dd <crypto_hash_sha512_tinynacl+0xad>
mov    -0x20(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b2 <crypto_hash_sha512_tinynacl+0x82>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    121a <crypto_hash_sha512_tinynacl+0xea>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e5 <crypto_hash_sha512_tinynacl+0xb5>
mov    -0x18(%rbp),%rax
movb   $0x80,-0x120(%rbp,%rax,1)
80
cmpq   $0x70,-0x18(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%ecx
shl    $0x7,%ecx
mov    $0x100,%eax
sub    %ecx,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x128(%rbp),%rax
shr    $0x3d,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
sub    $0x9,%rax
mov    %cl,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffff8,%rdi
mov    -0x128(%rbp),%rsi
shl    $0x3,%rsi
call   1050 <store64_bigendian@plt>
lea    -0x170(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <blocks@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x8,-0x20(%rbp)
jge    12d9 <crypto_hash_sha512_tinynacl+0x1a9>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    -0x170(%rbp,%rax,8),%rsi
ff
call   1050 <store64_bigendian@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    129d <crypto_hash_sha512_tinynacl+0x16d>
xor    %eax,%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_hash_sha512_tinynacl>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
call   1030 <blocks@plt>
mov    %r12,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x130(%rsp)
and    $0x7f,%rbx
je     1214 <crypto_hash_sha512_tinynacl+0xe4>
add    %r12,%r15
sub    %rbx,%r15
lea    0x40(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movb   $0x80,0x40(%rsp,%rbx,1)
xor    %eax,%eax
cmp    $0x70,%rbx
setae  %al
shl    $0x7,%rax
lea    0x80(%rax),%rbx
mov    %r12,%rcx
shr    $0x3d,%rcx
mov    %cl,0xb7(%rsp,%rax,1)
lea    (%rsp,%rax,1),%rdi
add    $0xb8,%rdi
shl    $0x3,%r12
mov    %r12,%rsi
call   1050 <store64_bigendian@plt>
mov    %rsp,%rdi
lea    0x40(%rsp),%rsi
mov    %rbx,%rdx
call   1030 <blocks@plt>
mov    (%rsp),%rsi
mov    %r14,%rdi
call   1050 <store64_bigendian@plt>
lea    0x8(%r14),%rdi
mov    0x8(%rsp),%rsi
call   1050 <store64_bigendian@plt>
lea    0x10(%r14),%rdi
mov    0x10(%rsp),%rsi
call   1050 <store64_bigendian@plt>
lea    0x18(%r14),%rdi
mov    0x18(%rsp),%rsi
call   1050 <store64_bigendian@plt>
lea    0x20(%r14),%rdi
mov    0x20(%rsp),%rsi
call   1050 <store64_bigendian@plt>
lea    0x28(%r14),%rdi
mov    0x28(%rsp),%rsi
call   1050 <store64_bigendian@plt>
lea    0x30(%r14),%rdi
mov    0x30(%rsp),%rsi
call   1050 <store64_bigendian@plt>
add    $0x38,%r14
mov    0x38(%rsp),%rsi
mov    %r14,%rdi
call   1050 <store64_bigendian@plt>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.crypto_hash_sha512_tinynacl.h = [8 x i64] [i64 7640891576956012808, i64 -4942790177534073029, i64 4354685564936845355, i64 -6534734903238641935, i64 5840696475078001361, i64 -7276294671716946913, i64 2270897969802886507, i64 6620516959819538809]
define i32 @crypto_hash_sha512_tinynacl(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca [256 x i8]
%9 = alloca i64
%10 = alloca [8 x i64]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = load i64, i64* %6
store i64 %11, i64* %9
%12 = bitcast [8 x i64]* %10 to i8*
%13 = getelementptr inbounds [8 x i64], [8 x i64]* %10, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i32 @blocks(i64* %13, i8* %14, i64 %15)
%17 = load i64, i64* %6
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 %17
store i8* %19, i8** %5
%20 = load i64, i64* %6
%21 = and i64 %20, 127
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = load i8*, i8** %5
%24 = sub i64 0, %22
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %5
store i64 0, i64* %7
br label %26
26: ; preds = %32, %3
%27 = load i64, i64* %7
%28 = icmp ult i64 %27, 256
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i64, i64* %7
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %29
%33 = load i64, i64* %7
%34 = add nsw i64 %33, 1
store i64 %34, i64* %7
br label %26
35: ; preds = %26
store i64 0, i64* %7
br label %36
36: ; preds = %47, %35
%37 = load i64, i64* %7
%38 = load i64, i64* %6
%39 = icmp ult i64 %37, %38
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = load i8*, i8** %5
%42 = load i64, i64* %7
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = load i8, i8* %43
%45 = load i64, i64* %7
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %45
store i8 %44, i8* %46
br label %47
47: ; preds = %40
%48 = load i64, i64* %7
%49 = add nsw i64 %48, 1
store i64 %49, i64* %7
br label %36
50: ; preds = %36
%51 = load i64, i64* %6
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %51
store i8 -128, i8* %52
%53 = load i64, i64* %6
%54 = icmp ult i64 %53, 112
%55 = zext i1 %54 to i32
%56 = mul nsw i32 128, %55
%57 = sub nsw i32 256, %56
%58 = sext i32 %57 to i64
store i64 %58, i64* %6
%59 = load i64, i64* %9
%60 = lshr i64 %59, 61
%61 = trunc i64 %60 to i8
%62 = load i64, i64* %6
%63 = sub i64 %62, 9
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %63
store i8 %61, i8* %64
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%66 = load i64, i64* %6
%67 = getelementptr inbounds i8, i8* %65, i64 %66
%68 = getelementptr inbounds i8, i8* %67, i64 -8
%69 = load i64, i64* %9
%70 = shl i64 %69, 3
%71 = call i32 @store64_bigendian(i8* %68, i64 %70)
%72 = getelementptr inbounds [8 x i64], [8 x i64]* %10, i64 0, i64 0
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%74 = load i64, i64* %6
%75 = call i32 @blocks(i64* %72, i8* %73, i64 %74)
store i64 0, i64* %7
br label %76
76: ; preds = %88, %50
%77 = load i64, i64* %7
%78 = icmp slt i64 %77, 8
br i1 %78, label %79, label %91
79: ; preds = %76
%80 = load i8*, i8** %4
%81 = load i64, i64* %7
%82 = mul nsw i64 8, %81
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i64, i64* %7
%85 = getelementptr inbounds [8 x i64], [8 x i64]* %10, i64 0, i64 %84
%86 = load i64, i64* %85
%87 = call i32 @store64_bigendian(i8* %83, i64 %86)
br label %88
88: ; preds = %79
%89 = load i64, i64* %7
%90 = add nsw i64 %89, 1
store i64 %90, i64* %7
br label %76
91: ; preds = %76
ret i32 0
}

LLVM IR (-O2):
@__const.crypto_hash_sha512_tinynacl.h = [8 x i64] [i64 7640891576956012808, i64 -4942790177534073029, i64 4354685564936845355, i64 -6534734903238641935, i64 5840696475078001361, i64 -7276294671716946913, i64 2270897969802886507, i64 6620516959819538809]
define i32 @crypto_hash_sha512_tinynacl(i8* %0, i8* %1, i64 %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = alloca [8 x i64]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = bitcast [8 x i64]* %6 to i8*
%9 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 0
%10 = call i32 @blocks(i64* %9, i8* %1, i64 %2)
%11 = and i64 %2, 127
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = getelementptr inbounds i8, i8* %1, i64 %2
%15 = sub nsw i64 0, %11
%16 = getelementptr i8, i8* %14, i64 %15
br label %17
17: ; preds = %13, %3
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %11
store i8 -128, i8* %18
%19 = icmp ult i64 %11, 112
%20 = select i1 %19, i64 128, i64 256
%21 = lshr i64 %2, 61
%22 = trunc i64 %21 to i8
%23 = add nsw i64 %20, -9
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %23
store i8 %22, i8* %24
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %20
%26 = getelementptr inbounds i8, i8* %25, i64 -8
%27 = shl i64 %2, 3
%28 = call i32 @store64_bigendian(i8* %26, i64 %27)
%29 = call i32 @blocks(i64* %9, i8* %7, i64 %20)
%30 = load i64, i64* %9
%31 = call i32 @store64_bigendian(i8* %0, i64 %30)
%32 = getelementptr inbounds i8, i8* %0, i64 8
%33 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 1
%34 = load i64, i64* %33
%35 = call i32 @store64_bigendian(i8* %32, i64 %34)
%36 = getelementptr inbounds i8, i8* %0, i64 16
%37 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 2
%38 = load i64, i64* %37
%39 = call i32 @store64_bigendian(i8* %36, i64 %38)
%40 = getelementptr inbounds i8, i8* %0, i64 24
%41 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 3
%42 = load i64, i64* %41
%43 = call i32 @store64_bigendian(i8* %40, i64 %42)
%44 = getelementptr inbounds i8, i8* %0, i64 32
%45 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 4
%46 = load i64, i64* %45
%47 = call i32 @store64_bigendian(i8* %44, i64 %46)
%48 = getelementptr inbounds i8, i8* %0, i64 40
%49 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 5
%50 = load i64, i64* %49
%51 = call i32 @store64_bigendian(i8* %48, i64 %50)
%52 = getelementptr inbounds i8, i8* %0, i64 48
%53 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 6
%54 = load i64, i64* %53
%55 = call i32 @store64_bigendian(i8* %52, i64 %54)
%56 = getelementptr inbounds i8, i8* %0, i64 56
%57 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 7
%58 = load i64, i64* %57
%59 = call i32 @store64_bigendian(i8* %56, i64 %58)
ret i32 0
}