#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];
  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)
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   1040 <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     1232 <shake128+0x112>
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    122d <shake128+0x10d>
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    11e9 <shake128+0xc9>
jmp    1232 <shake128+0x112>
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
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     11ba <shake128+0x8a>
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 = load i64, i64* %6
%14 = udiv i64 %13, 168
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 168, 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 168)
%24 = load i64, i64* %11
%25 = mul i64 %24, 168
%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, 168
%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 [168 x i8], [168 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 168)
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 [168 x i8], [168 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 @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
}