// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aezv3/ref/aez_ref.c
// Function: AEZhash
static void AEZhash(byte *K, unsigned kbytes, byte *N, unsigned nbytes,
    byte *A[], unsigned abytes[], unsigned veclen, unsigned tau, byte *result) {

    byte buf[16], sum[16], *p;
    unsigned i, j, bytes, empty;

    /* Initialize sum with hash of tau */
    memset(buf,0,12); write32_big_endian(tau, buf+12);
    E(K,kbytes,3,1,buf,sum);

    /* Hash nonce, accumulate into sum */
    empty = (nbytes==0);
    for (j=1; nbytes>=16; j++, nbytes-=16, N+=16) {
        E(K,kbytes,4,j,N,buf); xor_bytes(sum, buf, 16, sum);
    }
    if (nbytes || empty) {
        memset(buf,0,16); memcpy(buf,N,nbytes); buf[nbytes]=0x80;
        E(K,kbytes,4,0,buf,buf);
        xor_bytes(sum, buf, 16, sum);
    }

    /* Hash each vector element, accumulate into sum */
    for (i=0; i<veclen; i++) {
        p = A[i]; bytes = abytes[i]; empty = (bytes==0);
        for (j=1; bytes>=16; j++, bytes-=16, p+=16) {
            E(K,kbytes,5+i,j,p,buf); xor_bytes(sum, buf, 16, sum);
        }
        if (bytes || empty) {
            memset(buf,0,16); memcpy(buf,p,bytes); buf[bytes]=0x80;
            E(K,kbytes,5+i,0,buf,buf);
            xor_bytes(sum, buf, 16, sum);
        }
    }
    memcpy(result,sum,16);
}

// Assembly:
subq $0x78, %rsp
movq 0x90(%rsp), %rax
movl 0x88(%rsp), %eax
movl 0x80(%rsp), %eax
movq %rdi, 0x70(%rsp)
movl %esi, 0x6c(%rsp)
movq %rdx, 0x60(%rsp)
movl %ecx, 0x5c(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x48(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x1040
movl 0x88(%rsp), %edi
leaq 0x30(%rsp), %rsi
addq $0xc, %rsi
callq 0x1be0
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
leaq 0x30(%rsp), %r8
leaq 0x20(%rsp), %r9
movl $0x3, %edx
movl $0x1, %ecx
callq 0x1c40
cmpl $0x0, 0x5c(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
cmpl $0x10, 0x5c(%rsp)
jb 0x14ce
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x10(%rsp), %ecx
movq 0x60(%rsp), %r8
leaq 0x30(%rsp), %r9
movl $0x4, %edx
callq 0x1c40
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x2170
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
movl 0x5c(%rsp), %eax
subl $0x10, %eax
movl %eax, 0x5c(%rsp)
movq 0x60(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x60(%rsp)
jmp 0x1467
cmpl $0x0, 0x5c(%rsp)
jne 0x14dc
cmpl $0x0, 0x8(%rsp)
je 0x1543
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
leaq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x5c(%rsp), %eax
movl %eax, %edx
callq 0x10d0
movl 0x5c(%rsp), %eax
movb $-0x80, 0x30(%rsp,%rax)
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
leaq 0x30(%rsp), %r8
leaq 0x30(%rsp), %r9
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x1c40
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x2170
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x80(%rsp), %eax
jae 0x1689
movq 0x50(%rsp), %rax
movl 0x14(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
movl 0x14(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
cmpl $0x10, 0xc(%rsp)
jb 0x1600
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x14(%rsp), %edx
addl $0x5, %edx
movl 0x10(%rsp), %ecx
movq 0x18(%rsp), %r8
leaq 0x30(%rsp), %r9
callq 0x1c40
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x2170
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
movl 0xc(%rsp), %eax
subl $0x10, %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x18(%rsp)
jmp 0x1597
cmpl $0x0, 0xc(%rsp)
jne 0x160e
cmpl $0x0, 0x8(%rsp)
je 0x1677
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
leaq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0xc(%rsp), %eax
movl %eax, %edx
callq 0x10d0
movl 0xc(%rsp), %eax
movb $-0x80, 0x30(%rsp,%rax)
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x14(%rsp), %edx
addl $0x5, %edx
leaq 0x30(%rsp), %r8
leaq 0x30(%rsp), %r9
xorl %ecx, %ecx
callq 0x1c40
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x2170
jmp 0x1679
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x154b
movq 0x90(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rax)
addq $0x78, %rsp
retq
nopw (%rax,%rax)