#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;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ cshake256_simple_absorb_r1(int /*<<< orphan*/ *,
                                              int /*<<< orphan*/,
                                              unsigned char const *,
                                              unsigned long long);
int /*<<< orphan*/ keccak_squeezeblocks_r1(unsigned char *, int,
                                           int /*<<< orphan*/ *, int);
void cshake256_simple_r1(unsigned char *output, unsigned long long outlen,
                         uint16_t cstm, const unsigned char *in,
                         unsigned long long inlen) {
  uint64_t s[25];
  unsigned char t[136];
  cshake256_simple_absorb_r1(s, cstm, in, inlen);
  keccak_squeezeblocks_r1(output, outlen / 136, s, 136);
  output += (outlen / 136) * 136;
  if (outlen % 136) {
    keccak_squeezeblocks_r1(t, 1, s, 136);
    for (unsigned int i = 0; i < outlen % 136; i++)
      output[i] = t[i];
  }
}


x86 assembly (clang, -O0):
<cshake256_simple_r1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <cshake256_simple_absorb_r1@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x88,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks_r1@plt>
mov    -0x10(%rbp),%rax
mov    $0x88,%ecx
xor    %edx,%edx
div    %rcx
imul   $0x88,%rax,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x88,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
je     1234 <cshake256_simple_r1+0x114>
lea    -0x120(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x1,%esi
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks_r1@plt>
movl   $0x0,-0x124(%rbp)
mov    -0x124(%rbp),%eax
mov    %rax,-0x130(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x88,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x130(%rbp),%rax
cmp    %rdx,%rax
jae    122f <cshake256_simple_r1+0x10f>
mov    -0x124(%rbp),%eax
mov    -0x120(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x124(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11d6 <cshake256_simple_r1+0xb6>
jmp    1234 <cshake256_simple_r1+0x114>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cshake256_simple_r1>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %edx,%esi
mov    %rcx,%rdx
mov    %r8,%rcx
call   1040 <cshake256_simple_absorb_r1@plt>
movabs $0xf0f0f0f0f0f0f0f1,%rcx
f0 f0 f0
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%r12
shr    $0x7,%r12
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks_r1@plt>
mov    %r12,%rax
shl    $0x7,%rax
lea    (%rax,%r12,8),%rax
sub    %rax,%rbx
je     11b1 <cshake256_simple_r1+0x91>
add    %rax,%r14
lea    0x70(%rsp),%rdi
mov    %rsp,%rdx
mov    $0x1,%esi
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks_r1@plt>
xor    %eax,%eax
nopl   (%rax)
movzbl 0x70(%rsp,%rax,1),%ecx
mov    %cl,(%r14,%rax,1)
add    $0x1,%eax
cmp    %rax,%rbx
ja     11a0 <cshake256_simple_r1+0x80>
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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