// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rdx, (%rsp)
movl 0x238(%rdi), %ecx
xorl %eax, %eax
movl $0x0, %edi
cmpl $0x6, %ecx
jg 0x251f4
leal 0x1(%rcx), %edi
movl %edi, 0x238(%rbx)
movl %ecx, %edi
movl %edi, 0x444(%rdx)
movl 0x20c(%rbx), %ecx
movl %ecx, 0x44c(%rdx)
leaq 0x172af(%rip), %r12     # 0x3c4bc
movl (%r12), %ecx
cmpl %esi, %ecx
cmovlel %ecx, %eax
subl %eax, %esi
movl %esi, 0x448(%rdx)
movb $0x0, 0x240(%rbx)
leaq 0x172a0(%rip), %rax     # 0x3c4cc
cmpb $0x1, (%rax)
jne 0x25243
movq %rdx, %rdi
callq 0x2895c
movq (%rsp), %rcx
movl %eax, 0x438(%rcx)
movq (%rsp), %rax
cmpl $0x2, 0x10(%rax)
je 0x2540e
movl 0x430(%rax), %eax
subl %eax, 0x208(%rbx)
leaq 0x17224(%rip), %rax     # 0x3c488
cmpb $0x1, (%rax)
jne 0x2540e
leaq 0x17215(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x2540e
movq 0x16d4c(%rip), %rax     # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x12, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x252c2
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x16cf7(%rip), %rdi     # 0x3bfd0
callq 0x4340
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rcx
movq $0xf, 0x10(%r14,%rcx)
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0xe1(%r14,%rax)
jne 0x25320
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x28bbe
movq %rax, %r14
leaq 0xe3b2(%rip), %rax      # 0x336f0
leaq 0xe3b2(%rip), %rsi      # 0x336f7
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0xe820(%rip), %rsi      # 0x33b84
movl $0x12, %edx
movq %r14, %rdi
callq 0x4340
movq (%rsp), %rax
movl 0x430(%rax), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0xe80a(%rip), %rsi      # 0x33b97
movl $0xe, %edx
movq %rax, %rdi
callq 0x4340
movl 0x208(%rbx), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0xbee8(%rip), %rsi      # 0x3129a
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
leaq 0x170f2(%rip), %rax     # 0x3c4b8
movl (%rax), %esi
movq %r14, %rdi
callq 0x4500
movq %rax, %r14
leaq 0xf087(%rip), %rsi      # 0x34461
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl $0x468, %edi            # imm = 0x468
callq 0x42f0
movq %rax, %r14
movq (%rsp), %rsi
movq %rax, %rdi
callq 0x2879e
movl 0x260(%rbx), %eax
movq 0x270(%rbx), %rcx
cmpq $0x0, (%rcx,%rax,8)
jne 0x256ac
movq %r14, (%rcx,%rax,8)
movq (%rsp), %rcx
cmpl $0x2, 0x430(%rcx)
jb 0x25487
movl (%r12), %ecx
movl $0x1, %edx
xorl %esi, %esi
leal (%rax,%rdx), %edi
cmpl %ecx, %edi
movl %ecx, %r8d
cmovbl %esi, %r8d
subl %r8d, %edi
movq 0x270(%rbx), %r8
movq $0x0, (%r8,%rdi,8)
incl %edx
movq (%rsp), %rdi
cmpl 0x430(%rdi), %edx
jb 0x2545b
leaq 0x16ffa(%rip), %rax     # 0x3c488
cmpb $0x0, (%rax)
je 0x25610
leaq 0x16feb(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x25610
movq 0x16b22(%rip), %rax     # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x12, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x254ec
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x16acd(%rip), %rdi     # 0x3bfd0
callq 0x4340
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rcx
movq $0xf, 0x10(%r14,%rcx)
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0xe1(%r14,%rax)
jne 0x2554a
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x28bbe
movq %rax, %r14
leaq 0xe188(%rip), %rax      # 0x336f0
leaq 0xe188(%rip), %rsi      # 0x336f7
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0xe653(%rip), %rsi      # 0x33be1
movl $0xd, %edx
movq %r14, %rdi
callq 0x4340
movl 0x260(%rbx), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0xe63c(%rip), %rsi      # 0x33bef
movl $0x9, %edx
movq %rax, %rdi
callq 0x4340
movq (%rsp), %rax
movl 0x448(%rax), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0xee85(%rip), %rsi      # 0x34461
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq (%rsp), %rax
movl 0x448(%rax), %ecx
movl %ecx, 0x260(%rbx)
movl $0x1, 0x14(%rax)
movq 0x1f0(%rbx), %rsi
cmpq 0x1f8(%rbx), %rsi
je 0x25644
movq %rax, (%rsi)
addq $0x8, 0x1f0(%rbx)
jmp 0x25653
leaq 0x1e8(%rbx), %rdi
movq %rsp, %rdx
callq 0x1ac5a
movq (%rsp), %rax
movl 0x430(%rax), %eax
testq %rax, %rax
je 0x256a0
movq 0x1d0(%rbx), %r14
leaq (%r14,%rax,8), %r15
movq 0x1d8(%rbx), %rdx
subq %r15, %rdx
je 0x25684
movq %r14, %rdi
movq %r15, %rsi
callq 0x4480
movq 0x1d8(%rbx), %rax
movq %rax, %rcx
subq %r15, %rcx
addq %rcx, %r14
cmpq %r14, %rax
je 0x256a0
movq %r14, 0x1d8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x1693d(%rip), %rdi     # 0x3bff0
leaq 0xb968(%rip), %rsi      # 0x31022
callq 0x42e0
leaq 0xe1ad(%rip), %rsi      # 0x33873
movq %rax, %rdi
callq 0x42e0
leaq 0xc162(%rip), %rsi      # 0x31837
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0x4500
leaq 0xb950(%rip), %rsi      # 0x31041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0xe49a(%rip), %rsi      # 0x33ba6
movq %rax, %rdi
callq 0x42e0
movl 0x260(%rbx), %esi
movq %rax, %rdi
callq 0x43a0
leaq 0xe498(%rip), %rsi      # 0x33bc1
movq %rax, %rdi
callq 0x42e0
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0xed1d(%rip), %rsi      # 0x34461
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r14, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4540
nop