#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*/ KeccakF1600_StatePermute(scalar_t__ *);
int /*<<< orphan*/ keccak_absorb(scalar_t__ *, int, unsigned char const *,
                                 unsigned long long, int);
int /*<<< orphan*/ keccak_squeezeblocks(unsigned char *, int, scalar_t__ *,
                                        int);
unsigned int strlen(char const *);
void cshake128_256simple(unsigned char *output, const char *custom,
                         const unsigned char *in, unsigned long long inlen) {
  uint64_t s[25];
  unsigned char *sep = (unsigned char *)s;
  unsigned char t[168];
  unsigned int i;
  for (i = 0; i < 25; i++)
    s[i] = 0;
  sep[0] = 0x01;
  sep[1] = 0xa8;
  sep[2] = 0x01;
  sep[3] = 0x00;
  sep[4] = 0x01;
  sep[5] = 8 * strlen(custom);
  for (i = 0; i < strlen(custom); i++)
    sep[i + 6] = custom[i];
  KeccakF1600_StatePermute(s);
  keccak_absorb(s, 168, in, inlen, 0x04);
  keccak_squeezeblocks(t, 1, s, 168);
  for (i = 0; i < 32; i++)
    output[i] = t[i];
}


x86 assembly (clang, -O0):
<cshake128_256simple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x19,-0x1a4(%rbp)
jae    11a6 <cshake128_256simple+0x66>
mov    -0x1a4(%rbp),%eax
movq   $0x0,-0xf0(%rbp,%rax,8)
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1173 <cshake128_256simple+0x33>
mov    -0xf8(%rbp),%rax
movb   $0x1,(%rax)
mov    -0xf8(%rbp),%rax
movb   $0xa8,0x1(%rax)
mov    -0xf8(%rbp),%rax
movb   $0x1,0x2(%rax)
mov    -0xf8(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0xf8(%rbp),%rax
movb   $0x1,0x4(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
shl    $0x3,%eax
mov    %al,%cl
mov    -0xf8(%rbp),%rax
mov    %cl,0x5(%rax)
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
mov    %eax,-0x1a8(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1a8(%rbp),%eax
cmp    %ecx,%eax
jae    1259 <cshake128_256simple+0x119>
mov    -0x10(%rbp),%rax
mov    -0x1a4(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0xf8(%rbp),%rax
mov    -0x1a4(%rbp),%ecx
add    $0x6,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    11fe <cshake128_256simple+0xbe>
lea    -0xf0(%rbp),%rdi
call   1050 <KeccakF1600_StatePermute@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0xa8,%esi
mov    $0x4,%r8d
call   1060 <keccak_absorb@plt>
lea    -0x1a0(%rbp),%rdi
lea    -0xf0(%rbp),%rdx
mov    $0x1,%esi
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x20,-0x1a4(%rbp)
jae    12e6 <cshake128_256simple+0x1a6>
mov    -0x1a4(%rbp),%eax
mov    -0x1a0(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1a4(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    12ab <cshake128_256simple+0x16b>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cshake128_256simple>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x180,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
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)
movw   $0xa801,(%rsp)
movb   $0x1,0x2(%rsp)
movb   $0x1,0x4(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
shl    $0x3,%al
mov    %al,0x5(%rsp)
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11ff <cshake128_256simple+0xbf>
xor    %ebx,%ebx
nop
movzbl 0x0(%r13,%rbx,1),%eax
lea    0x6(%rbx),%ecx
mov    %al,(%rsp,%rcx,1)
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     11e0 <cshake128_256simple+0xa0>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <KeccakF1600_StatePermute@plt>
mov    %rbx,%rdi
mov    $0xa8,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x4,%r8d
call   1060 <keccak_absorb@plt>
lea    0xd0(%rsp),%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    $0xa8,%ecx
call   1030 <keccak_squeezeblocks@plt>
movaps 0xd0(%rsp),%xmm0
movaps 0xe0(%rsp),%xmm1
movups %xmm0,(%r12)
movups %xmm1,0x10(%r12)
add    $0x180,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @cshake128_256simple(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [25 x i64]
%10 = alloca i8*
%11 = alloca [168 x i8]
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%13 = getelementptr inbounds [25 x i64], [25 x i64]* %9, i64 0, i64 0
%14 = bitcast i64* %13 to i8*
store i8* %14, i8** %10
store i32 0, i32* %12
br label %15
15: ; preds = %22, %4
%16 = load i32, i32* %12
%17 = icmp ult i32 %16, 25
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32, i32* %12
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [25 x i64], [25 x i64]* %9, i64 0, i64 %20
store i64 0, i64* %21
br label %22
22: ; preds = %18
%23 = load i32, i32* %12
%24 = add i32 %23, 1
store i32 %24, i32* %12
br label %15
25: ; preds = %15
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 1, i8* %27
%28 = load i8*, i8** %10
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 -88, i8* %29
%30 = load i8*, i8** %10
%31 = getelementptr inbounds i8, i8* %30, i64 2
store i8 1, i8* %31
%32 = load i8*, i8** %10
%33 = getelementptr inbounds i8, i8* %32, i64 3
store i8 0, i8* %33
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i64 4
store i8 1, i8* %35
%36 = load i8*, i8** %6
%37 = call i32 @strlen(i8* %36)
%38 = mul i32 8, %37
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %10
%41 = getelementptr inbounds i8, i8* %40, i64 5
store i8 %39, i8* %41
store i32 0, i32* %12
br label %42
42: ; preds = %58, %25
%43 = load i32, i32* %12
%44 = load i8*, i8** %6
%45 = call i32 @strlen(i8* %44)
%46 = icmp ult i32 %43, %45
br i1 %46, label %47, label %61
47: ; preds = %42
%48 = load i8*, i8** %6
%49 = load i32, i32* %12
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = load i8*, i8** %10
%54 = load i32, i32* %12
%55 = add i32 %54, 6
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 %52, i8* %57
br label %58
58: ; preds = %47
%59 = load i32, i32* %12
%60 = add i32 %59, 1
store i32 %60, i32* %12
br label %42
61: ; preds = %42
%62 = getelementptr inbounds [25 x i64], [25 x i64]* %9, i64 0, i64 0
%63 = call i32 @KeccakF1600_StatePermute(i64* %62)
%64 = getelementptr inbounds [25 x i64], [25 x i64]* %9, i64 0, i64 0
%65 = load i8*, i8** %7
%66 = load i64, i64* %8
%67 = call i32 @keccak_absorb(i64* %64, i32 168, i8* %65, i64 %66, i32 4)
%68 = getelementptr inbounds [168 x i8], [168 x i8]* %11, i64 0, i64 0
%69 = getelementptr inbounds [25 x i64], [25 x i64]* %9, i64 0, i64 0
%70 = call i32 @keccak_squeezeblocks(i8* %68, i32 1, i64* %69, i32 168)
store i32 0, i32* %12
br label %71
71: ; preds = %83, %61
%72 = load i32, i32* %12
%73 = icmp ult i32 %72, 32
br i1 %73, label %74, label %86
74: ; preds = %71
%75 = load i32, i32* %12
%76 = zext i32 %75 to i64
%77 = getelementptr inbounds [168 x i8], [168 x i8]* %11, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = load i8*, i8** %5
%80 = load i32, i32* %12
%81 = zext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
store i8 %78, i8* %82
br label %83
83: ; preds = %74
%84 = load i32, i32* %12
%85 = add i32 %84, 1
store i32 %85, i32* %12
br label %71
86: ; preds = %71
ret void
}

LLVM IR (-O2):
define void @cshake128_256simple(i8* nocapture writeonly %0, i8* %1, i8* %2, i64 %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
store i8 1, i8* %6
%10 = getelementptr inbounds i8, i8* %6, i64 1
store i8 -88, i8* %10
%11 = getelementptr inbounds i8, i8* %6, i64 2
store i8 1, i8* %11
%12 = getelementptr inbounds i8, i8* %6, i64 4
store i8 1, i8* %12
%13 = tail call i32 @strlen(i8* %1)
%14 = trunc i32 %13 to i8
%15 = shl i8 %14, 3
%16 = getelementptr inbounds i8, i8* %6, i64 5
store i8 %15, i8* %16
%17 = tail call i32 @strlen(i8* %1)
%18 = icmp eq i32 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %4, %19
%20 = phi i64 [ %26, %19 ], [ 0, %4 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = load i8, i8* %21
%23 = add nuw i64 %20, 6
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds i8, i8* %6, i64 %24
store i8 %22, i8* %25
%26 = add nuw nsw i64 %20, 1
%27 = tail call i32 @strlen(i8* %1)
%28 = zext i32 %27 to i64
%29 = icmp ult i64 %26, %28
br i1 %29, label %19, label %30
30: ; preds = %19, %4
%31 = getelementptr inbounds [168 x i8], [168 x i8]* %7, i64 0, i64 0
%32 = call i32 @KeccakF1600_StatePermute(i64* %9)
%33 = call i32 @keccak_absorb(i64* %9, i32 168, i8* %2, i64 %3, i32 4)
%34 = call i32 @keccak_squeezeblocks(i8* %8, i32 1, i64* %9, i32 168)
ret void
}