#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*/ shake128_absorb(int /*<<< orphan*/ *, unsigned char const *,
                                   unsigned long long);
int /*<<< orphan*/ shake128_squeezeblocks(unsigned char *, int,
                                          int /*<<< orphan*/ *);
void shake128(unsigned char *output, unsigned long long outlen,
              const unsigned char *input, unsigned long long inlen) {
  unsigned int i;
  unsigned long nblocks = outlen / 168;
  unsigned char t[168];
  uint64_t s[25];
  shake128_absorb(s, input, inlen);
  shake128_squeezeblocks(output, nblocks, s);
  output += nblocks * 168;
  outlen -= nblocks * 168;
  if (outlen) {
    shake128_squeezeblocks(t, 1, s);
    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,-0x30(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <shake128_absorb@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%esi
lea    -0x150(%rbp),%rdx
call   1040 <shake128_squeezeblocks@plt>
imul   $0xa8,-0x30(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
imul   $0xa8,-0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f8 <shake128+0xd8>
lea    -0xe0(%rbp),%rdi
lea    -0x150(%rbp),%rdx
mov    $0x1,%esi
call   1040 <shake128_squeezeblocks@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    11f3 <shake128+0xd3>
mov    -0x24(%rbp),%eax
mov    -0xe0(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c4 <shake128+0xa4>
jmp    11f8 <shake128+0xd8>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shake128>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1030 <shake128_absorb@plt>
mov    %rbx,%rax
shr    $0x3,%rax
movabs $0xc30c30c30c30c31,%rcx
c3 30 0c
mul    %rcx
mov    %rdx,%r12
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1040 <shake128_squeezeblocks@plt>
imul   $0xa8,%r12,%rax
sub    %rax,%rbx
je     11a1 <shake128+0x81>
add    %rax,%r14
lea    0x70(%rsp),%rdi
mov    %rsp,%rdx
mov    $0x1,%esi
call   1040 <shake128_squeezeblocks@plt>
xor    %eax,%eax
nopl   (%rax)
movzbl 0x70(%rsp,%rax,1),%ecx
mov    %cl,(%r14,%rax,1)
add    $0x1,%eax
cmp    %rax,%rbx
ja     1190 <shake128+0x70>
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 i32
%10 = alloca i64
%11 = alloca [168 x i8]
%12 = alloca [25 x i32]
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* %10
%15 = getelementptr inbounds [25 x i32], [25 x i32]* %12, i64 0, i64 0
%16 = load i8*, i8** %7
%17 = load i64, i64* %8
%18 = call i32 @shake128_absorb(i32* %15, i8* %16, i64 %17)
%19 = load i8*, i8** %5
%20 = load i64, i64* %10
%21 = trunc i64 %20 to i32
%22 = getelementptr inbounds [25 x i32], [25 x i32]* %12, i64 0, i64 0
%23 = call i32 @shake128_squeezeblocks(i8* %19, i32 %21, i32* %22)
%24 = load i64, i64* %10
%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* %10
%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 %56
34: ; preds = %4
%35 = getelementptr inbounds [168 x i8], [168 x i8]* %11, i64 0, i64 0
%36 = getelementptr inbounds [25 x i32], [25 x i32]* %12, i64 0, i64 0
%37 = call i32 @shake128_squeezeblocks(i8* %35, i32 1, i32* %36)
store i32 0, i32* %9
br label %38
38: ; preds = %52, %34
%39 = load i32, i32* %9
%40 = zext i32 %39 to i64
%41 = load i64, i64* %6
%42 = icmp ult i64 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %38
%44 = load i32, i32* %9
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds [168 x i8], [168 x i8]* %11, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %5
%49 = load i32, i32* %9
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %43
%53 = load i32, i32* %9
%54 = add i32 %53, 1
store i32 %54, i32* %9
br label %38
55: ; preds = %38
br label %56
56: ; preds = %55, %4
ret void
}

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