// File: /workspace/github_cpp_makefile_star2_O2/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 0x198bf
movq (%rax), %rsi
cmpl $0x0, 0x14(%rsi)
jne 0x198bf
cmpq $0x0, 0x1f0(%rbx)
jne 0x198bf
movq %rsi, 0x1f0(%rbx)
movq %rbx, %rdi
callq 0x19b24
movq 0x1f0(%rbx), %rax
movl 0x430(%rax), %eax
shll $0x7, %eax
leaq 0x17cc2(%rip), %rcx     # 0x314ac
xorl %edx, %edx
divl (%rcx)
movl %eax, 0x1f8(%rbx)
leaq 0x17c8d(%rip), %rax     # 0x31488
cmpb $0x1, (%rax)
jne 0x198a5
leaq 0x17c7e(%rip), %rax     # 0x31489
cmpb $0x0, (%rax)
jne 0x198a5
movq 0x177b5(%rip), %rdi     # 0x30fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x12, 0x10(%rdi,%rax)
pushq $0x20
popq %r14
movl %r14d, %esi
callq 0x4440
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0xf, 0x10(%rax,%rcx)
movq %rax, %rdi
movl %r14d, %esi
callq 0x4440
movq 0x1f0(%rbx), %rsi
movq %rax, %rdi
callq 0x1e2c8
leaq 0xcef4(%rip), %rcx      # 0x26768
leaq 0xcef4(%rip), %rsi      # 0x2676f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x4300
leaq 0xcee1(%rip), %rsi      # 0x26776
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
movq 0x1d8(%rbx), %rdi
movq 0x1e8(%rdi), %rsi
addq $0x1e8, %rdi            # imm = 0x1E8
callq 0x13408
movl 0x1f8(%rbx), %eax
testl %eax, %eax
je 0x19acd
decl %eax
movl %eax, 0x1f8(%rbx)
je 0x199bf
testb %bpl, %bpl
je 0x19b15
leaq 0x17b9d(%rip), %rax     # 0x31488
cmpb $0x1, (%rax)
jne 0x19ad2
leaq 0x17b8e(%rip), %rax     # 0x31489
cmpb $0x0, (%rax)
jne 0x19ad2
movq 0x176c5(%rip), %rdi     # 0x30fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x12, 0x10(%rdi,%rax)
pushq $0x20
popq %rbp
movl %ebp, %esi
callq 0x4440
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0xf, 0x10(%rax,%rcx)
movq %rax, %rdi
movl %ebp, %esi
callq 0x4440
movq 0x1f0(%rbx), %rsi
movq %rax, %rdi
callq 0x1e2c8
leaq 0xce07(%rip), %rcx      # 0x26768
leaq 0xce07(%rip), %rsi      # 0x2676f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x4300
leaq 0xce27(%rip), %rsi      # 0x267a9
movq %rax, %rdi
callq 0x4300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x2, 0x10(%rax,%rcx)
movq %rax, %rdi
movl %ebp, %esi
callq 0x4440
movl 0x1f8(%rbx), %esi
movq %rax, %rdi
callq 0x4210
movq %rax, %rdi
callq 0x4180
jmp 0x19ad2
leaq 0x1f0(%rbx), %r14
movq 0x1f0(%rbx), %rsi
movq %rbx, %rdi
callq 0x19d1e
leaq 0x17aac(%rip), %rax     # 0x31488
cmpb $0x1, (%rax)
jne 0x19a86
leaq 0x17a9d(%rip), %rax     # 0x31489
cmpb $0x0, (%rax)
jne 0x19a86
movq 0x175d4(%rip), %rdi     # 0x30fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x12, 0x10(%rdi,%rax)
pushq $0x20
popq %r15
movl %r15d, %esi
callq 0x4440
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0xf, 0x10(%rax,%rcx)
movq %rax, %rdi
movl %r15d, %esi
callq 0x4440
movq 0x1f0(%rbx), %rsi
movq %rax, %rdi
callq 0x1e2c8
leaq 0xcd13(%rip), %rcx      # 0x26768
leaq 0xcd13(%rip), %rsi      # 0x2676f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x4300
leaq 0xcd1a(%rip), %rsi      # 0x26790
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
movq 0x1f0(%rbx), %rax
movl $0x1, 0x14(%rax)
movl $0x1e8, %edi            # imm = 0x1E8
addq 0x1e8(%rbx), %rdi
movq %r14, %rsi
callq 0x13442
movq 0x1f0(%rbx), %rax
cmpl $0x1, 0x10(%rax)
jne 0x19ac9
movq 0x1e8(%rbx), %rcx
movl 0x8(%rcx), %ecx
movq 0x8(%rax), %rax
subl 0x10(%rax), %ecx
movl %ecx, 0x14(%rax)
andq $0x0, (%r14)
testb %bpl, %bpl
je 0x19b15
movq 0x1d8(%rbx), %rcx
movq 0x1e8(%rcx), %rax
movq 0x1f0(%rcx), %rcx
subq %rax, %rcx
je 0x19b15
sarq $0x3, %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x19b15
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
jmp 0x19af4
incq 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq