// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/lunarkeyakv2/Haswell/KeccakP-1600-AVX2.cpp
// Function: KeccakP1600_AddBytes
void KeccakP1600_AddBytes(void *state, const UINT8 *data, size_t offset, size_t length)
//*****************************************************************************
{
    keccak_state_t  &s = *(keccak_state_t *)state;
    UINT64      *d = (UINT64 *)data;
    UINT8       *t1, *d1;
    UINT64      t[25];
    UINT64      *t0;
    ptrdiff_t   lane_n = length / sizeof(UINT64);
    ptrdiff_t   byte_n = length % sizeof(UINT64);
    ptrdiff_t   i;

    KeccakP1600_ExtractBytes(state, (UINT8 *)t, 0, sizeof(t));

/*
    // "trailingBits + 256" is passed as offset to do "state ^ trailingBits".
    if (offset >= 256)
    {
        if (length < sizeof(t))
            ((UINT8 *)t)[length] ^= (UINT8)offset;
        offset = 0;
    }
*/

    t0 = (UINT64 *)((UINT8 *)t + offset);

    for (i = 0; i < lane_n; i++)
        t0[i] ^= d[i];

    if (byte_n)
    {
        t1 = (UINT8 *)(t0 + i);
        d1 = (UINT8 *)(d + i);

        for (i = 0; i < byte_n; i++)
            t1[i] ^= d1[i];
    }

    s.a0 = LOAD(t + 0*5);
    s.a1 = LOAD(t + 1*5);
    s.a2 = LOAD(t + 2*5);
    s.a3 = LOAD(t + 3*5);
    s.a4 = LOAD(t + 4*5);
    s.c4 = SET(t[0*5 + 4], t[1*5 + 4], t[2*5 + 4], t[3*5 + 4]);
    s.a44 = _mm256_set1_epi64x(t[4*5 + 4]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
andq $-0x20, %rsp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, 0x128(%rsp)
movq %rsi, 0x120(%rsp)
movq %rdx, 0x118(%rsp)
movq %rcx, 0x110(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x110(%rsp), %rax
shrq $0x3, %rax
movq %rax, 0x10(%rsp)
movq 0x110(%rsp), %rax
andq $0x7, %rax
movq %rax, 0x8(%rsp)
movq 0x128(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0xc8, %ecx
callq 0x5060
leaq 0x20(%rsp), %rax
addq 0x118(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, (%rsp)
movq (%rsp), %rax
cmpq 0x10(%rsp), %rax
jge 0x67a0
movq 0x100(%rsp), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
xorq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
jmp 0x6766
cmpq $0x0, 0x8(%rsp)
je 0x6823
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xf8(%rsp)
movq 0x100(%rsp), %rax
movq (%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xf0(%rsp)
movq $0x0, (%rsp)
movq (%rsp), %rax
cmpq 0x8(%rsp), %rax
jge 0x6821
movq 0xf0(%rsp), %rax
movq (%rsp), %rcx
movzbl (%rax,%rcx), %esi
movq 0xf8(%rsp), %rax
movq (%rsp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
jmp 0x67e3
jmp 0x6823
leaq 0x20(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rax
vmovdqu (%rax), %ymm0
movq 0x108(%rsp), %rax
vmovdqa %ymm0, (%rax)
leaq 0x48(%rsp), %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
vmovdqu (%rax), %ymm0
movq 0x108(%rsp), %rax
vmovdqa %ymm0, 0x20(%rax)
leaq 0x70(%rsp), %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
vmovdqu (%rax), %ymm0
movq 0x108(%rsp), %rax
vmovdqa %ymm0, 0x40(%rax)
leaq 0x98(%rsp), %rax
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rax
vmovdqu (%rax), %ymm0
movq 0x108(%rsp), %rax
vmovdqa %ymm0, 0x60(%rax)
leaq 0xc0(%rsp), %rax
movq %rax, 0x150(%rsp)
movq 0x150(%rsp), %rax
vmovdqu (%rax), %ymm0
movq 0x108(%rsp), %rax
vmovdqa %ymm0, 0x80(%rax)
movq 0x40(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0xb8(%rsp), %rax
movq %rsi, 0x148(%rsp)
movq %rdx, 0x140(%rsp)
movq %rcx, 0x138(%rsp)
movq %rax, 0x130(%rsp)
movq 0x130(%rsp), %rsi
movq 0x138(%rsp), %rdx
movq 0x140(%rsp), %rcx
movq 0x148(%rsp), %rax
movq %rsi, 0x208(%rsp)
movq %rdx, 0x200(%rsp)
movq %rcx, 0x1f8(%rsp)
movq %rax, 0x1f0(%rsp)
vmovq 0x1f8(%rsp), %xmm1
vmovq 0x1f0(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovq 0x208(%rsp), %xmm2
vmovq 0x200(%rsp), %xmm1
vpunpcklqdq %xmm2, %xmm1, %xmm1 # xmm1 = xmm1[0],xmm2[0]
vmovdqa %xmm1, 0x1d0(%rsp)
vmovdqa %xmm0, 0x1c0(%rsp)
vmovdqa 0x1c0(%rsp), %ymm0
movq 0x108(%rsp), %rax
vmovdqa %ymm0, 0xa0(%rax)
movq 0xe0(%rsp), %rax
movq %rax, 0x178(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq %rax, 0x1b0(%rsp)
movq %rax, 0x1a8(%rsp)
movq %rax, 0x1a0(%rsp)
vmovq 0x1b8(%rsp), %xmm1
vmovq 0x1b0(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm1 # xmm1 = xmm0[0],xmm1[0]
vmovq 0x1a8(%rsp), %xmm2
vmovq 0x1a0(%rsp), %xmm0
vpunpcklqdq %xmm2, %xmm0, %xmm2 # xmm2 = xmm0[0],xmm2[0]
vmovaps %xmm2, %xmm0
vinserti128 $0x1, %xmm1, %ymm0, %ymm0
vmovdqa %ymm0, 0x180(%rsp)
vmovdqa 0x180(%rsp), %ymm0
movq 0x108(%rsp), %rax
vmovdqa %ymm0, 0xc0(%rax)
movq %rbp, %rsp
popq %rbp
vzeroupper
retq
nopw %cs:(%rax,%rax)