#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*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ KeccakF1600_StatePermute(int /*<<< orphan*/ *);
int /*<<< orphan*/ store64(int /*<<< orphan*/ *, int /*<<< orphan*/);
void keccak_squeezeblocks(uint8_t *h, size_t nblocks, uint64_t *s, uint32_t r) {
  while (nblocks > 0) {
    KeccakF1600_StatePermute(s);
    for (size_t i = 0; i < (r >> 3); i++) {
      store64(h + 8 * i, s[i]);
    }
    h += r;
    nblocks--;
  }
}


x86 assembly (clang, -O0):
<keccak_squeezeblocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    11c3 <keccak_squeezeblocks+0xa3>
mov    -0x18(%rbp),%rdi
call   1040 <KeccakF1600_StatePermute@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sar    $0x3,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    119d <keccak_squeezeblocks+0x7d>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <store64@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1153 <keccak_squeezeblocks+0x33>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <keccak_squeezeblocks+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keccak_squeezeblocks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
test   %rsi,%rsi
je     11ab <keccak_squeezeblocks+0x8b>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
sar    $0x3,%eax
movslq %ecx,%rdx
cmp    $0x2,%eax
mov    $0x1,%ecx
cmovae %eax,%ecx
movslq %ecx,%r14
shl    $0x2,%rdx
mov    %rdx,0x10(%rsp)
jmp    117b <keccak_squeezeblocks+0x5b>
cs nopw 0x0(%rax,%rax,1)
nop
add    0x10(%rsp),%r12
add    $0xffffffffffffffff,%r15
je     11ab <keccak_squeezeblocks+0x8b>
mov    %rbx,%rdi
call   1040 <KeccakF1600_StatePermute@plt>
cmpl   $0x8,0xc(%rsp)
jb     1170 <keccak_squeezeblocks+0x50>
mov    %r12,%rbp
xor    %r13d,%r13d
mov    (%rbx,%r13,4),%esi
mov    %rbp,%rdi
call   1030 <store64@plt>
add    $0x1,%r13
add    $0x20,%rbp
cmp    %r13,%r14
jne    1190 <keccak_squeezeblocks+0x70>
jmp    1170 <keccak_squeezeblocks+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @keccak_squeezeblocks(i32* %0, i64 %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
br label %10
10: ; preds = %35, %4
%11 = load i64, i64* %6
%12 = icmp ugt i64 %11, 0
br i1 %12, label %13, label %42
13: ; preds = %10
%14 = load i32*, i32** %7
%15 = call i32 @KeccakF1600_StatePermute(i32* %14)
store i64 0, i64* %9
br label %16
16: ; preds = %32, %13
%17 = load i64, i64* %9
%18 = load i32, i32* %8
%19 = ashr i32 %18, 3
%20 = sext i32 %19 to i64
%21 = icmp ult i64 %17, %20
br i1 %21, label %22, label %35
22: ; preds = %16
%23 = load i32*, i32** %5
%24 = load i64, i64* %9
%25 = mul i64 8, %24
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32*, i32** %7
%28 = load i64, i64* %9
%29 = getelementptr inbounds i32, i32* %27, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @store64(i32* %26, i32 %30)
br label %32
32: ; preds = %22
%33 = load i64, i64* %9
%34 = add i64 %33, 1
store i64 %34, i64* %9
br label %16
35: ; preds = %16
%36 = load i32, i32* %8
%37 = load i32*, i32** %5
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i32, i32* %37, i64 %38
store i32* %39, i32** %5
%40 = load i64, i64* %6
%41 = add i64 %40, -1
store i64 %41, i64* %6
br label %10
42: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @keccak_squeezeblocks(i32* %0, i64 %1, i32* %2, i32 %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %29, label %6
6: ; preds = %4
%7 = ashr i32 %3, 3
%8 = icmp ult i32 %3, 8
%9 = sext i32 %3 to i64
%10 = call i32 @llvm.umax.i32(i32 %7, i32 1)
%11 = sext i32 %10 to i64
br label %12
12: ; preds = %6, %16
%13 = phi i32* [ %0, %6 ], [ %17, %16 ]
%14 = phi i64 [ %1, %6 ], [ %18, %16 ]
%15 = tail call i32 @KeccakF1600_StatePermute(i32* %2)
br i1 %8, label %16, label %20
16: ; preds = %20, %12
%17 = getelementptr inbounds i32, i32* %13, i64 %9
%18 = add i64 %14, -1
%19 = icmp eq i64 %18, 0
br i1 %19, label %29, label %12
20: ; preds = %12, %20
%21 = phi i64 [ %27, %20 ], [ 0, %12 ]
%22 = shl i64 %21, 3
%23 = getelementptr inbounds i32, i32* %13, i64 %22
%24 = getelementptr inbounds i32, i32* %2, i64 %21
%25 = load i32, i32* %24
%26 = tail call i32 @store64(i32* %23, i32 %25)
%27 = add nuw i64 %21, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %16, label %20
29: ; preds = %16, %4
ret void
}