// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aezv4/ref/encrypt.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, k, 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 (i=1; nbytes>=16; i++, nbytes-=16, N+=16) {
        E(K,kbytes,4,i,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 (k=0; k<veclen; k++) {
        p = A[k]; bytes = abytes[k]; empty = (bytes==0);
        for (i=1; bytes>=16; i++, bytes-=16, p+=16) {
            E(K,kbytes,5+k,i,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+k,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 0x2e70
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
leaq 0x30(%rsp), %r8
leaq 0x20(%rsp), %r9
movl $0x3, %edx
movl $0x1, %ecx
callq 0x2ed0
cmpl $0x0, 0x5c(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movl $0x1, 0x14(%rsp)
cmpl $0x10, 0x5c(%rsp)
jb 0x275e
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x14(%rsp), %ecx
movq 0x60(%rsp), %r8
leaq 0x30(%rsp), %r9
movl $0x4, %edx
callq 0x2ed0
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movl 0x5c(%rsp), %eax
subl $0x10, %eax
movl %eax, 0x5c(%rsp)
movq 0x60(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x60(%rsp)
jmp 0x26f7
cmpl $0x0, 0x5c(%rsp)
jne 0x276c
cmpl $0x0, 0x8(%rsp)
je 0x27d3
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 0x1110
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 0x2ed0
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x80(%rsp), %eax
jae 0x2919
movq 0x50(%rsp), %rax
movl 0x10(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
movl 0x10(%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, 0x14(%rsp)
cmpl $0x10, 0xc(%rsp)
jb 0x2890
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x10(%rsp), %edx
addl $0x5, %edx
movl 0x14(%rsp), %ecx
movq 0x18(%rsp), %r8
leaq 0x30(%rsp), %r9
callq 0x2ed0
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movl 0xc(%rsp), %eax
subl $0x10, %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x18(%rsp)
jmp 0x2827
cmpl $0x0, 0xc(%rsp)
jne 0x289e
cmpl $0x0, 0x8(%rsp)
je 0x2907
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 0x1110
movl 0xc(%rsp), %eax
movb $-0x80, 0x30(%rsp,%rax)
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x10(%rsp), %edx
addl $0x5, %edx
leaq 0x30(%rsp), %r8
leaq 0x30(%rsp), %r9
xorl %ecx, %ecx
callq 0x2ed0
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
jmp 0x2909
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x27db
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)