#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*/ KeccakF1600_StatePermute(int /*<<< orphan*/ *);
int /*<<< orphan*/ store64(unsigned char *, int /*<<< orphan*/);
void keccak_squeezeblocks(unsigned char *h, unsigned long nblocks, uint64_t *s,
                          unsigned int r) {
  unsigned int i;
  while (nblocks > 0) {
    KeccakF1600_StatePermute(s);
    for (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    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    11b0 <keccak_squeezeblocks+0x90>
mov    -0x18(%rbp),%rdi
call   1040 <KeccakF1600_StatePermute@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shr    $0x3,%ecx
cmp    %ecx,%eax
jae    118f <keccak_squeezeblocks+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x3,%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
call   1030 <store64@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1152 <keccak_squeezeblocks+0x32>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <keccak_squeezeblocks+0x17>
add    $0x20,%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     119b <keccak_squeezeblocks+0x7b>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
shr    $0x3,%eax
mov    %ecx,%ecx
mov    %rcx,0x10(%rsp)
cmp    $0x2,%eax
mov    $0x1,%r14d
cmovae %eax,%r14d
jmp    116b <keccak_squeezeblocks+0x4b>
nop
add    0x10(%rsp),%r12
add    $0xffffffffffffffff,%r15
je     119b <keccak_squeezeblocks+0x7b>
mov    %rbx,%rdi
call   1040 <KeccakF1600_StatePermute@plt>
cmpl   $0x8,0xc(%rsp)
jb     1160 <keccak_squeezeblocks+0x40>
mov    %r12,%rbp
xor    %r13d,%r13d
mov    (%rbx,%r13,4),%esi
mov    %rbp,%rdi
call   1030 <store64@plt>
add    $0x1,%r13
add    $0x8,%rbp
cmp    %r13,%r14
jne    1180 <keccak_squeezeblocks+0x60>
jmp    1160 <keccak_squeezeblocks+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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