#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 /*<<< orphan*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ keccak_absorb(int /*<<< orphan*/ *, int,
                                 unsigned char const *, unsigned long long,
                                 int);
int /*<<< orphan*/ keccak_squeezeblocks(unsigned char *, int,
                                        int /*<<< orphan*/ *, int);
void shake256(unsigned char *output, unsigned long long outlen,
              const unsigned char *input, unsigned long long inlen) {
  uint64_t s[25];
  unsigned char t[136];
  unsigned long long nblocks = outlen / 136;
  size_t i;
  keccak_absorb(s, 136, input, inlen, 0x1F);
  keccak_squeezeblocks(output, nblocks, s, 136);
  output += nblocks * 136;
  outlen -= nblocks * 136;
  if (outlen) {
    keccak_squeezeblocks(t, 1, s, 136);
    for (i = 0; i < outlen; i++)
      output[i] = t[i];
  }
}


x86 assembly (clang, -O0):
<shake256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x88,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x128(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x88,%esi
mov    $0x1f,%r8d
call   1040 <keccak_absorb@plt>
mov    -0x8(%rbp),%rdi
mov    -0x128(%rbp),%rax
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
imul   $0x88,-0x128(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
imul   $0x88,-0x128(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1232 <shake256+0x112>
lea    -0x120(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x1,%esi
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
movq   $0x0,-0x130(%rbp)
mov    -0x130(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    122d <shake256+0x10d>
mov    -0x130(%rbp),%rax
mov    -0x120(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x130(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x130(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x130(%rbp)
jmp    11e9 <shake256+0xc9>
jmp    1232 <shake256+0x112>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shake256>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x88,%esi
mov    $0x1f,%r8d
call   1050 <keccak_absorb@plt>
movabs $0xf0f0f0f0f0f0f0f1,%rcx
f0 f0 f0
mov    %r12,%rax
mul    %rcx
mov    %rdx,%rbx
shr    $0x7,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
mov    %rbx,%rax
shl    $0x7,%rax
lea    (%rax,%rbx,8),%rax
sub    %rax,%r12
je     11be <shake256+0x8e>
add    %rax,%r14
lea    0x70(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @shake256(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [25 x i32]
%10 = alloca [136 x i8]
%11 = alloca i64
%12 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%13 = load i64, i64* %6
%14 = udiv i64 %13, 136
store i64 %14, i64* %11
%15 = getelementptr inbounds [25 x i32], [25 x i32]* %9, i64 0, i64 0
%16 = load i8*, i8** %7
%17 = load i64, i64* %8
%18 = call i32 @keccak_absorb(i32* %15, i32 136, i8* %16, i64 %17, i32 31)
%19 = load i8*, i8** %5
%20 = load i64, i64* %11
%21 = trunc i64 %20 to i32
%22 = getelementptr inbounds [25 x i32], [25 x i32]* %9, i64 0, i64 0
%23 = call i32 @keccak_squeezeblocks(i8* %19, i32 %21, i32* %22, i32 136)
%24 = load i64, i64* %11
%25 = mul i64 %24, 136
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 %25
store i8* %27, i8** %5
%28 = load i64, i64* %11
%29 = mul i64 %28, 136
%30 = load i64, i64* %6
%31 = sub i64 %30, %29
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %53
34: ; preds = %4
%35 = getelementptr inbounds [136 x i8], [136 x i8]* %10, i64 0, i64 0
%36 = getelementptr inbounds [25 x i32], [25 x i32]* %9, i64 0, i64 0
%37 = call i32 @keccak_squeezeblocks(i8* %35, i32 1, i32* %36, i32 136)
store i64 0, i64* %12
br label %38
38: ; preds = %49, %34
%39 = load i64, i64* %12
%40 = load i64, i64* %6
%41 = icmp ult i64 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i64, i64* %12
%44 = getelementptr inbounds [136 x i8], [136 x i8]* %10, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = load i8*, i8** %5
%47 = load i64, i64* %12
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 %45, i8* %48
br label %49
49: ; preds = %42
%50 = load i64, i64* %12
%51 = add i64 %50, 1
store i64 %51, i64* %12
br label %38
52: ; preds = %38
br label %53
53: ; preds = %52, %4
ret void
}

LLVM IR (-O2):
define void @shake256(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca [25 x i32]
%6 = alloca [136 x i8]
%7 = bitcast [25 x i32]* %5 to i8*
%8 = getelementptr inbounds [136 x i8], [136 x i8]* %6, i64 0, i64 0
%9 = udiv i64 %1, 136
%10 = getelementptr inbounds [25 x i32], [25 x i32]* %5, i64 0, i64 0
%11 = call i32 @keccak_absorb(i32* %10, i32 136, i8* %2, i64 %3, i32 31)
%12 = trunc i64 %9 to i32
%13 = call i32 @keccak_squeezeblocks(i8* %0, i32 %12, i32* %10, i32 136)
%14 = mul nuw i64 %9, 136
%15 = urem i64 %1, 136
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %4
%18 = getelementptr i8, i8* %0, i64 %14
%19 = getelementptr inbounds [136 x i8], [136 x i8]* %6, i64 0, i64 0
%20 = call i32 @keccak_squeezeblocks(i8* %8, i32 1, i32* %10, i32 136)
br label %21
21: ; preds = %17, %4
ret void
}