// File: /workspace/github_cpp_makefile_star2_O2/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 0xe157(%rip), %rdi      # 0x11fd8
leaq 0x8336(%rip), %rsi      # 0xc1be
callq 0x3280
movq %rax, %rdi
callq 0x3170
movl (%rbx), %r12d
movl %r12d, -0x2c(%rbp)
movsd 0x10(%rbx), %xmm0
movsd 0x8177(%rip), %xmm1     # 0xc020
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 0xb567
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 0xa599
movl (%r15), %edx
movl (%r13), %ecx
leaq 0x82b8(%rip), %rsi      # 0xc1d9
movq %r14, %rdi
xorl %eax, %eax
callq 0x3070
leaq 0x8222(%rip), %rsi      # 0xc154
movq %r14, %rdi
callq 0x3300
testq %rax, %rax
je 0x41c2
movq %rax, -0x50(%rbp)
movq %rax, %rsi
callq 0x503a
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 0xb567
movq 0xd78(%rbx), %r12
movq 0xd80(%rbx), %r15
movq %r15, -0x58(%rbp)
cmpq %r15, %r12
je 0x4154
movq 0xd60(%rbx), %rax
movq 0xd68(%rbx), %rcx
movl -0x2c(%rbp), %edx
movsd -0x38(%rbp), %xmm0
xorl %r14d, %r14d
movsd 0x806c(%rip), %xmm4     # 0xc028
movsd 0x806c(%rip), %xmm2     # 0xc030
movapd 0x80b4(%rip), %xmm3     # 0xc080
cmpq %rcx, %rax
je 0x4000
movl (%rax), %esi
subl %edx, %esi
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
addsd 0x8(%rax), %xmm1
subsd %xmm0, %xmm1
andpd %xmm3, %xmm1
ucomisd %xmm1, %xmm4
cmovaq %rax, %r14
minsd %xmm4, %xmm1
addq $0x40, %rax
movapd %xmm1, %xmm4
jmp 0x3fcc
movsd %xmm4, -0x70(%rbp)
ucomisd 0x802b(%rip), %xmm4     # 0xc038
ja 0x414b
testq %r14, %r14
je 0x414b
leaq 0x10(%r14), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x6cfc
addq $0x18, %r14
cmpq %r14, %rax
je 0x414b
movq (%r12), %r14
movl -0x2c(%rbp), %r15d
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x549a
leaq 0x4(%rax), %r8
movq -0x78(%rbp), %rdi
movq %r14, %rsi
movl %r15d, %edx
movsd -0x80(%rbp), %xmm0
leaq -0x88(%rbp), %rcx
callq 0xa190
testl %eax, %eax
je 0x40ec
movq %r13, %rdi
movq %r12, %rsi
callq 0x549a
movsd 0x18(%rax), %xmm1
movsd -0x70(%rbp), %xmm0
mulsd %xmm0, %xmm1
addsd 0x10(%rax), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rax), %xmm1
divsd 0x7f99(%rip), %xmm1     # 0xc040
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 0x8104(%rip), %rsi      # 0xc1e7
movb $0x2, %al
callq 0x33b0
jmp 0x4147
movq 0xdee5(%rip), %rdi      # 0x11fd8
leaq 0x80a4(%rip), %rsi      # 0xc19e
callq 0x3280
movq %rax, %rdi
movq %r12, %rsi
callq 0x3230
movq %rax, %rdi
leaq 0x8f26(%rip), %r14      # 0xd03a
movq %r14, %rsi
callq 0x3280
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x3460
movq %rax, %rdi
movq %r14, %rsi
callq 0x3280
movsd -0x38(%rbp), %xmm0
movq %rax, %rdi
callq 0x3420
movq %rax, %rdi
callq 0x3170
movq -0x58(%rbp), %r15
addq $0x20, %r12
jmp 0x3f92
movl -0x2c(%rbp), %edi
movsd -0x38(%rbp), %xmm0
movsd 0x7ebc(%rip), %xmm1     # 0xc020
leaq -0x2c(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0xb032
movl -0x2c(%rbp), %r12d
movl %r12d, %eax
subl 0x4(%rbx), %eax
cvtsi2sd %eax, %xmm2
movsd -0x38(%rbp), %xmm0
movsd 0x7ea4(%rip), %xmm1     # 0xc030
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
subsd 0x18(%rbx), %xmm2
ucomisd 0x7ea7(%rip), %xmm2     # 0xc048
jb 0x3f5c
movq -0x50(%rbp), %rdi
callq 0x3290
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xde0f(%rip), %rdi      # 0x11fd8
leaq 0x7ee3(%rip), %rsi      # 0xc0b3
callq 0x3280
leaq -0x110(%rbp), %rsi
movq %rax, %rdi
callq 0x3280
leaq 0x7f6b(%rip), %rsi      # 0xc156
movq %rax, %rdi
callq 0x3280
movq %rax, %rdi
callq 0x3170
pushq $0x1
popq %rdi
callq 0x3320
nop