// File: /workspace/github_cpp_makefile_star2_O3/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 0x4a30
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 0x4982
cmpl %r12d, %r14d
movl %r12d, %r15d
cmovbl %r14d, %r15d
testl %r15d, %r15d
je 0x4958
movl %r15d, %ebx
xorl %eax, %eax
movb (%r13,%rax), %cl
xorb %cl, -0x100(%rbp,%rax)
incq %rax
cmpq %rax, %rbx
jne 0x4942
jmp 0x495a
xorl %ebx, %ebx
cmpl %r12d, %r14d
ja 0x496e
leaq -0x100(%rbp), %rdi
callq 0x4b51
xorl %r15d, %r15d
addq %rbx, %r13
subq %rbx, %r12
jne 0x492e
movl %r15d, %eax
movb -0x100(%rbp,%rax), %al
jmp 0x4984
xorl %eax, %eax
movq 0x10(%rbp), %r13
movl %r15d, %ecx
movl -0x2c(%rbp), %edx
xorb %dl, %al
movb %al, -0x100(%rbp,%rcx)
leal -0x1(%r14), %ebx
testb %dl, %dl
jns 0x49b0
cmpl %ebx, %r15d
jne 0x49b0
leaq -0x100(%rbp), %rdi
callq 0x4b51
movl %ebx, %eax
xorb $-0x80, -0x100(%rbp,%rax)
leaq -0x100(%rbp), %rdi
callq 0x4b51
testq %r13, %r13
movq -0x38(%rbp), %rbx
je 0x4a1f
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 0x4a1f
leaq -0x100(%rbp), %r12
addq %r15, %rbx
movq %r12, %rdi
callq 0x4b51
cmpl %r13d, %r14d
movl %r13d, %r15d
cmovbl %r14d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x20f0
subq %r15, %r13
jne 0x49f7
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq