// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/led80n6t4silcv2/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;

	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);
	LED80_enc(state, cxt->userkey);

	/* 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);
		LED80_enc(state, cxt->userkey);
	}
	/* 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);
		LED80_enc(state, cxt->userkey);
	}

	/* 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;
	}

	g(state);
	memcpy(cxt->ts, state, STATE_LEN);
	LED80_enc(state, cxt->userkey);

	g(cxt->ts);
	LED80_enc(cxt->ts, cxt->userkey);
	return SUCCESS;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x40(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x38(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x30(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x28(%rsp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x1040
movq 0x28(%rsp), %rax
movl $0x8, %ecx
subq 0x30(%rsp), %rcx
subq $0x1, %rcx
movb $-0x38, (%rax,%rcx)
movq 0x28(%rsp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
subq 0x30(%rsp), %rax
addq %rax, %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1140
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1120
movq $0x0, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x40(%rsp), %rcx
shrq $0x3, %rcx
cmpq %rcx, %rax
jae 0x1f0b
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl $0x8, %edx
callq 0x1110
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1120
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x1eb5
movq 0x40(%rsp), %rax
andq $0x7, %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x1f56
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq 0x18(%rsp), %rax
movl %eax, %edx
callq 0x1110
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1120
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpq $0x8, 0x20(%rsp)
jae 0x1fb4
movq 0x10(%rsp), %rsi
andq $0xff, %rsi
movq 0x28(%rsp), %rax
movl $0x7, %ecx
subq 0x20(%rsp), %rcx
movzbl (%rax,%rcx), %edx
xorq %rsi, %rdx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
shrq $0x8, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x1f69
jmp 0x1fb6
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
movq 0x28(%rsp), %rcx
movzbl 0x1(%rcx), %ecx
xorl %ecx, %eax
movb %al, 0xb(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x7, 0xc(%rsp)
jge 0x2008
movq 0x28(%rsp), %rax
movl 0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq 0x28(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x1fd5
movb 0xb(%rsp), %dl
movq 0x28(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1120
movq 0x50(%rsp), %rax
movzbl 0x8(%rax), %eax
movq 0x50(%rsp), %rcx
movzbl 0x9(%rcx), %ecx
xorl %ecx, %eax
movb %al, 0x3(%rsp)
movl $0x0, 0x4(%rsp)
cmpl $0x7, 0x4(%rsp)
jge 0x2092
movq 0x50(%rsp), %rax
movl 0x4(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb 0x8(%rax,%rcx), %dl
movq 0x50(%rsp), %rax
movslq 0x4(%rsp), %rcx
movb %dl, 0x8(%rax,%rcx)
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x205d
movb 0x3(%rsp), %dl
movq 0x50(%rsp), %rax
movslq 0x4(%rsp), %rcx
movb %dl, 0x8(%rax,%rcx)
movq 0x50(%rsp), %rdi
addq $0x8, %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1120
xorl %eax, %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)