// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/lakekeyakv2/generic32/KeccakP-800-opt32.c
// Function: KeccakP800_ExtractAndAddBytes
void KeccakP800_ExtractAndAddBytes(const void *argState, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
{
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
#ifdef KeccakP800_useLaneComplementing
    unsigned int sizeLeft = length;
    unsigned int lanePosition = offset/4;
    unsigned int offsetInLane = offset%4;
    const unsigned char *curInput = input;
    unsigned char *curOutput = output;
    const UINT32 *state = (const UINT32*)argState;
    const UINT32 *pLaneComplement;

    state += lanePosition;
    pLaneComplement = KeccakP800LaneComplement + lanePosition;
    if ((sizeLeft > 0) && (offsetInLane != 0)) {
        unsigned int bytesInLane = 4 - offsetInLane;
        UINT32  lane = (*state++ ^ *pLaneComplement++) >> (offsetInLane * 8);
        if (bytesInLane > sizeLeft)
            bytesInLane = sizeLeft;
        sizeLeft -= bytesInLane;
        do {
            *curOutput++ = (*curInput++) ^ (unsigned char)lane;
            lane >>= 8;
        }
        while ( --bytesInLane != 0);
    }

    while(sizeLeft >= 4) {
        WRITE32_UNALIGNED( curOutput, READ32_UNALIGNED( curInput ) ^ *state++ ^ *pLaneComplement++ );
        sizeLeft -= 4;
        curInput += 4;
        curOutput += 4;
    }

    if (sizeLeft > 0) {
        UINT32  lane = *state ^ *pLaneComplement;
        do {
            *curOutput++ = (*curInput++) ^ (unsigned char)lane;
            lane >>= 8;
        }
        while ( --sizeLeft != 0 );
    }
#else
    unsigned int sizeLeft = length;
    unsigned int lanePosition = offset/4;
    unsigned int offsetInLane = offset%4;
    const unsigned char *curInput = input;
    unsigned char *curOutput = output;
    const UINT32 *state = (const UINT32*)argState;

    state += lanePosition;
    if ((sizeLeft > 0) && (offsetInLane != 0)) {
        unsigned int bytesInLane = 4 - offsetInLane;
        UINT32  lane = *state++ >> (offsetInLane * 8);
        if (bytesInLane > sizeLeft)
            bytesInLane = sizeLeft;
        sizeLeft -= bytesInLane;
        do {
            *curOutput++ = (*curInput++) ^ (unsigned char)lane;
            lane >>= 8;
        }
        while ( --bytesInLane != 0);
    }

    while(sizeLeft >= 4) {
        WRITE32_UNALIGNED( curOutput, READ32_UNALIGNED( curInput ) ^ *state++ );
        sizeLeft -= 4;
        curInput += 4;
        curOutput += 4;
    }

    if (sizeLeft > 0) {
        UINT32  lane = *state;
        do {
            *curOutput++ = (*curInput++) ^ (unsigned char)lane;
            lane >>= 8;
        }
        while ( --sizeLeft != 0 );
    }
#endif
#else
#error "Not yet implemented"
#endif
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movl %ecx, -0x1c(%rsp)
movl %r8d, -0x20(%rsp)
movl -0x20(%rsp), %eax
movl %eax, -0x24(%rsp)
movl -0x1c(%rsp), %eax
shrl $0x2, %eax
movl %eax, -0x28(%rsp)
movl -0x1c(%rsp), %eax
andl $0x3, %eax
movl %eax, -0x2c(%rsp)
movq -0x10(%rsp), %rax
movq %rax, -0x38(%rsp)
movq -0x18(%rsp), %rax
movq %rax, -0x40(%rsp)
movq -0x8(%rsp), %rax
movq %rax, -0x48(%rsp)
movl -0x28(%rsp), %ecx
movq -0x48(%rsp), %rax
movl %ecx, %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rsp)
cmpl $0x0, -0x24(%rsp)
jbe 0xf66d
cmpl $0x0, -0x2c(%rsp)
je 0xf66d
movl $0x4, %eax
subl -0x2c(%rsp), %eax
movl %eax, -0x4c(%rsp)
movq -0x48(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x48(%rsp)
movl (%rax), %eax
movl -0x2c(%rsp), %ecx
shll $0x3, %ecx
shrl %cl, %eax
movl %eax, -0x50(%rsp)
movl -0x4c(%rsp), %eax
cmpl -0x24(%rsp), %eax
jbe 0xf610
movl -0x24(%rsp), %eax
movl %eax, -0x4c(%rsp)
movl -0x4c(%rsp), %ecx
movl -0x24(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rsp)
movq -0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rsp)
movzbl (%rax), %eax
movl -0x50(%rsp), %ecx
movzbl %cl, %ecx
xorl %ecx, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
movl -0x50(%rsp), %eax
shrl $0x8, %eax
movl %eax, -0x50(%rsp)
movl -0x4c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rsp)
cmpl $0x0, %eax
jne 0xf61e
jmp 0xf66d
jmp 0xf66f
cmpl $0x4, -0x24(%rsp)
jb 0xf6c0
movq -0x38(%rsp), %rax
movl (%rax), %ecx
movq -0x48(%rsp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq %rdx, -0x48(%rsp)
xorl (%rax), %ecx
movq -0x40(%rsp), %rax
movl %ecx, (%rax)
movl -0x24(%rsp), %eax
subl $0x4, %eax
movl %eax, -0x24(%rsp)
movq -0x38(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rsp)
movq -0x40(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rsp)
jmp 0xf66f
cmpl $0x0, -0x24(%rsp)
jbe 0xf721
movq -0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rsp)
movq -0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rsp)
movzbl (%rax), %eax
movl -0x54(%rsp), %ecx
movzbl %cl, %ecx
xorl %ecx, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rsp)
movb %cl, (%rax)
movl -0x54(%rsp), %eax
shrl $0x8, %eax
movl %eax, -0x54(%rsp)
movl -0x24(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rsp)
cmpl $0x0, %eax
jne 0xf6d2
jmp 0xf721
retq
nopw %cs:(%rax,%rax)