// File: /workspace/github_cpp_makefile_star2_O2/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 0x4163
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, %rbx
movq %rcx, %r12
movq %rdx, %r13
movl %r8d, -0x34(%rbp)
movq 0x10(%rbp), %r15
shrl $0x3, %edi
movq %rdi, -0x30(%rbp)
leaq -0x100(%rbp), %rdi
xorl %r14d, %r14d
movl $0xc8, %edx
xorl %esi, %esi
callq 0x20d0
movq -0x30(%rbp), %rsi
testq %r12, %r12
je 0x40e7
movl %r12d, %eax
cmpl %r12d, %esi
movl %r12d, %r14d
cmovbl %esi, %r14d
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x40c8
movb (%r13,%rcx), %dl
xorb %dl, -0x100(%rbp,%rcx)
incq %rcx
jmp 0x40b2
addq %r14, %r13
subq %r14, %r12
cmpl %eax, %esi
ja 0x409e
leaq -0x100(%rbp), %rdi
callq 0x427a
movq -0x30(%rbp), %rsi
xorl %r14d, %r14d
jmp 0x409e
movl %r14d, %eax
movl -0x34(%rbp), %ecx
xorb %cl, -0x100(%rbp,%rax)
leal -0x1(%rsi), %r12d
testb %cl, %cl
jns 0x410d
cmpl %r12d, %r14d
jne 0x410d
leaq -0x100(%rbp), %rdi
callq 0x427a
movl %r12d, %eax
xorb $-0x80, -0x100(%rbp,%rax)
leaq -0x100(%rbp), %r13
movq %r13, %rdi
callq 0x427a
testq %r15, %r15
movq -0x30(%rbp), %rax
je 0x4152
cmpl %r15d, %eax
movl %r15d, %r12d
cmovbl %eax, %r12d
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x20e0
addq %r12, %rbx
subq %r12, %r15
je 0x4127
jmp 0x411f
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq