// File: /workspace/github_cpp_makefile_star2_O3/occivink[P]pyct/monocypher.cpp
// Function: extended_hash(unsigned char*, unsigned int, unsigned char const*, unsigned int)
static void extended_hash(u8       *digest, u32 digest_size,
                          const u8 *input , u32 input_size)
{
    crypto_blake2b_ctx ctx;
    crypto_blake2b_general_init(&ctx, MIN(digest_size, 64), 0, 0);
    blake_update_32            (&ctx, digest_size);
    crypto_blake2b_update      (&ctx, input, input_size);
    crypto_blake2b_final       (&ctx, digest);

    if (digest_size > 64) {
        // the conversion to u64 avoids integer overflow on
        // ludicrously big hash sizes.
        u32 r   = (u32)(((u64)digest_size + 31) >> 5) - 2;
        u32 i   =  1;
        u32 in  =  0;
        u32 out = 32;
        while (i < r) {
            // Input and output overlap. This is intentional
            crypto_blake2b(digest + out, digest + in, 64);
            i   +=  1;
            in  += 32;
            out += 32;
        }
        crypto_blake2b_general(digest + out, digest_size - (32 * r),
                               0, 0, // no key
                               digest + in , 64);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movl %ecx, %ebp
movq %rdx, %r15
movl %esi, %ebx
movq %rdi, %r14
movabsq $0x6a09e667f2bdc908, %r13 # imm = 0x6A09E667F2BDC908
cmpl $0x40, %esi
movl $0x40, %eax
cmovbl %esi, %eax
movaps 0x8027(%rip), %xmm0     # 0xd0c0
leaq 0xf0(%rsp), %r12
movaps %xmm0, (%r12)
movaps 0x8043(%rip), %xmm0     # 0xd0f0
movaps %xmm0, 0x30(%r12)
movaps 0x8026(%rip), %xmm0     # 0xd0e0
movaps %xmm0, 0x20(%r12)
movaps 0x8009(%rip), %xmm0     # 0xd0d0
movaps %xmm0, 0x10(%r12)
movq %rax, %rcx
xorq %r13, %rcx
movq %rcx, (%r12)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r12)
movq %rax, 0xd8(%r12)
movq $0x0, 0xd0(%r12)
movq %r12, %rdi
callq 0x503b
movl %ebp, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2f4e
movq %r12, %rdi
movq %r14, %rsi
callq 0x47a9
cmpl $0x41, %ebx
jb 0x5292
movl %ebx, %ebp
addq $0x1f, %rbp
shrq $0x5, %rbp
leal -0x2(%rbp), %eax
cmpl $0x2, %eax
jb 0x520f
movl %eax, 0x4(%rsp)
movq %rbx, 0x8(%rsp)
addl $-0x3, %ebp
movl $0x20, %r15d
leaq 0x40(%r13), %rbx
leaq 0x10(%rsp), %r12
movaps 0x7f6b(%rip), %xmm0     # 0xd0c0
movaps 0x7f94(%rip), %xmm1     # 0xd0f0
movaps 0x7f7d(%rip), %xmm2     # 0xd0e0
movaps 0x7f66(%rip), %xmm3     # 0xd0d0
leal -0x20(%r15), %esi
movl %r15d, %r13d
addq %r14, %r13
addq %r14, %rsi
movaps %xmm0, 0x10(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm2, 0x30(%rsp)
movaps %xmm3, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x40, 0xe8(%rsp)
movq $0x0, 0xe0(%rsp)
movl $0x40, %edx
movq %r12, %rdi
callq 0x2f4e
movq %r12, %rdi
movq %r13, %rsi
callq 0x47a9
movaps 0x7efe(%rip), %xmm3     # 0xd0d0
movaps 0x7f07(%rip), %xmm2     # 0xd0e0
movaps 0x7f10(%rip), %xmm1     # 0xd0f0
movaps 0x7ed9(%rip), %xmm0     # 0xd0c0
addl $0x20, %r15d
decl %ebp
jne 0x516a
movl %r15d, %r12d
addl $-0x20, %r15d
movq 0x8(%rsp), %rbx
movabsq $0x6a09e667f2bdc908, %r13 # imm = 0x6A09E667F2BDC908
movl 0x4(%rsp), %eax
jmp 0x5234
movl $0x20, %r12d
xorl %r15d, %r15d
movaps 0x7ea1(%rip), %xmm0     # 0xd0c0
movaps 0x7eca(%rip), %xmm1     # 0xd0f0
movaps 0x7eb3(%rip), %xmm2     # 0xd0e0
movaps 0x7e9c(%rip), %xmm3     # 0xd0d0
addq %r14, %r12
shll $0x5, %eax
subl %eax, %ebx
addq %r14, %r15
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
movaps %xmm1, 0x30(%r14)
movaps %xmm2, 0x20(%r14)
movaps %xmm3, 0x10(%r14)
xorq %rbx, %r13
movq %r13, (%r14)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r14)
movq %rbx, 0xd8(%r14)
movq $0x0, 0xd0(%r14)
movl $0x40, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2f4e
movq %r14, %rdi
movq %r12, %rsi
callq 0x47a9
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq