#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 int, int);
int /*<<< orphan*/ keccak_squeezeblocks(unsigned char *, int, scalar_t__ *,
                                        int);
void shake128(unsigned char *output, unsigned int outputByteLen,
              const unsigned char *input, unsigned int inputByteLen) {
  unsigned int i;
  uint64_t s[25];
  unsigned char d[168];
  for (i = 0; i < 25; i++)
    s[i] = 0;
  keccak_absorb(s, 168, input, inputByteLen, 0x1F);
  keccak_squeezeblocks(output, outputByteLen / 168, s, 168);
  output += (outputByteLen / 168) * 168;
  if (outputByteLen % 168) {
    keccak_squeezeblocks(d, 1, s, 168);
    for (i = 0; i < outputByteLen % 168; i++) {
      output[i] = d[i];
    }
  }
}


x86 assembly (clang, -O0):
<shake128>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x19,-0x20(%rbp)
jae    1167 <shake128+0x47>
mov    -0x20(%rbp),%eax
movq   $0x0,-0xf0(%rbp,%rax,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1140 <shake128+0x20>
lea    -0xf0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    $0xa8,%esi
mov    $0x1f,%r8d
call   1040 <keccak_absorb@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
lea    -0xf0(%rbp),%rdx
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
mov    -0xc(%rbp),%eax
mov    $0xa8,%ecx
xor    %edx,%edx
div    %ecx
imul   $0xa8,%eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa8,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
je     124a <shake128+0x12a>
lea    -0x1a0(%rbp),%rdi
lea    -0xf0(%rbp),%rdx
mov    $0x1,%esi
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1a4(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa8,%ecx
xor    %edx,%edx
div    %ecx
mov    -0x1a4(%rbp),%eax
cmp    %edx,%eax
jae    1245 <shake128+0x125>
mov    -0x20(%rbp),%eax
mov    -0x1a0(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1200 <shake128+0xe0>
jmp    124a <shake128+0x12a>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shake128>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x178,%rsp
mov    %esi,%r14d
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,%r15
mov    %r15,%rdi
mov    $0xa8,%esi
mov    $0x1f,%r8d
call   1050 <keccak_absorb@plt>
mov    %r14d,%eax
shr    $0x3,%eax
imul   $0x18618619,%rax,%rbp
shr    $0x21,%rbp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
imul   $0x3cf3cf3d,%r14d,%eax
ror    $0x3,%eax
cmp    $0x1861862,%eax
jb     1222 <shake128+0xf2>
imul   $0xa8,%ebp,%ebp
mov    %ebp,%eax
add    %rax,%rbx
lea    0xd0(%rsp),%r15
mov    %rsp,%rdx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
not    %ebp
add    %r14d,%ebp
add    $0x1,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
add    $0x178,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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