#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 long long, int);
int /*<<< orphan*/ keccak_squeezeblocks(unsigned char *, int, scalar_t__ *,
                                        int);
void s2n_sike_p434_r3_shake256(unsigned char *output, unsigned long long outlen,
                               const unsigned char *input,
                               unsigned long long inlen) {
  uint64_t s[25];
  unsigned char t[136];
  unsigned long long nblocks = outlen / 136;
  size_t i;
  for (i = 0; i < 25; ++i) {
    s[i] = 0;
  }
  keccak_absorb(s, 136, input, inlen, 0x1F);
  keccak_squeezeblocks(output, nblocks, s, 136);
  output += nblocks * 136;
  outlen -= nblocks * 136;
  if (outlen) {
    keccak_squeezeblocks(t, 1, s, 136);
    for (i = 0; i < outlen; i++) {
      output[i] = t[i];
    }
  }
}


x86 assembly (clang, -O0):
<s2n_sike_p434_r3_shake256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x88,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x188(%rbp)
movq   $0x0,-0x190(%rbp)
cmpq   $0x19,-0x190(%rbp)
19
jae    1193 <s2n_sike_p434_r3_shake256+0x73>
mov    -0x190(%rbp),%rax
movq   $0x0,-0xf0(%rbp,%rax,8)
mov    -0x190(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x190(%rbp)
jmp    115b <s2n_sike_p434_r3_shake256+0x3b>
lea    -0xf0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x88,%esi
mov    $0x1f,%r8d
call   1040 <keccak_absorb@plt>
mov    -0x8(%rbp),%rdi
mov    -0x188(%rbp),%rax
mov    %eax,%esi
lea    -0xf0(%rbp),%rdx
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
imul   $0x88,-0x188(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
imul   $0x88,-0x188(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1275 <s2n_sike_p434_r3_shake256+0x155>
lea    -0x180(%rbp),%rdi
lea    -0xf0(%rbp),%rdx
mov    $0x1,%esi
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
movq   $0x0,-0x190(%rbp)
mov    -0x190(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1270 <s2n_sike_p434_r3_shake256+0x150>
mov    -0x190(%rbp),%rax
mov    -0x180(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x190(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x190(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x190(%rbp)
jmp    122c <s2n_sike_p434_r3_shake256+0x10c>
jmp    1275 <s2n_sike_p434_r3_shake256+0x155>
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s2n_sike_p434_r3_shake256>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
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    $0x88,%esi
mov    $0x1f,%r8d
call   1050 <keccak_absorb@plt>
movabs $0xf0f0f0f0f0f0f0f1,%rcx
f0 f0 f0
mov    %r12,%rax
mul    %rcx
mov    %rdx,%rbx
shr    $0x7,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
mov    %rbx,%rax
shl    $0x7,%rax
lea    (%rax,%rbx,8),%rax
sub    %rax,%r12
je     1217 <s2n_sike_p434_r3_shake256+0xe7>
add    %rax,%r14
lea    0xd0(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x88,%ecx
call   1030 <keccak_squeezeblocks@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @s2n_sike_p434_r3_shake256(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca [25 x i64]
%6 = bitcast [25 x i64]* %5 to i8*
%7 = alloca [136 x i8]
%8 = getelementptr inbounds [136 x i8], [136 x i8]* %7, i64 0, i64 0
%9 = udiv i64 %1, 136
%10 = getelementptr inbounds [25 x i64], [25 x i64]* %5, i64 0, i64 0
%11 = call i32 @keccak_absorb(i64* %10, i32 136, i8* %2, i64 %3, i32 31)
%12 = trunc i64 %9 to i32
%13 = call i32 @keccak_squeezeblocks(i8* %0, i32 %12, i64* %10, i32 136)
%14 = mul nuw i64 %9, 136
%15 = urem i64 %1, 136
%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 [136 x i8], [136 x i8]* %7, i64 0, i64 0
%20 = call i32 @keccak_squeezeblocks(i8* %8, i32 1, i64* %10, i32 136)
br label %21
21: ; preds = %17, %4
ret void
}