// File: /workspace/github_c_makefile_star2_O2/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 %r8, -0x30(%rsp)
movq %rdi, -0x18(%rsp)
movabsq $0x1, %rax
xorl %edi, %edi
xorl %r9d, %r9d
movl %edx, -0x4c(%rsp)
movl %edx, %ebp
movq %rsi, -0x20(%rsp)
movq %rsi, %r12
movq %rax, -0x58(%rsp)
movq %rax, %r15
cmpl $0x40, %ebp
movq %r15, -0x28(%rsp)
jb 0x15cd
movq %rdi, -0x10(%rsp)
movq %r9, -0x8(%rsp)
xorl %edx, %edx
xorl %r10d, %r10d
xorl %r13d, %r13d
cmpq $0xf, %rdx
ja 0x155a
movl (%r12,%rdx,4), %r8d
movl 0x4(%r12,%rdx,4), %r15d
movl (%rcx,%rdx,4), %eax
addl %r8d, %eax
movl 0x8(%r12,%rdx,4), %r11d
movl 0x8(%rcx,%rdx,4), %ebx
addl %r11d, %ebx
imulq %rax, %rbx
addq %r10, %rbx
movl 0x4(%rcx,%rdx,4), %eax
addl %r15d, %eax
movl 0xc(%r12,%rdx,4), %edi
movl 0xc(%rcx,%rdx,4), %r9d
addl %edi, %r9d
imulq %rax, %r9
movl 0x10(%rcx,%rdx,4), %r14d
movl 0x14(%rcx,%rdx,4), %esi
addl %r14d, %r8d
movl 0x18(%rcx,%rdx,4), %eax
addl %eax, %r11d
imulq %r8, %r11
addq %r13, %r11
addl %esi, %r15d
movl 0x1c(%rcx,%rdx,4), %r10d
addl %r10d, %edi
imulq %r15, %rdi
movl 0x10(%r12,%rdx,4), %r8d
addl %r8d, %r14d
movl 0x18(%r12,%rdx,4), %r15d
addl %r15d, %eax
imulq %r14, %rax
addq %r9, %rax
addq %rbx, %rax
movl 0x14(%r12,%rdx,4), %r9d
addl %r9d, %esi
movl 0x1c(%r12,%rdx,4), %r13d
addl %r13d, %r10d
imulq %rsi, %r10
addq %rax, %r10
addl 0x20(%rcx,%rdx,4), %r8d
addl 0x28(%rcx,%rdx,4), %r15d
addl 0x24(%rcx,%rdx,4), %r9d
addl 0x2c(%rcx,%rdx,4), %r13d
addq $0x8, %rdx
imulq %r8, %r15
addq %rdi, %r15
addq %r11, %r15
imulq %r9, %r13
addq %r15, %r13
jmp 0x148e
movq -0x58(%rsp), %rdx
movq -0x30(%rsp), %r8
mulxq (%r8), %rax, %rdi
movabsq $0xfffffffffffffff, %r9 # imm = 0xFFFFFFFFFFFFFFF
andq %r9, %r10
shldq $0x3, %rax, %rdi
movabsq $0x1fffffffffffffff, %rsi # imm = 0x1FFFFFFFFFFFFFFF
andq %rsi, %rax
addq %r10, %rax
addq %rax, %rdi
movq %rdi, -0x58(%rsp)
andq %r9, %r13
movq -0x28(%rsp), %rdx
mulxq 0x8(%r8), %rax, %r15
shldq $0x3, %rax, %r15
andq %rsi, %rax
addq %r13, %rax
addq %rax, %r15
addl $-0x40, %ebp
addq $0x40, %r12
movq -0x8(%rsp), %r9
addq $0x40, %r9
movq -0x10(%rsp), %rdi
addq $-0x40, %rdi
jmp 0x146e
testl %ebp, %ebp
je 0x16a1
addq $0x1c, %rcx
movl -0x4c(%rsp), %ebp
movl %ebp, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
movabsq $0x1fffffffffffffff, %rbx # imm = 0x1FFFFFFFFFFFFFFF
movq -0x58(%rsp), %rdx
movq -0x20(%rsp), %r11
leal (%r14,%rdi), %eax
cmpl $0x10, %eax
jb 0x166e
movl (%r11,%r9), %esi
movq %rdi, %r15
movl 0x4(%r11,%r9), %edi
movl -0x1c(%rcx), %r8d
addl %esi, %r8d
movl 0x8(%r11,%r9), %r10d
movl -0x14(%rcx), %eax
addl %r10d, %eax
imulq %r8, %rax
addq %r13, %rax
movl -0x18(%rcx), %r8d
addl %edi, %r8d
addl -0xc(%rcx), %esi
addl -0x4(%rcx), %r10d
imulq %rsi, %r10
addq %r12, %r10
movl 0xc(%r11,%r9), %r12d
movl -0x10(%rcx), %r13d
addl %r12d, %r13d
imulq %r8, %r13
addl -0x8(%rcx), %edi
addl (%rcx), %r12d
addq %rax, %r13
imulq %rdi, %r12
movq %r15, %rdi
addq %r10, %r12
addq $0x10, %r9
addq $0x10, %rcx
addq $-0x10, %rdi
jmp 0x15fa
cmpl %r9d, %ebp
je 0x1718
addq %r9, %r11
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, -0x48(%rsp)
movq %r14, %rax
subq %r9, %rax
xorl %esi, %esi
cmpq %rax, %rsi
jae 0x16b5
movb (%r11), %dil
movb %dil, -0x48(%rsp,%rsi)
incq %rsi
incq %r11
jmp 0x168c
movabsq $0x1fffffffffffffff, %rbx # imm = 0x1FFFFFFFFFFFFFFF
movq -0x58(%rsp), %rsi
jmp 0x1759
movl -0x48(%rsp), %r8d
movl -0x44(%rsp), %eax
movl -0x1c(%rcx), %edi
addl %r8d, %edi
movl -0x40(%rsp), %esi
movq %r9, %rbp
movl -0x14(%rcx), %r9d
addl %esi, %r9d
imulq %rdi, %r9
movl -0x18(%rcx), %r10d
addl %eax, %r10d
movl -0x3c(%rsp), %edi
movl -0x10(%rcx), %r11d
addl %edi, %r11d
imulq %r10, %r11
addq %r9, %r11
addl -0xc(%rcx), %r8d
addl -0x4(%rcx), %esi
imulq %r8, %rsi
addl -0x8(%rcx), %eax
addl (%rcx), %edi
imulq %rax, %rdi
addq %rsi, %rdi
addq %r14, %r13
addq %r11, %r13
subq %rbp, %r13
addq %r14, %r12
addq %rdi, %r12
subq %rbp, %r12
movabsq $0xfffffffffffffff, %rdi # imm = 0xFFFFFFFFFFFFFFF
andq %rdi, %r13
movq -0x30(%rsp), %rcx
mulxq (%rcx), %rsi, %rax
shldq $0x3, %rsi, %rax
andq %rbx, %rsi
addq %rax, %rsi
movq -0x28(%rsp), %rdx
mulxq 0x8(%rcx), %r15, %rax
addq %r13, %rsi
andq %rdi, %r12
shldq $0x3, %r15, %rax
andq %rbx, %r15
addq %rax, %r15
addq %r12, %r15
movq %rsi, %rax
andq %rbx, %rax
shrq $0x3d, %rsi
addq %rax, %rsi
xorl %eax, %eax
cmpq %rbx, %rsi
cmoveq %rax, %rsi
movq %r15, %rcx
andq %rbx, %rcx
shrq $0x3d, %r15
addq %rcx, %r15
cmpq %rbx, %r15
cmoveq %rax, %r15
movq -0x18(%rsp), %rax
movq %rsi, (%rax)
movq %r15, 0x8(%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq