// File: /workspace/github_cpp_makefile_star2_O3/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 0x21c2c
movq (%rax), %rsi
cmpl $0x0, 0x14(%rsi)
jne 0x21c2c
cmpq $0x0, 0x1f0(%rbx)
jne 0x21c2c
movq %rsi, 0x1f0(%rbx)
movq %rbx, %rdi
callq 0x21fe0
movq 0x1f0(%rbx), %rax
movl 0x430(%rax), %eax
shll $0x7, %eax
leaq 0x199f2(%rip), %rcx     # 0x3b4ac
xorl %edx, %edx
divl (%rcx)
movl %eax, 0x1f8(%rbx)
leaq 0x199bd(%rip), %rax     # 0x3b488
cmpb $0x1, (%rax)
jne 0x21bf4
leaq 0x199ae(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x21bf4
movq 0x194e5(%rip), %rax     # 0x3afd0
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 0x21b22
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x19497(%rip), %rdi     # 0x3afd0
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 0x21b79
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x1f0(%rbx), %rsi
movq %r14, %rdi
callq 0x28270
movq %rax, %r14
leaq 0x10bde(%rip), %rax     # 0x32778
leaq 0x10bde(%rip), %rsi     # 0x3277f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0x10bc6(%rip), %rsi     # 0x32786
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 0x21c21
subq %rsi, %rdx
callq 0x4480
movq 0x1f0(%r14), %rdx
addq $-0x8, %rdx
movq %rdx, 0x1f0(%r14)
movl 0x1f8(%rbx), %eax
testl %eax, %eax
je 0x21f82
decl %eax
movl %eax, 0x1f8(%rbx)
je 0x21dd7
testb %bpl, %bpl
je 0x21fd0
leaq 0x19830(%rip), %rax     # 0x3b488
cmpb $0x1, (%rax)
jne 0x21f87
leaq 0x19821(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x21f87
movq 0x19358(%rip), %rax     # 0x3afd0
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 0x21caf
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1930a(%rip), %rdi     # 0x3afd0
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 0x21d06
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x1f0(%rbx), %rsi
movq %r14, %rdi
callq 0x28270
movq %rax, %r14
leaq 0x10a51(%rip), %rax     # 0x32778
leaq 0x10a51(%rip), %rsi     # 0x3277f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0x10a6c(%rip), %rsi     # 0x327b9
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 0x21d92
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
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 0x21f87
movq 0x1f0(%rbx), %rsi
movq %rbx, %rdi
callq 0x221da
leaq 0x1969b(%rip), %rax     # 0x3b488
cmpb $0x1, (%rax)
jne 0x21f16
leaq 0x1968c(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x21f16
movq 0x191c3(%rip), %rax     # 0x3afd0
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 0x21e44
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x19175(%rip), %rdi     # 0x3afd0
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 0x21e9b
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x1f0(%rbx), %rsi
movq %r14, %rdi
callq 0x28270
movq %rax, %r14
leaq 0x108bc(%rip), %rax     # 0x32778
leaq 0x108bc(%rip), %rsi     # 0x3277f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movl $0x6, %edx
movq %r14, %rdi
callq 0x4340
leaq 0x108be(%rip), %rsi     # 0x327a0
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 0x21f4f
movq %rax, (%rsi)
addq $0x8, 0x1f0(%rdi)
jmp 0x21f5e
addq $0x1e8, %rdi            # imm = 0x1E8
movq %r14, %rdx
callq 0x1a462
movq (%r14), %rax
cmpl $0x1, 0x10(%rax)
jne 0x21f7b
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 0x21fd0
movq 0x1d8(%rbx), %rcx
movq 0x1e8(%rcx), %rax
movq 0x1f0(%rcx), %rcx
subq %rax, %rcx
je 0x21fd0
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 0x21fb1
incq 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop