// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes128n8t8silcv2/ref/silc.c
// Function: process_ad
int process_ad(ae_cxt* cxt, const byte* ad, unsigned long long adlen, const byte* nonce, unsigned long long nlen)
{
	byte* state = cxt->es;
	AES_KEY *ekey = cxt->pt_ekey;

	cxt->ad = (byte*) ad;
	cxt->adlen = adlen;
	cxt->nonce = (byte*) nonce;
	cxt->nlen = nlen;

	/* process the nonce */
	memset(state, 0, STATE_LEN);
	state[STATE_LEN-nlen-1] = PARAM;
	memcpy(state+STATE_LEN-nlen, nonce, nlen);
	//xor_bytes(state, nonce, nlen);	// xor to the last nlen bytes
	pstate2("processing nonce:", NULL);
	AES_encrypt(state, state, ekey);

	/* process the middle normal blocks of ad */
	unsigned long long i;
	for(i = 0; i < (unsigned long long)adlen/STATE_LEN; i++){
		xor_bytes(state, ad+STATE_LEN*i, STATE_LEN);
		pstate2("After xoring associated data:", state);
		pstate2("Enc:", NULL);
		AES_encrypt(state, state, ekey);
	}
	/* process the last block partial block if any */
	unsigned long long lastblocklen = adlen % STATE_LEN;
	if(lastblocklen){
		xor_bytes(state, ad+i*STATE_LEN, lastblocklen);
		pstate2("After processing last partial associated data block:", state);
		pstate2("Enc:", NULL);
		AES_encrypt(state, state, ekey);
	}

	/* encode the adlen and process */
	unsigned long long t_adlen = adlen;
	for(i = 0; i < sizeof(unsigned long long); i++) {
		state[STATE_LEN-1-i] ^= t_adlen & 0xff;
		t_adlen >>= 8;
	}
	pstate2("After xoring the length of associated data:", state);

	g(state);
	pstate2("After applying g:", state);
	memcpy(cxt->ts, state, STATE_LEN);
	pstate2("Enc:", NULL);
	AES_encrypt(state, state, ekey);

	g(cxt->ts);
	pstate2("After applying g to tag state:", cxt->ts);
	pstate2("Enc:", NULL);
	AES_encrypt(cxt->ts, cxt->ts, ekey);
	return SUCCESS;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x60(%rsp), %rax
movq 0x118(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x130(%rax)
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x138(%rax)
movq 0x48(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x140(%rax)
movq 0x40(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x148(%rax)
movq 0x38(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
movq 0x38(%rsp), %rax
movl $0x10, %ecx
subq 0x40(%rsp), %rcx
subq $0x1, %rcx
movb $-0x30, (%rax,%rcx)
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
subq 0x40(%rsp), %rax
addq %rax, %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x10e0
leaq 0x3f03(%rip), %rdi      # 0x9830
xorl %eax, %eax
movl %eax, %esi
callq 0x10f0
movq 0x38(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1070
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq 0x50(%rsp), %rcx
shrq $0x4, %rcx
cmpq %rcx, %rax
jae 0x59cb
movq 0x38(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x28(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movl $0x10, %edx
callq 0x10d0
movq 0x38(%rsp), %rsi
leaq 0x3eb0(%rip), %rdi      # 0x9842
callq 0x10f0
leaq 0x3ec2(%rip), %rdi      # 0x9860
xorl %eax, %eax
movl %eax, %esi
callq 0x10f0
movq 0x38(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1070
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x5953
movq 0x50(%rsp), %rax
andq $0xf, %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x5a38
movq 0x38(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x28(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movq 0x20(%rsp), %rax
movl %eax, %edx
callq 0x10d0
movq 0x38(%rsp), %rsi
leaq 0x3e56(%rip), %rdi      # 0x9865
callq 0x10f0
leaq 0x3e45(%rip), %rdi      # 0x9860
xorl %eax, %eax
movl %eax, %esi
callq 0x10f0
movq 0x38(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1070
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
cmpq $0x8, 0x28(%rsp)
jae 0x5a96
movq 0x18(%rsp), %rsi
andq $0xff, %rsi
movq 0x38(%rsp), %rax
movl $0xf, %ecx
subq 0x28(%rsp), %rcx
movzbl (%rax,%rcx), %edx
xorq %rsi, %rdx
movb %dl, (%rax,%rcx)
movq 0x18(%rsp), %rax
shrq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x5a4b
movq 0x38(%rsp), %rsi
leaq 0x3df8(%rip), %rdi      # 0x989a
callq 0x10f0
movq 0x38(%rsp), %rax
movzbl (%rax), %eax
movq 0x38(%rsp), %rcx
movzbl 0x1(%rcx), %ecx
xorl %ecx, %eax
movb %al, 0x13(%rsp)
movl $0x0, 0x14(%rsp)
cmpl $0xf, 0x14(%rsp)
jge 0x5af9
movq 0x38(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq 0x38(%rsp), %rax
movslq 0x14(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x5ac6
movb 0x13(%rsp), %dl
movq 0x38(%rsp), %rax
movslq 0x14(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x38(%rsp), %rsi
leaq 0x3db0(%rip), %rdi      # 0x98c6
callq 0x10f0
movq 0x60(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rax)
leaq 0x3d25(%rip), %rdi      # 0x9860
xorl %eax, %eax
movl %eax, %esi
callq 0x10f0
movq 0x38(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1070
movq 0x60(%rsp), %rax
movzbl 0x10(%rax), %eax
movq 0x60(%rsp), %rcx
movzbl 0x11(%rcx), %ecx
xorl %ecx, %eax
movb %al, 0xb(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0xf, 0xc(%rsp)
jge 0x5bad
movq 0x60(%rsp), %rax
movl 0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb 0x10(%rax,%rcx), %dl
movq 0x60(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb %dl, 0x10(%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5b78
movb 0xb(%rsp), %dl
movq 0x60(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb %dl, 0x10(%rax,%rcx)
movq 0x60(%rsp), %rsi
addq $0x10, %rsi
leaq 0x3d09(%rip), %rdi      # 0x98d8
callq 0x10f0
leaq 0x3c85(%rip), %rdi      # 0x9860
xorl %eax, %eax
movl %eax, %esi
callq 0x10f0
movq 0x60(%rsp), %rdi
addq $0x10, %rdi
movq 0x60(%rsp), %rsi
addq $0x10, %rsi
movq 0x30(%rsp), %rdx
callq 0x1070
xorl %eax, %eax
addq $0x68, %rsp
retq
nopw (%rax,%rax)