#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 shake128(unsigned char *output, unsigned long long outlen,
              const unsigned char *input, unsigned long long inlen) {
  uint64_t s[25] = {0};
  unsigned char t[168];
  unsigned long long nblocks = outlen / 168;
  size_t i;
  keccak_absorb(s, 168, input, inlen, 0x1F);
  keccak_squeezeblocks(output, nblocks, s, 168);
  output += nblocks * 168;
  outlen -= nblocks * 168;
  if (outlen) {
    keccak_squeezeblocks(t, 1, s, 168);
    for (i = 0; i < outlen; i++)
      output[i] = t[i];
  }
}


x86 assembly (clang, -O0):
<shake128>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    $0xa8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x148(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0xa8,%esi
mov    $0x1f,%r8d
call   1050 <keccak_absorb@plt>
mov    -0x8(%rbp),%rdi
mov    -0x148(%rbp),%rax
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
imul   $0xa8,-0x148(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
imul   $0xa8,-0x148(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1255 <shake128+0x125>
lea    -0x140(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x1,%esi
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
movq   $0x0,-0x150(%rbp)
mov    -0x150(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1250 <shake128+0x120>
mov    -0x150(%rbp),%rax
mov    -0x140(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x150(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x150(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x150(%rbp)
jmp    120c <shake128+0xdc>
jmp    1255 <shake128+0x125>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shake128>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xa8,%esi
mov    $0x1f,%r8d
call   1050 <keccak_absorb@plt>
mov    %r12,%rax
shr    $0x3,%rax
movabs $0xc30c30c30c30c31,%rcx
c3 30 0c
mul    %rcx
mov    %rdx,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
imul   $0xa8,%rbx,%rax
sub    %rax,%r12
je     11e2 <shake128+0xb2>
add    %rax,%r14
lea    0x70(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @shake128(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca [25 x i32]
%6 = alloca [168 x i8]
%7 = bitcast [25 x i32]* %5 to i8*
%8 = getelementptr inbounds [168 x i8], [168 x i8]* %6, i64 0, i64 0
%9 = udiv i64 %1, 168
%10 = getelementptr inbounds [25 x i32], [25 x i32]* %5, i64 0, i64 0
%11 = call i32 @keccak_absorb(i32* %10, i32 168, i8* %2, i64 %3, i32 31)
%12 = trunc i64 %9 to i32
%13 = call i32 @keccak_squeezeblocks(i8* %0, i32 %12, i32* %10, i32 168)
%14 = mul nuw i64 %9, 168
%15 = urem i64 %1, 168
%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 [168 x i8], [168 x i8]* %6, i64 0, i64 0
%20 = call i32 @keccak_squeezeblocks(i8* %8, i32 1, i32* %10, i32 168)
br label %21
21: ; preds = %17, %4
ret void
}