// File: /workspace/github_cpp_makefile_star2_O1/estwings57[P]CasHMC/sources/Link.cpp
// Function: CasHMC::Link::Update(bool)
void Link::Update(bool lastUpdate)
{
	//Transmit packet from buffer
	if(linkMasterP->linkRxTx.size()>0 && linkMasterP->linkRxTx[0]->bufPopDelay==0 && inFlightPacket==NULL) {
	//	if(linkMasterP->currentState == ACTIVE
	//	|| linkMasterP->currentState == LINK_RETRY
	//	|| (linkMasterP->currentState == START_RETRY && linkMasterP->linkRxTx[0]->CMD == IRTRY && linkMasterP->linkRxTx[0]->FRP == 1)
	//	|| ((linkMasterP->currentState == WAIT || linkMasterP->currentState == SLEEP) && linkMasterP->linkRxTx[0]->CMD == QUIET)
	//	|| linkMasterP->linkRxTx[0]->CMD == NULL_) {
			inFlightPacket = linkMasterP->linkRxTx[0];
			UpdateStatistic(inFlightPacket);
			inFlightCountdown = (inFlightPacket->LNG * 128) / LINK_WIDTH;
			DEBUG(ALI(18)<<header<<ALI(15)<<*inFlightPacket<<(downstream ? "Down) " : "Up)   ")<<"START transmission packet");
			linkMasterP->linkRxTx.erase(linkMasterP->linkRxTx.begin());
	//	}
	}
	
	if(inFlightCountdown > 0) {
		inFlightCountdown--;
		//Packet transmission done
		if(inFlightCountdown == 0) {
			NoisePacket(inFlightPacket);
			DEBUG(ALI(18)<<header<<ALI(15)<<*inFlightPacket<<(downstream ? "Down) " : "Up)   ")<<"DONE transmission packet");
			inFlightPacket->bufPopDelay = 1;
			linkSlaveP->linkRxTx.push_back(inFlightPacket);
			if(inFlightPacket->packetType == RESPONSE)
				inFlightPacket->trace->linkFullLat = linkSlaveP->currentClockCycle - inFlightPacket->trace->linkTransmitTime;
			inFlightPacket = NULL;
		}
		else if(lastUpdate) {
			DEBUG(ALI(18)<<header<<ALI(15)<<*inFlightPacket<<(downstream ? "Down) " : "Up)   ")<<"Link transmiting countdown : "<<ALI(2)<<inFlightCountdown);
		}
	}
	
	if(lastUpdate && linkMasterP->linkRxTx.size()>0) {
		for(int i=0; i<linkMasterP->linkRxTx.size(); i++) {
			linkMasterP->linkRxTx[i]->bufPopDelay = (linkMasterP->linkRxTx[i]->bufPopDelay>0) ? linkMasterP->linkRxTx[i]->bufPopDelay-1 : 0;
		}
	}
	Step();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq 0x1d8(%rdi), %rcx
movq 0x1e8(%rcx), %rax
cmpq %rax, 0x1f0(%rcx)
je 0x2231e
movq (%rax), %rsi
cmpl $0x0, 0x14(%rsi)
jne 0x2231e
cmpq $0x0, 0x1f0(%rbx)
jne 0x2231e
movq %rsi, 0x1f0(%rbx)
movq %rbx, %rdi
callq 0x226f4
movq 0x1f0(%rbx), %rax
movl 0x430(%rax), %eax
shll $0x7, %eax
leaq 0x1a304(%rip), %rcx     # 0x3c4ac
xorl %edx, %edx
divl (%rcx)
movl %eax, 0x1f8(%rbx)
leaq 0x1a2cf(%rip), %rax     # 0x3c488
cmpb $0x1, (%rax)
jne 0x222f0
leaq 0x1a2c0(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x222f0
movq 0x19df7(%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 0x22217
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 0x19da2(%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 0x22275
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x1f0(%rbx), %rsi
movq %r14, %rdi
callq 0x28bbe
movq %rax, %r14
leaq 0x1145a(%rip), %rax     # 0x336f0
leaq 0x1145a(%rip), %rsi     # 0x336f7
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0x11442(%rip), %rsi     # 0x336fe
movl $0x19, %edx
movq %r14, %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 0x1d8(%rbx), %r14
movq 0x1e8(%r14), %rdi
movq 0x1f0(%r14), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x22316
subq %rsi, %rdx
callq 0x4480
addq $-0x8, 0x1f0(%r14)
movl 0x1f8(%rbx), %eax
testl %eax, %eax
je 0x22697
decl %eax
movl %eax, 0x1f8(%rbx)
je 0x224de
testb %bpl, %bpl
je 0x226e5
leaq 0x1a13e(%rip), %rax     # 0x3c488
cmpb $0x1, (%rax)
jne 0x22697
leaq 0x1a12f(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x22697
movq 0x19c66(%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 0x223a8
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 0x19c11(%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 0x22406
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x1f0(%rbx), %rsi
movq %r14, %rdi
callq 0x28bbe
movq %rax, %r14
leaq 0x112c9(%rip), %rax     # 0x336f0
leaq 0x112c9(%rip), %rsi     # 0x336f7
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0x112e4(%rip), %rsi     # 0x33731
movl $0x1d, %edx
movq %r14, %rdi
callq 0x4340
movq (%r14), %rax
movq -0x18(%rax), %rcx
movq $0x2, 0x10(%r14,%rcx)
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0xe1(%r14,%rax)
jne 0x22499
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movl 0x1f8(%rbx), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
movq (%rax), %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
jmp 0x22697
movq 0x1f0(%rbx), %rsi
movq %rbx, %rdi
callq 0x22908
leaq 0x19f94(%rip), %rax     # 0x3c488
cmpb $0x1, (%rax)
jne 0x2262b
leaq 0x19f85(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x2262b
movq 0x19abc(%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 0x22552
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 0x19a67(%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 0x225b0
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x1f0(%rbx), %rsi
movq %r14, %rdi
callq 0x28bbe
movq %rax, %r14
leaq 0x1111f(%rip), %rax     # 0x336f0
leaq 0x1111f(%rip), %rsi     # 0x336f7
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0x11121(%rip), %rsi     # 0x33718
movl $0x18, %edx
movq %r14, %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
leaq 0x1f0(%rbx), %r14
movq 0x1f0(%rbx), %rax
movl $0x1, 0x14(%rax)
movq 0x1e8(%rbx), %rdi
movq 0x1f0(%rdi), %rsi
cmpq 0x1f8(%rdi), %rsi
je 0x22664
movq %rax, (%rsi)
addq $0x8, 0x1f0(%rdi)
jmp 0x22673
addq $0x1e8, %rdi            # imm = 0x1E8
movq %r14, %rdx
callq 0x1ac5a
movq (%r14), %rax
cmpl $0x1, 0x10(%rax)
jne 0x22690
movq 0x1e8(%rbx), %rcx
movl 0x8(%rcx), %ecx
movq 0x8(%rax), %rax
subl 0x10(%rax), %ecx
movl %ecx, 0x14(%rax)
movq $0x0, (%r14)
testb %bpl, %bpl
je 0x226e5
movq 0x1d8(%rbx), %rcx
movq 0x1e8(%rcx), %rax
movq 0x1f0(%rcx), %rcx
subq %rax, %rcx
je 0x226e5
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
movl 0x14(%rdi), %r8d
leal -0x1(%r8), %r9d
testl %r8d, %r8d
cmovlel %edx, %r9d
movl %r9d, 0x14(%rdi)
incq %rsi
cmpq %rsi, %rcx
jne 0x226c6
incq 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq