// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/lunarkeyakv2/compact/KeccakP-800-compact.c
// Function: KeccakP800_Permute_Nrounds
void KeccakP800_Permute_Nrounds(void *argState, tSmallUInt nr)
{
    tSmallUInt x, y;
    tKeccakLane temp;
    tKeccakLane BC[5];
    tKeccakLane *state;
    UINT8       LFSRstate;

    state = (tKeccakLane*)argState;
    LFSRstate = 0x01;
    for ( y = (tSmallUInt)(cKeccakNumberOfRounds - nr); y != 0; --y )
    {
        for( x = 1; x < 128; x <<= 1 )
        {
            if ((LFSRstate & 0x80) != 0)
                /* Primitive polynomial over GF(2): x^8+x^6+x^5+x^4+1 */
                LFSRstate = (LFSRstate << 1) ^ 0x71;
            else
                LFSRstate <<= 1;
        }
    }

    do
    {
        /* Theta */
        for ( x = 0; x < 5; ++x )
        {
            BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ state[15 + x] ^ state[20 + x];
        }
        for ( x = 0; x < 5; ++x )
        {
            temp = BC[MOD5(x+4)] ^ ROL32(BC[MOD5(x+1)], 1);
            for ( y = 0; y < 25; y += 5 )
            {
                state[y + x] ^= temp;
            }
        }

        /* Rho Pi */
        temp = state[1];
        for ( x = 0; x < 24; ++x )
        {
            BC[0] = state[KeccakP800_PiLane[x]];
            state[KeccakP800_PiLane[x]] = ROL32( temp, KeccakP800_RotationConstants[x] );
            temp = BC[0];
        }

        /*    Chi */
        for ( y = 0; y < 25; y += 5 )
        {
#if defined(UNROLL_CHILOOP)
            BC[0] = state[y + 0];
            BC[1] = state[y + 1];
            BC[2] = state[y + 2];
            BC[3] = state[y + 3];
            BC[4] = state[y + 4];
#else
            for ( x = 0; x < 5; ++x )
            {
                BC[x] = state[y + x];
            }
#endif
            for ( x = 0; x < 5; ++x )
            {
                state[y + x] = BC[x] ^((~BC[MOD5(x+1)]) & BC[MOD5(x+2)]);
            }
        }

        /*    Iota */
        temp = 0;
        for( x = 1; x < 128; x <<= 1 )
        {
            if ( x <= (sizeof(tKeccakLane)*8) )
                temp ^= (tKeccakLane)(LFSRstate & 1) << (x - 1);

            if ((LFSRstate & 0x80) != 0)
                /* Primitive polynomial over GF(2): x^8+x^6+x^5+x^4+1 */
                LFSRstate = (LFSRstate << 1) ^ 0x71;
            else
                LFSRstate <<= 1;
        }
        state[0] ^= temp;
    }
    while( --nr != 0 );
}

// Assembly:
movl $0x16, %ecx
subl %esi, %ecx
movb $0x1, %al
movl $0x1, %edx
subl $0x1, %ecx
jb 0x6c09
movl %edx, %r8d
cmpl $0x7f, %r8d
ja 0x6be0
leal (%rax,%rax), %r9d
movzbl %r9b, %r10d
xorb $0x71, %r9b
testb %al, %al
movzbl %r9b, %eax
cmovnsl %r10d, %eax
addl %r8d, %r8d
jmp 0x6be8
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
leaq 0x4(%rdi), %rcx
movq 0xc384(%rip), %rdx      # 0x12fa0
movl $0x1, %r8d
movq 0xc3b7(%rip), %r9       # 0x12fe0
movq 0xc3c0(%rip), %r10      # 0x12ff0
leaq -0x20(%rsp), %r11
xorl %ebx, %ebx
cmpq $0x5, %rbx
je 0x6c59
movl 0x14(%rdi,%rbx,4), %ebp
xorl (%rdi,%rbx,4), %ebp
xorl 0x28(%rdi,%rbx,4), %ebp
xorl 0x3c(%rdi,%rbx,4), %ebp
xorl 0x50(%rdi,%rbx,4), %ebp
movl %ebp, -0x20(%rsp,%rbx,4)
incq %rbx
jmp 0x6c37
movq %rdi, %rbx
xorl %r14d, %r14d
cmpq $0x5, %r14
je 0x6c9a
movzbl 0x4(%r14,%rdx), %r15d
movzbl 0x1(%rdx,%r14), %r12d
incq %r14
rorxl $0x1f, -0x20(%rsp,%r12,4), %ebp
xorl -0x20(%rsp,%r15,4), %ebp
xorl %r15d, %r15d
cmpq $0x18, %r15
ja 0x6c94
xorl %ebp, (%rbx,%r15,4)
addq $0x5, %r15
jmp 0x6c84
addq $0x4, %rbx
jmp 0x6c5f
xorl %ebx, %ebx
movq %rcx, %r14
cmpq $0x18, %rbx
je 0x6cd6
movl (%r14), %ebp
movzbl (%r9,%rbx), %r14d
movl (%rdi,%r14,4), %r15d
movl %r15d, -0x20(%rsp)
movb (%r10,%rbx), %r15b
shlxl %r15d, %ebp, %r12d
negb %r15b
shrxl %r15d, %ebp, %ebp
xorl %r12d, %ebp
movl %ebp, (%rdi,%r14,4)
incq %rbx
movq %r11, %r14
jmp 0x6c9f
movq %rdi, %rbx
xorl %r14d, %r14d
cmpq $0x19, %r14
jae 0x6d30
vmovups (%rdi,%r14,4), %xmm0
vmovaps %xmm0, -0x20(%rsp)
movl 0x10(%rdi,%r14,4), %ebp
movl %ebp, -0x10(%rsp)
xorl %r15d, %r15d
cmpq $0x5, %r15
je 0x6d26
movzbl 0x1(%rdx,%r15), %r12d
movl -0x20(%rsp,%r12,4), %ebp
movzbl 0x2(%rdx,%r15), %r12d
andnl -0x20(%rsp,%r12,4), %ebp, %ebp
xorl -0x20(%rsp,%r15,4), %ebp
movl %ebp, (%rbx,%r15,4)
incq %r15
jmp 0x6cfa
addq $0x5, %r14
addq $0x14, %rbx
jmp 0x6cdc
xorl %ebx, %ebx
movl %r8d, %r14d
cmpl $0x7f, %r14d
ja 0x6d70
cmpl $0x20, %r14d
ja 0x6d56
movl %eax, %ebp
andb $0x1, %bpl
movzbl %bpl, %ebp
leal -0x1(%r14), %r15d
shlxl %r15d, %ebp, %ebp
xorl %ebp, %ebx
leal (%rax,%rax), %ebp
movzbl %bpl, %r15d
xorb $0x71, %bpl
testb %al, %al
movzbl %bpl, %eax
cmovnsl %r15d, %eax
addl %r14d, %r14d
jmp 0x6d35
xorl %ebx, (%rdi)
decl %esi
jne 0x6c35
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq