#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 scalar_t__ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ keccak_absorb(scalar_t__ *, int, unsigned char const *,
                                 unsigned long long, int);
int /*<<< orphan*/ keccak_squeezeblocks(unsigned char *, int, scalar_t__ *,
                                        int);
void sha3_512(unsigned char *output, const unsigned char *input,
              unsigned long long inlen) {
  uint64_t s[25];
  unsigned char t[72];
  size_t i;
  for (i = 0; i < 25; ++i)
    s[i] = 0;
  keccak_absorb(s, 72, input, inlen, 0x06);
  keccak_squeezeblocks(t, 1, s, 72);
  for (i = 0; i < 64; i++)
    output[i] = t[i];
}


x86 assembly (clang, -O0):
<sha3_512>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x138(%rbp)
cmpq   $0x19,-0x138(%rbp)
19
jae    117a <sha3_512+0x5a>
mov    -0x138(%rbp),%rax
movq   $0x0,-0xe0(%rbp,%rax,8)
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    1142 <sha3_512+0x22>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x48,%esi
mov    $0x6,%r8d
call   1040 <keccak_absorb@plt>
lea    -0x130(%rbp),%rdi
lea    -0xe0(%rbp),%rdx
mov    $0x1,%esi
mov    $0x48,%ecx
call   1030 <keccak_squeezeblocks@plt>
movq   $0x0,-0x138(%rbp)
cmpq   $0x40,-0x138(%rbp)
40
jae    1202 <sha3_512+0xe2>
mov    -0x138(%rbp),%rax
mov    -0x130(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x138(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    11c1 <sha3_512+0xa1>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha3_512>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
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)
movq   $0x0,0xc0(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x48,%esi
mov    $0x6,%r8d
call   1040 <keccak_absorb@plt>
lea    0xd0(%rsp),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0x48,%ecx
call   1030 <keccak_squeezeblocks@plt>
movaps 0xd0(%rsp),%xmm0
movaps 0xe0(%rsp),%xmm1
movaps 0xf0(%rsp),%xmm2
movaps 0x100(%rsp),%xmm3
movups %xmm0,(%rbx)
movups %xmm1,0x10(%rbx)
movups %xmm2,0x20(%rbx)
movups %xmm3,0x30(%rbx)
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @sha3_512(i8* nocapture writeonly %0, i8* %1, i64 %2) {
%4 = alloca [25 x i64]
%5 = bitcast [25 x i64]* %4 to i8*
%6 = alloca [72 x i8]
%7 = getelementptr inbounds [72 x i8], [72 x i8]* %6, i64 0, i64 0
%8 = getelementptr inbounds [72 x i8], [72 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [25 x i64], [25 x i64]* %4, i64 0, i64 0
%10 = call i32 @keccak_absorb(i64* %9, i32 72, i8* %1, i64 %2, i32 6)
%11 = call i32 @keccak_squeezeblocks(i8* %8, i32 1, i64* %9, i32 72)
ret void
}