// File: /workspace/github_c_makefile_star2_O3/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:
movb $0x1, %al
cmpl $0x16, %esi
je 0x6be8
movl $0x16, %ecx
subl %esi, %ecx
movb $0x1, %al
movl $0x1, %edx
leal (%rax,%rax), %r8d
movzbl %r8b, %r9d
xorb $0x71, %r8b
testb %al, %al
movzbl %r8b, %eax
cmovnsl %r9d, %eax
leal (%rdx,%rdx), %r8d
cmpl $0x40, %edx
movl %r8d, %edx
jb 0x6bc2
decl %ecx
jne 0x6bbd
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq 0x14(%rdi), %rcx
movq %rcx, -0x8(%rsp)
leaq 0x28(%rdi), %rdx
leaq 0x3c(%rdi), %r8
leaq 0x50(%rdi), %r9
movb $0x1f, %r10b
kmovd %r10d, %k1
movq 0xc38a(%rip), %r10      # 0x12fa0
movq 0xc3c3(%rip), %r11      # 0x12fe0
movq 0xc3cc(%rip), %rbx      # 0x12ff0
vmovdqu32 (%rdi), %ymm0 {%k1} {z}
movq -0x8(%rsp), %rcx
vmovdqu32 (%rcx), %ymm1 {%k1} {z}
vmovdqu32 (%rdx), %ymm2 {%k1} {z}
vpternlogd $0x96, %ymm0, %ymm1, %ymm2
vmovdqu32 (%r8), %ymm0 {%k1} {z}
vmovdqu32 (%r9), %ymm1 {%k1} {z}
vpternlogd $0x96, %ymm0, %ymm2, %ymm1
vmovdqu32 %ymm1, -0x28(%rsp) {%k1}
movq %rdi, %r14
xorl %r15d, %r15d
movzbl 0x4(%r15,%r10), %r12d
movzbl 0x1(%r10,%r15), %r13d
incq %r15
rorxl $0x1f, -0x28(%rsp,%r13,4), %ebp
xorl -0x28(%rsp,%r12,4), %ebp
movq $-0x5, %r12
xorl %ebp, 0x14(%r14,%r12,4)
addq $0x5, %r12
cmpq $0x14, %r12
jb 0x6c89
addq $0x4, %r14
cmpq $0x5, %r15
jne 0x6c66
movl 0x4(%rdi), %ebp
xorl %r14d, %r14d
movzbl (%r11,%r14), %r15d
movb (%rbx,%r14), %r12b
shlxl %r12d, %ebp, %r13d
negb %r12b
shrxl %r12d, %ebp, %ebp
movl (%rdi,%r15,4), %r12d
xorl %r13d, %ebp
movl %ebp, (%rdi,%r15,4)
incq %r14
movl %r12d, %ebp
cmpq $0x18, %r14
jne 0x6ca8
movq %rdi, %r14
xorl %r15d, %r15d
vmovdqu (%rdi,%r15,4), %xmm0
movl 0x4(%rdi,%r15,4), %ebp
vmovdqa %xmm0, -0x28(%rsp)
movl 0x10(%rdi,%r15,4), %r12d
movl %r12d, -0x18(%rsp)
xorl %r12d, %r12d
movzbl 0x2(%r10,%r12), %r13d
movl -0x28(%rsp,%r13,4), %r13d
andnl %r13d, %ebp, %ebp
xorl -0x28(%rsp,%r12,4), %ebp
movl %ebp, (%r14,%r12,4)
leaq 0x1(%r12), %rcx
movl %r13d, %ebp
movq %rcx, %r12
cmpq $0x5, %rcx
jne 0x6cf9
leaq 0x5(%r15), %rcx
addq $0x14, %r14
cmpq $0x14, %r15
movq %rcx, %r15
jb 0x6cdb
movl $0x1, %r14d
xorl %ebp, %ebp
cmpl $0x20, %r14d
ja 0x6d55
movl %eax, %ecx
andb $0x1, %cl
movzbl %cl, %ecx
leal -0x1(%r14), %r15d
shlxl %r15d, %ecx, %ecx
xorl %ecx, %ebp
leal (%rax,%rax), %ecx
movzbl %cl, %r15d
xorb $0x71, %cl
testb %al, %al
movzbl %cl, %eax
cmovnsl %r15d, %eax
leal (%r14,%r14), %ecx
cmpl $0x40, %r14d
movl %ecx, %r14d
jb 0x6d3c
xorl %ebp, (%rdi)
decl %esi
jne 0x6c24
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq