// File: /workspace/github_cpp_makefile_star2_O3/estwings57[P]CasHMC/sources/Link.cpp
// Function: CasHMC::Link::Link(std::basic_ofstream<char, std::char_traits<char>>&, std::basic_ofstream<char, std::char_traits<char>>&, unsigned int, bool, CasHMC::TranStatistic*)
Link::Link(ofstream &debugOut_, ofstream &stateOut_, unsigned id, bool down, TranStatistic *statisP):
	SimulatorObject(debugOut_, stateOut_),
	linkID(id),
	downstream(down),
	statis(statisP)
{
	classID << linkID;
	header = "   (LK_";
	header += downstream ? "D" : "U";
	header += classID.str() + ")";
	
	linkMasterP = NULL;
	linkSlaveP = NULL;
	inFlightPacket = NULL;
	inFlightCountdown = 0;
	
	//The probability of at least one bit error
	//  (pow(10, -LINK_BER) - 1)/pow(10, -LINK_BER) : Probability of no error in one bit
	//  (1 - pow((pow(10, -LINK_BER) - 1)/pow(10, -LINK_BER), 128)) : Probability of at least one bit error in 128 bits
	//  errorProba is square root of bits size per one bit error, because errorProba is over than variable capacity.
	//  Link error will be calculated two times by errorProba respectively
	errorProba = sqrt(1 / (1 - pow((pow(10, -LINK_BER) - 1)/pow(10, -LINK_BER), 128)));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %r9, %r14
movl %r8d, %ebp
movl %ecx, %r15d
movq %rdi, %rbx
callq 0x16fc6
leaq 0x193ae(%rip), %rax     # 0x3abd0
movq %rax, (%rbx)
movl %r15d, 0x1c8(%rbx)
movb %bpl, 0x1cc(%rbx)
movq %r14, 0x1e0(%rbx)
leaq 0x50(%rbx), %rdi
movl %r15d, %esi
callq 0x41e0
leaq 0x20(%rbx), %r14
movq 0x28(%rbx), %rdx
leaq 0x10f1b(%rip), %rcx     # 0x32770
movl $0x7, %r8d
movq %r14, %rdi
xorl %esi, %esi
callq 0x4440
leaq 0x11da9(%rip), %rax     # 0x33615
leaq 0x10707(%rip), %rsi     # 0x31f7a
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movq %r14, %rdi
callq 0x4580
leaq 0x58(%rbx), %rsi
leaq 0x28(%rsp), %rdi
callq 0x4450
leaq 0x11c46(%rip), %rsi     # 0x334e1
leaq 0x28(%rsp), %rdi
callq 0x4580
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x218cc
movq %rsi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x218d6
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq %r15, %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x4110
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x2190d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4300
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x21928
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4300
movq $0x0, 0x1d8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x1e8(%rbx)
xorl %ebp, %ebp
movl %ebp, 0x1f8(%rbx)
leaq 0x19b94(%rip), %r14     # 0x3b4e0
xorl %eax, %eax
subl (%r14), %eax
cvtsi2sd %eax, %xmm1
movsd 0x10dfb(%rip), %xmm0    # 0x32758
callq 0x4520
addsd 0x10df6(%rip), %xmm0    # 0x32760
movsd %xmm0, (%rsp)
subl (%r14), %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd 0x10dd7(%rip), %xmm0    # 0x32758
callq 0x4520
movsd (%rsp), %xmm2
divsd %xmm0, %xmm2
movsd 0x10dd1(%rip), %xmm1    # 0x32768
movapd %xmm2, %xmm0
callq 0x4520
movapd %xmm0, %xmm1
movsd 0xe704(%rip), %xmm0     # 0x300b0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
divsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x219c8
sqrtsd %xmm0, %xmm0
jmp 0x219cd
callq 0x4250
cvttsd2si %xmm0, %rax
movl %eax, 0x1d0(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x21a02
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4300
jmp 0x21a02
movq %rax, %r14
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x21a24
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4300
jmp 0x21a24
jmp 0x21a21
movq %rax, %r14
movq %rbx, %rdi
callq 0x175ae
movq %r14, %rdi
callq 0x4540