// File: /workspace/github_cpp_makefile_star2_O1/hugosantos[P]dbeacon/dbeacon.cpp
// Function: beaconMcastState::update(unsigned char, unsigned int, unsigned long, unsigned long, unsigned long)
void beaconMcastState::update(uint8_t ttl, uint32_t seqnum, uint64_t timestamp, uint64_t tsnow, uint64_t _now) {
	/*
	 * ttl - received TTL
	 * seqnum - received seqnum in probe
	 * timestamp - received timestamp in probe (timeofday in sender)
	 * _now - when this packet was received locally (timeofday of host)
	 */

	int64_t now = (uint32_t)_now;

	int64_t diff = now - timestamp;
	int64_t absdiff = abs64(diff);

	if (udiff(seqnum, lastseq) > PACKETS_VERY_OLD) {
		refresh(seqnum - 1, tsnow);
	}

	if (seqnum < lastseq && (lastseq - seqnum) >= packetcount)
		return;

	s.timestamp = timestamp;
	s.lastupdate = tsnow;

	bool dup = false;

	uint32_t expectseq = lastseq + 1;

	if (seqnum < expectseq) {
		for (uint32_t i = 0; i < pointer; i++) {
			if (cacheseqnum[i] == seqnum) {
				dup = true;
				break;
			}
		}
	}

	s.rttl = ttl;

	if (dup) {
		lastdup ++;
	} else {
		packetcountreal++;

		cacheseqnum[pointer++] = seqnum;

		lastdelay += diff;

		int newjitter = absdiff - lastjitter;
		lastjitter = absdiff;
		if (newjitter < 0)
			newjitter = -newjitter;
		s.avgjitter = 15/16. * s.avgjitter + 1/16. * newjitter;

		if (expectseq == seqnum) {
			packetcount ++;
		} else if (seqnum > expectseq) {
			packetcount += seqnum - lastseq;

			lastloss += seqnum - lastseq - 1;
		} else {
			lastloss --;
			lastooo ++;
		}

		if (expectseq <= seqnum) {
			lastseq = seqnum;
		}
	}

	if (packetcount >= PACKETS_PERIOD) {
		s.avgdelay = lastdelay / (float)packetcountreal;
		s.avgloss = lastloss / (float)packetcount;
		s.avgooo = lastooo / (float)packetcount;
		s.avgdup = lastdup / (float)packetcount;

		s.valid = true;

		lastdelay = 0;
		lastloss = 0;
		lastooo = 0;
		lastdup = 0;
		packetcount = 0;
		packetcountreal = 0;
		pointer = 0;
	}
}

// Assembly:
movl (%rdi), %eax
movl %eax, %r10d
subl %edx, %r10d
negl %r10d
subl %edx, %eax
movl %r9d, %r9d
cmovbl %r10d, %eax
subq %rcx, %r9
movq %r9, %r10
negq %r10
cmovsq %r9, %r10
cmpl $0x97, %eax
jb 0x6e64
leal -0x1(%rdx), %eax
movl %eax, (%rdi)
xorl %eax, %eax
movq %rax, 0x28(%rdi)
movq %r8, 0x30(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rdi)
movups %xmm0, 0x14(%rdi)
movups %xmm0, 0x38(%rdi)
movq %rax, 0x45(%rdi)
movl (%rdi), %eax
movl %eax, %r11d
subl %edx, %r11d
jbe 0x6e78
cmpl 0x4(%rdi), %r11d
jae 0x6fac
movq %rcx, 0x28(%rdi)
movq %r8, 0x30(%rdi)
leal 0x1(%rax), %ecx
cmpl %edx, %ecx
jbe 0x6ea6
movl 0xc(%rdi), %r8d
testq %r8, %r8
je 0x6ea6
xorl %r11d, %r11d
cmpl %edx, 0x50(%rdi,%r11,4)
je 0x6f27
incq %r11
cmpl %r11d, %r8d
jne 0x6e93
movb %sil, 0x4d(%rdi)
incl 0x8(%rdi)
movl 0xc(%rdi), %esi
leal 0x1(%rsi), %r8d
movl %r8d, 0xc(%rdi)
movl %edx, 0x50(%rdi,%rsi,4)
addl %r9d, 0x10(%rdi)
movl %r10d, %esi
subl 0x14(%rdi), %esi
movl %r10d, 0x14(%rdi)
movl %esi, %r8d
negl %r8d
cmovsl %esi, %r8d
xorps %xmm0, %xmm0
cvtss2sd 0x3c(%rdi), %xmm0
cvtsi2sd %r8d, %xmm1
mulsd 0x516f(%rip), %xmm1     # 0xc058
mulsd 0x516f(%rip), %xmm0     # 0xc060
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x3c(%rdi)
cmpl %edx, %ecx
jne 0x6f07
incl 0x4(%rdi)
jmp 0x6f1f
jae 0x6f19
movl %edx, %esi
subl %eax, %esi
addl %esi, 0x4(%rdi)
notl %eax
addl %edx, %eax
addl %eax, 0x18(%rdi)
jmp 0x6f1f
decl 0x18(%rdi)
incl 0x20(%rdi)
cmpl %edx, %ecx
ja 0x6f2e
movl %edx, (%rdi)
jmp 0x6f2e
movb %sil, 0x4d(%rdi)
incl 0x1c(%rdi)
movl 0x4(%rdi), %eax
cmpl $0x28, %eax
jb 0x6fac
xorps %xmm0, %xmm0
cvtsi2ssl 0x10(%rdi), %xmm0
movl 0x8(%rdi), %ecx
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x38(%rdi)
xorps %xmm0, %xmm0
cvtsi2ssl 0x18(%rdi), %xmm0
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x40(%rdi)
xorps %xmm0, %xmm0
cvtsi2ssl 0x20(%rdi), %xmm0
divss %xmm1, %xmm0
movss %xmm0, 0x48(%rdi)
xorps %xmm0, %xmm0
cvtsi2ssl 0x1c(%rdi), %xmm0
leaq 0x4(%rdi), %rax
divss %xmm1, %xmm0
movss %xmm0, 0x44(%rdi)
movb $0x1, 0x4c(%rdi)
movl $0x0, 0x18(%rdi)
movq $0x0, 0x1c(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
retq
nop