// File: /workspace/github_cpp_makefile_star2_O1/adamjanovsky[P]PA193_test_parser_monero/src/keccak/Keccak-readable-and-compact.c
// Function: Keccak
void Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input, unsigned long long int inputByteLen, unsigned char delimitedSuffix, unsigned char *output, unsigned long long int outputByteLen)
{
    UINT8 state[200];
    unsigned int rateInBytes = rate/8;
    unsigned int blockSize = 0;
    unsigned int i;
    
    if (((rate + capacity) != 1600) || ((rate % 8) != 0))
        return;
    
    /* === Initialize the state === */
    memset(state, 0, sizeof(state));
    
    /* === Absorb all the input blocks === */
    while(inputByteLen > 0) {
        blockSize = MIN((unsigned int)inputByteLen, rateInBytes);
        for(i=0; i<blockSize; i++)
            state[i] ^= input[i];
        input += blockSize;
        inputByteLen -= blockSize;
        
        if (blockSize == rateInBytes) {
            KeccakF1600_StatePermute(state);
            blockSize = 0;
        }
    }
    
    /* === Do the padding and switch to the squeezing phase === */
    /* Absorb the last few bits and add the first bit of padding (which coincides with the delimiter in delimitedSuffix) */
    state[blockSize] ^= delimitedSuffix;
    /* If the first bit of padding is at position rate-1, we need a whole new block for the second bit of padding */
    if (((delimitedSuffix & 0x80) != 0) && (blockSize == (rateInBytes-1)))
        KeccakF1600_StatePermute(state);
    /* Add the second bit of padding */
    state[rateInBytes-1] ^= 0x80;
    /* Switch to the squeezing phase */
    KeccakF1600_StatePermute(state);
    
    /* === Squeeze out all the output blocks === */
    while(outputByteLen > 0) {
        blockSize = MIN((unsigned int)outputByteLen, rateInBytes);
        memcpy(output, state, blockSize);
        output += blockSize;
        outputByteLen -= blockSize;
        
        if (outputByteLen > 0)
            KeccakF1600_StatePermute(state);
    }
}

// Assembly:
addl %edi, %esi
xorl $0x640, %esi            # imm = 0x640
movl %edi, %eax
andl $0x7, %eax
orl %esi, %eax
jne 0x4a1c
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rcx, %r12
movq %rdx, %r13
movl %edi, %r14d
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
shrl $0x3, %r14d
leaq -0x100(%rbp), %rdi
xorl %r15d, %r15d
movl $0xc8, %edx
xorl %esi, %esi
callq 0x20c0
testq %r12, %r12
je 0x4972
cmpl %r12d, %r14d
movl %r12d, %r15d
cmovbl %r14d, %r15d
movl %r15d, %ebx
testl %r15d, %r15d
je 0x4956
xorl %eax, %eax
movb (%r13,%rax), %cl
xorb %cl, -0x100(%rbp,%rax)
incq %rax
cmpq %rax, %rbx
jne 0x4942
cmpl %r12d, %r14d
ja 0x496a
leaq -0x100(%rbp), %rdi
callq 0x4b3d
xorl %r15d, %r15d
addq %rbx, %r13
subq %rbx, %r12
jne 0x492e
movl %r15d, %eax
movl -0x2c(%rbp), %ecx
xorb %cl, -0x100(%rbp,%rax)
movq 0x10(%rbp), %r13
leal -0x1(%r14), %ebx
testb %cl, %cl
jns 0x499c
cmpl %ebx, %r15d
jne 0x499c
leaq -0x100(%rbp), %rdi
callq 0x4b3d
movl %ebx, %eax
xorb $-0x80, -0x100(%rbp,%rax)
leaq -0x100(%rbp), %rdi
callq 0x4b3d
testq %r13, %r13
movq -0x38(%rbp), %rbx
je 0x4a0b
cmpl %r13d, %r14d
movl %r13d, %r15d
cmovbl %r14d, %r15d
leaq -0x100(%rbp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x20f0
subq %r15, %r13
je 0x4a0b
leaq -0x100(%rbp), %r12
addq %r15, %rbx
movq %r12, %rdi
callq 0x4b3d
cmpl %r13d, %r14d
movl %r13d, %r15d
cmovbl %r14d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x20f0
subq %r15, %r13
jne 0x49e3
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq