// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/omdsha512k128n128tau128v2/ref/omdsha512.c
// Function: hash
void
hash (hashblock taga, const hashblock key, const unsigned char *ad,
      unsigned long long int adlen)
{
   hashblock lstar, lzero;
   hashblock delta;
   hashblock left, right;
   hashblock xor_res, key_func_res;
   hashblock taures;
   unsigned int  modlen;
   long long int i, l;
   size_t b;

   /* CHANGE FROM V1 TO V2 HERE */
   /* L_* = F_K(0^n, <tau>_m) */
   l2b (taures, OMD_tau);
   key_func (lstar, block0s, key, taures);
   /* L[0] = 4.L* */
   double_block (lzero, lstar);
   double_block (lzero, lzero);

   /*b = n+m*/
   b = OMD_n + OMD_m;

   /* A_1 || A_2 ··· A_{l−1} || A_l = A, where |A_i| = b for 1 ≤ i ≤ l−1
      and |A_l| ≤ b */
   /* l=ceil(adlen/b) */
   l = (adlen + b - 1)/b;

   /* Tag_a = 0^n  */
   memset (taga, 0x00, OMD_n);
   /* If AD="" => Tag_a = 0^n */
   if (adlen == 0)
      {
	 return;
      }

   /* \bar{\delta}_{0,0} = 0^n */
   memset (delta, 0x00, OMD_n);

   /** for i = 1 to l-1 **/
   /**********************/
   for (i = 1; i < l; i++)
      {
	 /*  \bar{\delta}_{i, 0} =  \bar{\delta}{i-1, 0} ^ L[ntz(i)]  */
	 increment_masking_associated_data (delta, delta, lzero, i);

	 /* Left = A_l[b-1...m]; */
	 memcpy (left, &ad[(i-1)*b],  OMD_n);
	 /* Right = A_l[m-1...0]  */
	 memcpy (right,&ad[(i-1)*b+OMD_n],OMD_m);

	 /* Tag_a = Tag_a ^ F_K(Left ^ \delta_{i, 0}, right) */
	 xor_block (xor_res, delta, left);
	 key_func (key_func_res, xor_res, key, right);
	 xor_block (taga, taga, key_func_res);
      }
   /**************************/
   /******* endfor ***********/

   /* here adlen!=0, we process last ad block*/

   modlen = adlen%b;

   /* |A_l| = b then */
   if (modlen == 0)
      {
	 /* last mask = \bar{\delta}{l,0}  */
	 increment_masking_associated_data (delta, delta, lzero,l);

	 memcpy (left, &ad[(l-1)*b],      OMD_n);
	 memcpy (right,&ad[(l-1)*b+OMD_n],OMD_m);
      }
   /* |A_l| < b then */
   else
      {
	 /* last mask = \bar{\delta}{l-1,1}  */
	 final_masking_associated_data (delta, delta, lstar);

	 memset (left , 0x00, OMD_n);
	 memset (right, 0x00, OMD_m);

	 memcpy (left, &ad[(l-1)*b], (modlen < OMD_n ? modlen : OMD_n));
	 memcpy (right, &ad[(l-1)*b+OMD_n], (modlen < OMD_n
					     ? 0
					     : modlen - OMD_n));

	 if (modlen < OMD_n)
	    /* pad last block */
	    left[modlen] = 0x80;
	 else
	    right[modlen-OMD_n] = 0x80;
   }

   /* Tag_a = Tag_a ^ F_K(Left ^ \delta_{l, 0 or 1}, right) */
   xor_block (xor_res, delta, left);
   key_func (key_func_res, xor_res, key, right);
   xor_block (taga, taga, key_func_res);
}

// Assembly:
subq $0x278, %rsp            # imm = 0x278
movq %rdi, 0x270(%rsp)
movq %rsi, 0x268(%rsp)
movq %rdx, 0x260(%rsp)
movq %rcx, 0x258(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x10, %esi
callq 0x1140
leaq 0x210(%rsp), %rdi
movq 0x268(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x175e(%rip), %rsi      # 0x3000
callq 0x10b0
leaq 0x1d0(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x1070
leaq 0x1d0(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x1070
movq $0x80, 0x30(%rsp)
movq 0x258(%rsp), %rax
addq 0x30(%rsp), %rax
subq $0x1, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq 0x270(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x1040
cmpq $0x0, 0x258(%rsp)
jne 0x191d
jmp 0x1c6f
leaq 0x190(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x1040
movq $0x1, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq 0x38(%rsp), %rax
jge 0x1a3c
leaq 0x190(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
movq 0x40(%rsp), %rax
movl %eax, %ecx
callq 0x1050
leaq 0x150(%rsp), %rdi
movq 0x260(%rsp), %rsi
movq 0x40(%rsp), %rax
subq $0x1, %rax
imulq 0x30(%rsp), %rax
addq %rax, %rsi
movl $0x40, %edx
callq 0x1150
leaq 0x110(%rsp), %rdi
movq 0x260(%rsp), %rsi
movq 0x40(%rsp), %rax
subq $0x1, %rax
imulq 0x30(%rsp), %rax
addq $0x40, %rax
addq %rax, %rsi
movl $0x40, %edx
callq 0x1150
leaq 0xd0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x150(%rsp), %rdx
callq 0x1130
leaq 0x90(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
movq 0x268(%rsp), %rdx
leaq 0x110(%rsp), %rcx
callq 0x10b0
movq 0x270(%rsp), %rdi
movq 0x270(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x1130
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x193a
movq 0x258(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x30(%rsp)
movl %edx, %eax
movl %eax, 0x4c(%rsp)
cmpl $0x0, 0x4c(%rsp)
jne 0x1ae3
leaq 0x190(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
movq 0x38(%rsp), %rax
movl %eax, %ecx
callq 0x1050
leaq 0x150(%rsp), %rdi
movq 0x260(%rsp), %rsi
movq 0x38(%rsp), %rax
subq $0x1, %rax
imulq 0x30(%rsp), %rax
addq %rax, %rsi
movl $0x40, %edx
callq 0x1150
leaq 0x110(%rsp), %rdi
movq 0x260(%rsp), %rsi
movq 0x38(%rsp), %rax
subq $0x1, %rax
imulq 0x30(%rsp), %rax
addq $0x40, %rax
addq %rax, %rsi
movl $0x40, %edx
callq 0x1150
jmp 0x1c10
leaq 0x190(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x210(%rsp), %rdx
callq 0x1090
leaq 0x150(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x1040
leaq 0x110(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x1040
leaq 0x150(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x260(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
imulq 0x30(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
cmpl $0x40, 0x4c(%rsp)
jae 0x1b65
movl 0x4c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x1b70
movl $0x40, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1b70
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1150
leaq 0x110(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x260(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
imulq 0x30(%rsp), %rcx
addq $0x40, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
cmpl $0x40, 0x4c(%rsp)
jae 0x1bc6
xorl %eax, %eax
movl %eax, 0x4(%rsp)
jmp 0x1bd1
movl 0x4c(%rsp), %eax
subl $0x40, %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1150
cmpl $0x40, 0x4c(%rsp)
jae 0x1bfd
movl 0x4c(%rsp), %eax
movb $-0x80, 0x150(%rsp,%rax)
jmp 0x1c0e
movl 0x4c(%rsp), %eax
subl $0x40, %eax
movl %eax, %eax
movb $-0x80, 0x110(%rsp,%rax)
jmp 0x1c10
leaq 0xd0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x150(%rsp), %rdx
callq 0x1130
leaq 0x90(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
movq 0x268(%rsp), %rdx
leaq 0x110(%rsp), %rcx
callq 0x10b0
movq 0x270(%rsp), %rdi
movq 0x270(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x1130
addq $0x278, %rsp            # imm = 0x278
retq
nopw (%rax,%rax)