// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/hs1sivv2/ref/encrypt.c
// Function: prf_hash2
void prf_hash2(uint64_t *h, uint32_t *in, unsigned inbytes, uint32_t *nhkey,
               uint64_t *polykey, uint64_t *asukey) {
    uint64_t s0 = 1, s1 = 1;
    unsigned i=0, j;

    /* Hash full blocks of HS1_SIV_NH_LEN bytes */
    while (inbytes >= HS1_SIV_NH_LEN) {
        uint64_t a0 = 0, a1 = 0;
        for (i=0;i<HS1_SIV_NH_LEN/4;i+=8) {
            a0 += (uint64_t)(read32le(in+i+0) + nhkey[i+0]) *
                            (read32le(in+i+2) + nhkey[i+2]);
            a0 += (uint64_t)(read32le(in+i+1) + nhkey[i+1]) *
                            (read32le(in+i+3) + nhkey[i+3]);
            a1 += (uint64_t)(read32le(in+i+0) + nhkey[i+4]) *
                            (read32le(in+i+2) + nhkey[i+6]);
            a1 += (uint64_t)(read32le(in+i+1) + nhkey[i+5]) *
                            (read32le(in+i+3) + nhkey[i+7]);
            a0 += (uint64_t)(read32le(in+i+4) + nhkey[i+4]) *
                            (read32le(in+i+6) + nhkey[i+6]);
            a0 += (uint64_t)(read32le(in+i+5) + nhkey[i+5]) *
                            (read32le(in+i+7) + nhkey[i+7]);
            a1 += (uint64_t)(read32le(in+i+4) + nhkey[i+8]) *
                            (read32le(in+i+6) + nhkey[i+10]);
            a1 += (uint64_t)(read32le(in+i+5) + nhkey[i+9]) *
                            (read32le(in+i+7) + nhkey[i+11]);
        }
        s0 = poly_step(s0, a0&m60, polykey[0]);
        s1 = poly_step(s1, a1&m60, polykey[1]);
        inbytes -= HS1_SIV_NH_LEN;
        in += HS1_SIV_NH_LEN/4;
    }
    /* If partial block remains, hash it */
    i=0;
    if (inbytes != 0) {
        uint64_t a0 = 0, a1 = 0;
        while (inbytes >= 16) {
            a0 += (uint64_t)(read32le(in+i+0) + nhkey[i+0]) *
                            (read32le(in+i+2) + nhkey[i+2]);
            a0 += (uint64_t)(read32le(in+i+1) + nhkey[i+1]) *
                            (read32le(in+i+3) + nhkey[i+3]);
            a1 += (uint64_t)(read32le(in+i+0) + nhkey[i+4]) *
                            (read32le(in+i+2) + nhkey[i+6]);
            a1 += (uint64_t)(read32le(in+i+1) + nhkey[i+5]) *
                            (read32le(in+i+3) + nhkey[i+7]);
            i += 4; inbytes -= 16;
        }
        if (inbytes) {
            uint32_t tail[4] = {0,0,0,0};
            for (j=0;j<inbytes;j++)
                ((unsigned char *)tail)[j] = ((unsigned char *)(in+i))[j];
            a0 += (uint64_t)(read32le(tail+0) + nhkey[i+0]) *
                            (read32le(tail+2) + nhkey[i+2]);
            a0 += (uint64_t)(read32le(tail+1) + nhkey[i+1]) *
                            (read32le(tail+3) + nhkey[i+3]);
            a1 += (uint64_t)(read32le(tail+0) + nhkey[i+4]) *
                            (read32le(tail+2) + nhkey[i+6]);
            a1 += (uint64_t)(read32le(tail+1) + nhkey[i+5]) *
                            (read32le(tail+3) + nhkey[i+7]);
            a0 += inbytes;
            a1 += inbytes;
        }
        s0 = poly_step(s0, a0&m60, polykey[0]);
        s1 = poly_step(s1, a1&m60, polykey[1]);
    }
    s0 = poly_finalize(s0);
    s1 = poly_finalize(s1);
    #if (HS1_SIV_HASH_RNDS > 4)
    write64le(h, (uint64_t)asu_hash(s1, asukey+3) << 32 | asu_hash(s0, asukey));
    #else
    (void)asukey;
    write64le(h,s0);
    write64le(h+1,s1);
    #endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, -0x28(%rsp)
movabsq $0x1fffffffffffffff, %r13 # imm = 0x1FFFFFFFFFFFFFFF
movl $0x1, %ebp
cmpl $0x40, %edx
movq %r8, -0x30(%rsp)
jb 0x15ed
movq (%r8), %rax
movq %rax, -0x18(%rsp)
movq 0x8(%r8), %rax
movq %rax, -0x20(%rsp)
movl (%rcx), %eax
movl %eax, -0x4c(%rsp)
movl $0x1, %r10d
movq %rdx, -0x10(%rsp)
movq %r10, -0x8(%rsp)
movq %rbp, -0x58(%rsp)
movb $0x1, %dl
movl -0x4c(%rsp), %eax
movl %eax, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %r15d, %r15d
movl (%rsi,%r13,4), %eax
movl 0x4(%rsi,%r13,4), %ebp
addl %eax, %r14d
movl 0x8(%rsi,%r13,4), %edi
movl 0x8(%rcx,%r13,4), %r11d
addl %edi, %r11d
imulq %r14, %r11
addq %r15, %r11
movl 0x4(%rcx,%r13,4), %r10d
addl %ebp, %r10d
movl 0xc(%rsi,%r13,4), %r8d
movl 0xc(%rcx,%r13,4), %r9d
addl %r8d, %r9d
imulq %r10, %r9
movl 0x10(%rcx,%r13,4), %r10d
movl 0x14(%rcx,%r13,4), %r14d
addl %r10d, %eax
movl 0x18(%rcx,%r13,4), %ebx
addl %ebx, %edi
imulq %rax, %rdi
addq %r12, %rdi
addl %r14d, %ebp
movl 0x1c(%rcx,%r13,4), %r15d
addl %r15d, %r8d
imulq %rbp, %r8
movl 0x10(%rsi,%r13,4), %eax
addl %eax, %r10d
movl 0x18(%rsi,%r13,4), %ebp
addl %ebp, %ebx
imulq %r10, %rbx
addq %r9, %rbx
addq %r11, %rbx
movl 0x14(%rsi,%r13,4), %r9d
addl %r9d, %r14d
movl 0x1c(%rsi,%r13,4), %r12d
addl %r12d, %r15d
imulq %r14, %r15
addq %rbx, %r15
movl 0x20(%rcx,%r13,4), %r14d
addl %r14d, %eax
addl 0x28(%rcx,%r13,4), %ebp
imulq %rax, %rbp
addq %r8, %rbp
addl 0x24(%rcx,%r13,4), %r9d
addl 0x2c(%rcx,%r13,4), %r12d
addq %rdi, %rbp
imulq %r9, %r12
addq %rbp, %r12
movl $0x8, %r13d
testb $0x1, %dl
movl $0x0, %edx
jne 0x14b3
movabsq $0xfffffffffffffff, %rdi # imm = 0xFFFFFFFFFFFFFFF
andq %rdi, %r15
movq -0x18(%rsp), %rdx
movq -0x58(%rsp), %rbp
mulxq %rbp, %rbp, %rax
shldq $0x3, %rbp, %rax
movabsq $0x1fffffffffffffff, %r13 # imm = 0x1FFFFFFFFFFFFFFF
andq %r13, %rbp
addq %rax, %rbp
addq %r15, %rbp
andq %rdi, %r12
movq -0x20(%rsp), %rdx
movq -0x8(%rsp), %r10
mulxq %r10, %r10, %rax
shldq $0x3, %r10, %rax
andq %r13, %r10
addq %rax, %r10
addq %r12, %r10
movq -0x10(%rsp), %rdx
addl $-0x40, %edx
addq $0x40, %rsi
cmpl $0x3f, %edx
ja 0x1492
jmp 0x15f3
movl $0x1, %r10d
testl %edx, %edx
je 0x176f
cmpl $0x10, %edx
jb 0x1697
leal -0x10(%rdx), %eax
shrl $0x2, %eax
andl $-0x4, %eax
movl %eax, -0x58(%rsp)
movl (%rcx), %r8d
xorl %edi, %edi
xorl %r11d, %r11d
xorl %ebx, %ebx
movl (%rsi,%rdi), %eax
movl 0x4(%rsi,%rdi), %r14d
addl %eax, %r8d
movl 0x8(%rsi,%rdi), %r15d
movl 0x8(%rcx,%rdi), %r12d
addl %r15d, %r12d
imulq %r8, %r12
addq %rbx, %r12
movl 0x4(%rcx,%rdi), %r9d
addl %r14d, %r9d
movl 0x10(%rcx,%rdi), %r8d
addl %r8d, %eax
addl 0x18(%rcx,%rdi), %r15d
imulq %rax, %r15
addq %r11, %r15
movl 0xc(%rsi,%rdi), %r11d
movl 0xc(%rcx,%rdi), %ebx
addl %r11d, %ebx
imulq %r9, %rbx
addl 0x14(%rcx,%rdi), %r14d
addl 0x1c(%rcx,%rdi), %r11d
addq %r12, %rbx
imulq %r14, %r11
addq %r15, %r11
addl $-0x10, %edx
addq $0x10, %rdi
cmpl $0xf, %edx
ja 0x161b
testl %edx, %edx
je 0x172d
movl -0x58(%rsp), %eax
addl $0x4, %eax
jmp 0x169e
xorl %r11d, %r11d
xorl %ebx, %ebx
xorl %eax, %eax
movq %r10, %r12
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, -0x48(%rsp)
movl %eax, %edi
leaq (%rsi,%rdi,4), %rax
movl %edx, %edx
xorl %esi, %esi
movb (%rax,%rsi), %r8b
movb %r8b, -0x48(%rsp,%rsi)
incq %rsi
cmpq %rsi, %rdx
jne 0x16b5
movl -0x48(%rsp), %r10d
movl -0x44(%rsp), %r8d
movl (%rcx,%rdi,4), %eax
addl %r10d, %eax
movl -0x40(%rsp), %esi
movl 0x8(%rcx,%rdi,4), %r9d
addl %esi, %r9d
imulq %rax, %r9
movl 0x4(%rcx,%rdi,4), %r14d
addl %r8d, %r14d
movl -0x3c(%rsp), %eax
movl 0xc(%rcx,%rdi,4), %r15d
addl %eax, %r15d
imulq %r14, %r15
addl 0x10(%rcx,%rdi,4), %r10d
addl 0x18(%rcx,%rdi,4), %esi
imulq %r10, %rsi
addl 0x14(%rcx,%rdi,4), %r8d
addl 0x1c(%rcx,%rdi,4), %eax
imulq %r8, %rax
addq %rdx, %rbx
addq %r9, %rbx
addq %r15, %rbx
addq %rdx, %r11
addq %rsi, %r11
addq %rax, %r11
movq %r12, %r10
movabsq $0xfffffffffffffff, %rsi # imm = 0xFFFFFFFFFFFFFFF
andq %rsi, %rbx
movq %rbp, %rdx
movq -0x30(%rsp), %rcx
mulxq (%rcx), %rax, %rbp
shldq $0x3, %rax, %rbp
andq %r13, %rax
addq %rbx, %rbp
movq %r10, %rdx
mulxq 0x8(%rcx), %rcx, %r10
addq %rax, %rbp
andq %rsi, %r11
shldq $0x3, %rcx, %r10
andq %r13, %rcx
addq %r11, %r10
addq %rcx, %r10
movq %rbp, %rax
andq %r13, %rax
shrq $0x3d, %rbp
addq %rax, %rbp
xorl %eax, %eax
cmpq %r13, %rbp
cmoveq %rax, %rbp
movq %r10, %rcx
andq %r13, %rcx
shrq $0x3d, %r10
addq %rcx, %r10
cmpq %r13, %r10
cmoveq %rax, %r10
movq -0x28(%rsp), %rax
movq %rbp, (%rax)
movq %r10, 0x8(%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq