// File: /workspace/github_cpp_makefile_star2_O3/estwings57[P]CasHMC/sources/LinkMaster.cpp
// Function: CasHMC::LinkMaster::UpdateField(int, CasHMC::Packet*)
void LinkMaster::UpdateField(int nextWriteP, Packet *packet)
{
	//Sequence number updated
	packet->SEQ = (masterSEQ<7) ? masterSEQ++ : 0;
	//Update retry buffer pointer field
	packet->RRP = lastestRRP;
	packet->FRP = (nextWriteP < MAX_RETRY_BUF) ? nextWriteP : nextWriteP - MAX_RETRY_BUF;
	//CRC field updated
	startCRC = false;
	if(CRC_CHECK)	packet->CRC = packet->GetCRC();
	//Decrement the token count register by the number of packet in the transmitted packet
	if(packet->packetType != FLOW) {
		tokenCount -= packet->LNG;
		DEBUG(ALI(18)<<header<<ALI(15)<<*packet<<(downstream ? "Down) " : "Up)   ")
			<<"Decreased TOKEN : "<<packet->LNG<<" (remaining : "<<tokenCount<<"/"<<MAX_LINK_BUF<<")");
	}
	//Save packet in retry buffer
	Packet *retryPacket = new Packet(*packet);
	if(retryBuffers[retBufWriteP] == NULL) {
		retryBuffers[retBufWriteP] = retryPacket;
	}
	else {
		ERROR(header<<"  == Error - retryBuffers["<<retBufWriteP<<"] is not NULL  (CurrentClock : "<<currentClockCycle<<")");
		exit(0);
	}
	for(int i=1; i<packet->LNG; i++) {
		retryBuffers[(retBufWriteP+i<MAX_RETRY_BUF ? retBufWriteP+i : retBufWriteP+i-MAX_RETRY_BUF)] = NULL;
	}
	DEBUG(ALI(18)<<header<<ALI(15)<<*packet<<(downstream ? "Down) " : "Up)   ")
			<<"RETRY BUFFER["<<retBufWriteP<<"] (FRP : "<<packet->FRP<<")");
	retBufWriteP = packet->FRP;
	//Send packet to standby buffer where the packet is ready to be transmitted
	packet->bufPopDelay = 1;
	linkRxTx.push_back(packet);
	//DEBUG(ALI(18)<<header<<ALI(15)<<*Buffers[0]<<(downstream ? "Down) " : "Up)   ")
	//			<<"SENDING packet to link "<<linkMasterID<<" (LK_"<<(downstream ? "D" : "U")<<linkMasterID<<")");
	Buffers.erase(Buffers.begin(), Buffers.begin()+packet->LNG);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rdi, %rbx
movq %rdx, 0x8(%rsp)
movl 0x238(%rdi), %ecx
xorl %eax, %eax
movl $0x0, %edx
cmpl $0x6, %ecx
jg 0x24a2d
leal 0x1(%rcx), %edx
movl %edx, 0x238(%rbx)
movl %ecx, %edx
movl %edx, 0x444(%r14)
movl 0x20c(%rbx), %ecx
movl %ecx, 0x44c(%r14)
leaq 0x16a74(%rip), %r13     # 0x3b4bc
movl (%r13), %ecx
cmpl %esi, %ecx
cmovlel %ecx, %eax
subl %eax, %esi
movl %esi, 0x448(%r14)
movb $0x0, 0x240(%rbx)
leaq 0x16a64(%rip), %rax     # 0x3b4cc
cmpb $0x1, (%rax)
jne 0x24a7c
movq %r14, %rdi
callq 0x28074
movl %eax, 0x438(%r14)
cmpl $0x2, 0x10(%r14)
je 0x24c35
movl 0x430(%r14), %eax
subl %eax, 0x208(%rbx)
leaq 0x169ed(%rip), %rax     # 0x3b488
cmpb $0x1, (%rax)
jne 0x24c35
leaq 0x169de(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x24c35
movq 0x16515(%rip), %rax     # 0x3afd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x12, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r15
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x24af2
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x164c7(%rip), %rdi     # 0x3afd0
callq 0x4340
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rcx
movq $0xf, 0x10(%r15,%rcx)
movq -0x18(%rax), %rax
leaq (%r15,%rax), %r12
cmpb $0x0, 0xe1(%r15,%rax)
jne 0x24b4a
movq %r12, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r12)
movb $0x20, 0xe0(%r12)
movq %r15, %rdi
movq %r14, %rsi
callq 0x28270
movq %rax, %r15
leaq 0xdc10(%rip), %rax      # 0x32778
leaq 0xdc10(%rip), %rsi      # 0x3277f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r15, %rdi
callq 0x4340
leaq 0xe072(%rip), %rsi      # 0x32c00
movl $0x12, %edx
movq %r15, %rdi
callq 0x4340
movl 0x430(%r14), %esi
movq %r15, %rdi
callq 0x41e0
movq %rax, %r15
leaq 0xe05f(%rip), %rsi      # 0x32c13
movl $0xe, %edx
movq %rax, %rdi
callq 0x4340
movl 0x208(%rbx), %esi
movq %r15, %rdi
callq 0x41e0
movq %rax, %r15
leaq 0xb721(%rip), %rsi      # 0x302fa
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
leaq 0x168cb(%rip), %rax     # 0x3b4b8
movl (%rax), %esi
movq %r15, %rdi
callq 0x4500
movq %rax, %r15
leaq 0xe8e0(%rip), %rsi      # 0x334e1
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl $0x468, %edi            # imm = 0x468
callq 0x42f0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x27f1e
movl 0x260(%rbx), %eax
movq 0x270(%rbx), %rcx
cmpq $0x0, (%rcx,%rax,8)
jne 0x24ec8
movq %r15, (%rcx,%rax,8)
movl 0x430(%r14), %ecx
cmpl $0x2, %ecx
jb 0x24ca6
movl (%r13), %edx
movl $0x1, %esi
xorl %edi, %edi
leal (%rax,%rsi), %r8d
cmpl %edx, %r8d
movl %edx, %r9d
cmovbl %edi, %r9d
subl %r9d, %r8d
movq 0x270(%rbx), %r9
movq $0x0, (%r9,%r8,8)
incl %esi
cmpl %ecx, %esi
jb 0x24c80
leaq 0x167db(%rip), %rax     # 0x3b488
cmpb $0x0, (%rax)
je 0x24e1f
leaq 0x167cc(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x24e1f
movq 0x16303(%rip), %rax     # 0x3afd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x12, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r15
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x24d04
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x162b5(%rip), %rdi     # 0x3afd0
callq 0x4340
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rcx
movq $0xf, 0x10(%r15,%rcx)
movq -0x18(%rax), %rax
leaq (%r15,%rax), %r12
cmpb $0x0, 0xe1(%r15,%rax)
jne 0x24d5c
movq %r12, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r12)
movb $0x20, 0xe0(%r12)
movq %r15, %rdi
movq %r14, %rsi
callq 0x28270
movq %rax, %r15
leaq 0xd9fe(%rip), %rax      # 0x32778
leaq 0xd9fe(%rip), %rsi      # 0x3277f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r15, %rdi
callq 0x4340
leaq 0xdebd(%rip), %rsi      # 0x32c5d
movl $0xd, %edx
movq %r15, %rdi
callq 0x4340
movl 0x260(%rbx), %esi
movq %r15, %rdi
callq 0x41e0
movq %rax, %r15
leaq 0xdea6(%rip), %rsi      # 0x32c6b
movl $0x9, %edx
movq %rax, %rdi
callq 0x4340
movl 0x448(%r14), %esi
movq %r15, %rdi
callq 0x41e0
movq %rax, %r15
leaq 0xe6f6(%rip), %rsi      # 0x334e1
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl 0x448(%r14), %eax
movl %eax, 0x260(%rbx)
movl $0x1, 0x14(%r14)
movq 0x1f0(%rbx), %rsi
cmpq 0x1f8(%rbx), %rsi
je 0x24e51
movq %r14, (%rsi)
addq $0x8, 0x1f0(%rbx)
jmp 0x24e68
leaq 0x1e8(%rbx), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x1a462
movq (%r14), %r14
movl 0x430(%r14), %eax
testq %rax, %rax
je 0x24eba
movq 0x1d0(%rbx), %r14
leaq (%r14,%rax,8), %r15
movq 0x1d8(%rbx), %rdx
subq %r15, %rdx
je 0x24ea2
movq %r14, %rdi
movq %r15, %rsi
callq 0x4480
movq 0x1d8(%rbx), %rax
movq %rax, %rcx
jmp 0x24ea8
movq %r15, %rax
movq %r15, %rcx
subq %r15, %rax
addq %rax, %r14
cmpq %r14, %rcx
je 0x24eba
movq %r14, 0x1d8(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x16121(%rip), %rdi     # 0x3aff0
leaq 0xb14c(%rip), %rsi      # 0x30022
callq 0x42e0
leaq 0xda0d(%rip), %rsi      # 0x328ef
movq %rax, %rdi
callq 0x42e0
leaq 0xb9a6(%rip), %rsi      # 0x30897
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0x4500
leaq 0xb134(%rip), %rsi      # 0x30041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0xdcfa(%rip), %rsi      # 0x32c22
movq %rax, %rdi
callq 0x42e0
movl 0x260(%rbx), %esi
movq %rax, %rdi
callq 0x43a0
leaq 0xdcf8(%rip), %rsi      # 0x32c3d
movq %rax, %rdi
callq 0x42e0
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0xe581(%rip), %rsi      # 0x334e1
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4540
nop