// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]eph_converter/src/B2bDecoder.cpp
// Function: B2b::m_genclock()
void B2b::m_genclock(){
	FILE* fp = NULL;
	char filename[128] = {0};
	int mjd,iyear,imon,iday,ih,im,gweek,gd;
	double sod,dintv = 30,dt,dtmin,dtlimit =120,xclk,xclk_out,dclk,c[3],sec;
	/******** generate the ephemeris here *****************/
	cout << "begin to recover clock ..." << endl;
	mjd = mjd0;
	sod = sod0;
	sod = ((int)(sod / dintv)) * dintv; /**force it to the epoch**/
	mjd2date(mjd,sod,&iyear,&imon,&iday,&ih,&im,&sec);
	gpsweek(iyear,imon,iday,&gweek,&gd);
	sprintf(filename,"cov%04d%d.clk",gweek,gd);
	if(!(fp = fopen(filename,"w"))){cout << "can't open file " << filename << " to write!" << endl;exit(1);}
	m_wtclkheader(fp);
	while(true){
		mjd2date(mjd,sod,&iyear,&imon,&iday,&ih,&im,&sec);
		for (auto &cprn : cprn_list) {
			/*************get the minus ssr*****************/
			dtmin = 9e9;
			clk *ssr_selected = nullptr;
			for (auto &ssr : CLK_ALL) {
				dt = (ssr.mjd - mjd) * 86400.0 + ssr.sod - sod;
				if (dtmin > fabs(dt)) {
					dtmin = fabs(dt);
					ssr_selected = &ssr;
				}
			}
			if (dtmin > dtlimit || ssr_selected == nullptr)
				continue;
			/*************request for the brdm *****************/
			if (ssr_selected->CLK.find(cprn) == ssr_selected->CLK.end())
				continue;
			if (!(nav.v_readClk(cprn.c_str(),mjd,sod,&xclk_out,&ssr_selected->CLK[cprn].iode))){
				cout << "ssr do not match ephemeris for " << cprn << " " << mjd << " " << sod << endl;
				continue;
			}
			/*************update the eph here *****************/
			memcpy(c,ssr_selected->CLK[cprn].clk,sizeof(double) * 3);
			dclk = c[0] + dtmin * (c[1] + dtmin * c[2]);
			xclk = xclk_out - dclk / VEL_LIGHT;
			fprintf(fp,"AS %3s%6d%3d%3d%3d%3d%10.6lf%3d%22.12e\r\n", cprn.c_str(), iyear, imon, iday, ih, im, sec, 1,xclk);
		}
		timinc(mjd,sod,dintv,&mjd,&sod);
		if( (mjd - mjd1) * 86400.0 + sod - sod1 >= 0.0)
			break;
	}
	fclose(fp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0x110(%rbp), %r14
movaps %xmm0, 0x70(%r14)
movaps %xmm0, 0x60(%r14)
movaps %xmm0, 0x50(%r14)
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movq 0xde2d(%rip), %r15      # 0x11fd8
leaq 0x901c(%rip), %rsi      # 0xd1ce
movl $0x1a, %edx
movq %r15, %rdi
callq 0x3330
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movl (%rbx), %r12d
movl %r12d, -0x2c(%rbp)
movsd 0x10(%rbx), %xmm0
movsd 0x8e26(%rip), %xmm1     # 0xd020
divsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, (%rsp)
leaq -0x48(%rbp), %r15
leaq -0x44(%rbp), %r13
leaq -0x30(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
movl %r12d, %edi
movapd %xmm0, -0x70(%rbp)
movq %r15, %rsi
movq %r13, %rdx
callq 0xbdb1
movl (%r15), %edi
movl (%r13), %esi
leaq -0x30(%rbp), %rax
movl (%rax), %edx
leaq -0x90(%rbp), %r15
leaq -0x8c(%rbp), %r13
movq %r15, %rcx
movq %r13, %r8
callq 0xaa75
movl (%r15), %edx
movl (%r13), %ecx
leaq 0x8f77(%rip), %rsi      # 0xd1e9
movq %r14, %rdi
xorl %eax, %eax
callq 0x3080
leaq 0x8ee1(%rip), %rsi      # 0xd164
movq %r14, %rdi
callq 0x3350
testq %rax, %rax
je 0x459b
movq %rax, %r14
leaq 0x9022(%rip), %rdi      # 0xd2c0
movq %rax, %rsi
callq 0x3300
movq %r14, -0x50(%rbp)
movq %r14, %rdi
callq 0x3340
leaq 0x20(%rbx), %rax
movq %rax, -0x78(%rbp)
movapd -0x70(%rbp), %xmm0
leaq -0x60(%rbp), %rax
movq %rax, (%rsp)
movl %r12d, %edi
leaq -0x48(%rbp), %rsi
leaq -0x44(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
callq 0xbdb1
movsd 0x8d45(%rip), %xmm2     # 0xd030
movq 0xd78(%rbx), %r12
movq 0xd80(%rbx), %r15
cmpq %r15, %r12
movapd 0x8d7c(%rip), %xmm3     # 0xd080
movq %r15, -0x58(%rbp)
je 0x452a
movq 0xd60(%rbx), %rax
movq 0xd68(%rbx), %rcx
cmpq %rcx, %rax
je 0x451d
movl -0x2c(%rbp), %edx
movsd -0x38(%rbp), %xmm0
movsd 0x8cf3(%rip), %xmm4     # 0xd028
xorl %r14d, %r14d
movapd %xmm4, %xmm1
movl (%rax), %esi
subl %edx, %esi
xorps %xmm4, %xmm4
cvtsi2sd %esi, %xmm4
mulsd %xmm2, %xmm4
addsd 0x8(%rax), %xmm4
subsd %xmm0, %xmm4
andpd %xmm3, %xmm4
ucomisd %xmm4, %xmm1
cmovaq %rax, %r14
minsd %xmm1, %xmm4
addq $0x40, %rax
cmpq %rcx, %rax
jne 0x4338
movapd %xmm4, -0x70(%rbp)
ucomisd 0x8cbe(%rip), %xmm4     # 0xd038
seta %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x451d
leaq 0x10(%r14), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x70ce
movapd 0x8cde(%rip), %xmm3     # 0xd080
movsd 0x8c86(%rip), %xmm2     # 0xd030
addq $0x18, %r14
cmpq %r14, %rax
je 0x451d
movq (%r12), %r14
movl -0x2c(%rbp), %r15d
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x5a60
leaq 0x4(%rax), %r8
movq -0x78(%rbp), %rdi
movq %r14, %rsi
movl %r15d, %edx
movsd -0x80(%rbp), %xmm0
leaq -0x88(%rbp), %rcx
callq 0xa862
testl %eax, %eax
je 0x446e
movq %r13, %rdi
movq %r12, %rsi
callq 0x5a60
movsd 0x18(%rax), %xmm1
movapd -0x70(%rbp), %xmm0
mulsd %xmm0, %xmm1
addsd 0x10(%rax), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rax), %xmm1
divsd 0x8c1a(%rip), %xmm1     # 0xd040
addsd -0x88(%rbp), %xmm1
movq (%r12), %rdx
movl -0x48(%rbp), %ecx
movl -0x44(%rbp), %r8d
movl -0x30(%rbp), %r9d
movl -0x40(%rbp), %eax
movl -0x3c(%rbp), %esi
movsd -0x60(%rbp), %xmm0
movl %esi, 0x8(%rsp)
movl %eax, (%rsp)
movl $0x1, 0x10(%rsp)
movq -0x50(%rbp), %rdi
leaq 0x8d95(%rip), %rsi      # 0xd1f7
movb $0x2, %al
callq 0x33e0
jmp 0x4509
movl $0x1f, %edx
movq 0xdb5e(%rip), %r14      # 0x11fd8
movq %r14, %rdi
leaq 0x8d2a(%rip), %rsi      # 0xd1ae
callq 0x3330
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x3330
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9bbe(%rip), %r15      # 0xe06a
movq %r15, %rsi
callq 0x3330
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x3480
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x3330
movsd -0x38(%rbp), %xmm0
movq %r14, %rdi
callq 0x3440
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movsd 0x8b1f(%rip), %xmm2     # 0xd030
movapd 0x8b67(%rip), %xmm3     # 0xd080
movq -0x58(%rbp), %r15
addq $0x20, %r12
cmpq %r15, %r12
jne 0x430e
movl -0x2c(%rbp), %edi
movsd -0x38(%rbp), %xmm0
movsd 0x8ae6(%rip), %xmm1     # 0xd020
leaq -0x2c(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0xb5a9
movsd 0x8ae1(%rip), %xmm1     # 0xd030
movl -0x2c(%rbp), %r12d
movl %r12d, %eax
subl 0x4(%rbx), %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
movsd -0x38(%rbp), %xmm0
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
subsd 0x18(%rbx), %xmm2
ucomisd 0x8ace(%rip), %xmm2     # 0xd048
jb 0x42bf
movq -0x50(%rbp), %rdi
callq 0x32c0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xda36(%rip), %rdi      # 0x11fd8
leaq 0x8b1a(%rip), %rsi      # 0xd0c3
callq 0x32b0
leaq -0x110(%rbp), %rsi
movq %rax, %rdi
callq 0x32b0
leaq 0x8ba2(%rip), %rsi      # 0xd166
movq %rax, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3170
movl $0x1, %edi
callq 0x3370