// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/trivia128v2/ref/encrypt.c
// Function: Initialize_process_AD_Reinitialize
void Initialize_process_AD_Reinitialize(u64 *SC_State, const unsigned char *ad, unsigned long long adlen)
{
   u64  Z[1], Checksum[3], Block, ck_ctr; 
   u32 dummy_word[2], Tag[4], temp; 
   u8 FINISH; 
   int i; 

   for(i=0; i<18; i++) {SC_Update64(SC_State, Z);} // Update SC_State for 18 64-rounds.


/*  PROCESS ASSOCIATED DATA BLOCKS...   */
//----------------------------------------

   ck_ctr = CHUNK_SIZE;  set_zero32(Tag,4);  set_zero64(Checksum,3);
   while(adlen >=8) // Process All But the Final Block of AD 
   {
	Block = load64(ad);
	process_block(Block, Tag, Checksum, SC_State, Z, PROC_BLOCK); // Update the Tag and Checksum
       	ad = ad+8; adlen = adlen-8; ck_ctr--;
        if(ck_ctr==0) // process the checksum blocks
   	{
	   for(i=0; i<3; i++){
		process_block(Checksum[i], Tag, Checksum, SC_State, Z, PROC_CHECKSUM);}// Update Tag 
                                                                                                // for the Checksum Block
	   ck_ctr=CHUNK_SIZE; set_zero64(Checksum,3); // Reset The Chunk Counter and Set the Checksum Array to zero
   	}
   }

   process_block(pad(ad, adlen), Tag, Checksum, SC_State, Z, PROC_BLOCK);//, PROC_AD); // Update the Tag and Checksum for the 
                                                                                   // Final Block
 
   for(i=0; i<3; i++)
	{  process_block(Checksum[i], Tag, Checksum, SC_State, Z, PROC_CHECKSUM);
	   if(i == 0) {Tag[0] ^= (u32)(Z[0]>>32); Tag[1] ^= (u32)(Z[0]);}
	   if(i == 2) {Tag[2] ^= (u32)(Z[0]>>32); Tag[3] ^= (u32)(Z[0]);}
	}


// Update the Tag for the Final 4 Checksum Blocks for AD and Get the Key for Variable Length Handling
  // for(i=0; i<4; i++){process_block(Checksum[i], Tag, Checksum, SC_State, Z+i, PROC_CHECKSUM);}

// Add the Currently Generated Key to Handle Variable Length AD
  // Tag[0] ^= (u32)(Z[0]>>32); Tag[1] ^= (u32)(Z[0]); Tag[2] ^= (u32)(Z[1]>>32); Tag[3] ^= (u32)(Z[1]); Tag[4] ^= (u32)(Z[2]>>32);

   insert_SC(SC_State, Tag); // Insert Tag for AD to streamcipher state
   for(i=0; i<18; i++) {SC_Update64(SC_State, Z);} // Update SC_State for 18 64-rounds.
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movl $0x0, 0x4(%rsp)
cmpl $0x12, 0x4(%rsp)
jge 0x1cce
movq 0x70(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1090
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x1cab
movq $0x80, 0x30(%rsp)
leaq 0x10(%rsp), %rdi
movl $0x4, %esi
callq 0x1ed0
leaq 0x40(%rsp), %rdi
movl $0x3, %esi
callq 0x1f10
cmpq $0x8, 0x60(%rsp)
jb 0x1dc5
movq 0x68(%rsp), %rdi
callq 0x1080
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0x58(%rsp), %r8
xorl %r9d, %r9d
callq 0x1100
movq 0x68(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x68(%rsp)
movq 0x60(%rsp), %rax
subq $0x8, %rax
movq %rax, 0x60(%rsp)
movq 0x30(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x1dc0
movl $0x0, 0x4(%rsp)
cmpl $0x3, 0x4(%rsp)
jge 0x1da8
movslq 0x4(%rsp), %rax
movq 0x40(%rsp,%rax,8), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0x58(%rsp), %r8
movl $0x1, %r9d
callq 0x1100
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x1d6b
movq $0x80, 0x30(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x3, %esi
callq 0x1f10
jmp 0x1cf5
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rax
movl %eax, %esi
callq 0x10a0
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0x58(%rsp), %r8
xorl %r9d, %r9d
callq 0x1100
movl $0x0, 0x4(%rsp)
cmpl $0x3, 0x4(%rsp)
jge 0x1e8d
movslq 0x4(%rsp), %rax
movq 0x40(%rsp,%rax,8), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0x58(%rsp), %r8
movl $0x1, %r9d
callq 0x1100
cmpl $0x0, 0x4(%rsp)
jne 0x1e56
movq 0x58(%rsp), %rax
shrq $0x20, %rax
xorl 0x10(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x58(%rsp), %rax
xorl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x2, 0x4(%rsp)
jne 0x1e7b
movq 0x58(%rsp), %rax
shrq $0x20, %rax
xorl 0x18(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x58(%rsp), %rax
xorl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x1e7d
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x1dfd
movq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1030
movl $0x0, 0x4(%rsp)
cmpl $0x12, 0x4(%rsp)
jge 0x1ec7
movq 0x70(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1090
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x1ea4
addq $0x78, %rsp
retq
nopl (%rax)