// File: /workspace/github_cpp_makefile_star2_O1/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 0x17976
leaq 0x19cc6(%rip), %rax     # 0x3bbd0
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 0x117ab(%rip), %rcx     # 0x336e8
movl $0x7, %r8d
movq %r14, %rdi
xorl %esi, %esi
callq 0x4440
leaq 0x12641(%rip), %rax     # 0x34595
leaq 0x10faf(%rip), %rsi     # 0x32f0a
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rax, %rsi
movq %r14, %rdi
callq 0x4580
leaq 0x58(%rbx), %rsi
leaq 0x28(%rsp), %rdi
callq 0x4450
leaq 0x124de(%rip), %rsi     # 0x34461
leaq 0x28(%rsp), %rdi
callq 0x4580
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x21fb3
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x21fba
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x4110
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x21ff9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4300
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22014
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 0x1a4a8(%rip), %r14     # 0x3c4e0
xorl %eax, %eax
subl (%r14), %eax
cvtsi2sd %eax, %xmm1
movsd 0x11687(%rip), %xmm0    # 0x336d0
callq 0x4520
addsd 0x11682(%rip), %xmm0    # 0x336d8
movsd %xmm0, 0x20(%rsp)
subl (%r14), %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd 0x11662(%rip), %xmm0    # 0x336d0
callq 0x4520
movsd 0x20(%rsp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1165b(%rip), %xmm1    # 0x336e0
movapd %xmm2, %xmm0
callq 0x4520
movapd %xmm0, %xmm1
movsd 0xf016(%rip), %xmm0     # 0x310b0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
divsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x220b6
sqrtsd %xmm0, %xmm0
jmp 0x220bb
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 (%rsp), %rdi
cmpq %r15, %rdi
je 0x220ef
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4300
jmp 0x220ef
movq %rax, %r14
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22111
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4300
jmp 0x22111
jmp 0x2210e
movq %rax, %r14
movq %rbx, %rdi
callq 0x17d50
movq %r14, %rdi
callq 0x4540
nop