// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0x120(%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 0xde21(%rip), %r15      # 0x11fd8
leaq 0x9010(%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), %edi
movl %edi, -0x2c(%rbp)
movsd 0x10(%rbx), %xmm0
movsd 0x8e1c(%rip), %xmm1     # 0xd020
divsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, (%rsp)
leaq -0x4c(%rbp), %r15
leaq -0x48(%rbp), %r12
leaq -0x44(%rbp), %r13
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xbef6
movl (%r15), %edi
movl (%r12), %esi
movl (%r13), %edx
leaq -0x88(%rbp), %r15
leaq -0x84(%rbp), %r12
movq %r15, %rcx
movq %r12, %r8
callq 0xabdd
movl (%r15), %edx
movl (%r12), %ecx
leaq 0x8f74(%rip), %rsi      # 0xd1e9
movq %r14, %rdi
xorl %eax, %eax
callq 0x3080
leaq 0x8ede(%rip), %rsi      # 0xd164
movq %r14, %rdi
callq 0x3350
testq %rax, %rax
je 0x459d
movq %rax, %r14
leaq 0x901f(%rip), %rdi      # 0xd2c0
movq %rax, %rsi
callq 0x3300
movq %r14, -0x58(%rbp)
movq %r14, %rdi
callq 0x3340
leaq 0x20(%rbx), %rax
movq %rax, -0x70(%rbp)
movl -0x2c(%rbp), %edi
movsd -0x38(%rbp), %xmm0
leaq -0x68(%rbp), %rax
movq %rax, (%rsp)
leaq -0x4c(%rbp), %rsi
leaq -0x48(%rbp), %rdx
leaq -0x44(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
callq 0xbef6
movsd 0x8d42(%rip), %xmm2     # 0xd030
movq 0xd78(%rbx), %r12
movq 0xd80(%rbx), %r15
cmpq %r15, %r12
movapd 0x8d79(%rip), %xmm3     # 0xd080
movq %r15, -0x60(%rbp)
je 0x4534
movq 0xd60(%rbx), %rax
movq 0xd68(%rbx), %rcx
cmpq %rcx, %rax
je 0x436e
movl -0x2c(%rbp), %edx
movsd -0x38(%rbp), %xmm0
movsd 0x8cf4(%rip), %xmm1     # 0xd028
xorl %r14d, %r14d
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
movapd %xmm4, %xmm1
cmpq %rcx, %rax
jne 0x4337
jmp 0x4379
xorl %r14d, %r14d
movsd 0x8caf(%rip), %xmm4     # 0xd028
movapd %xmm4, -0xa0(%rbp)
ucomisd 0x8caf(%rip), %xmm4     # 0xd038
ja 0x4527
testq %r14, %r14
je 0x4527
leaq 0x10(%r14), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x7080
movapd 0x8cd1(%rip), %xmm3     # 0xd080
movsd 0x8c79(%rip), %xmm2     # 0xd030
addq $0x18, %r14
cmpq %r14, %rax
je 0x4527
movq (%r12), %r14
movl -0x2c(%rbp), %r15d
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x59da
leaq 0x4(%rax), %r8
movq -0x70(%rbp), %rdi
movq %r14, %rsi
movl %r15d, %edx
movsd -0x78(%rbp), %xmm0
leaq -0x80(%rbp), %rcx
callq 0xa9ca
testl %eax, %eax
je 0x4478
movq %r13, %rdi
movq %r12, %rsi
callq 0x59da
movsd 0x18(%rax), %xmm1
movapd -0xa0(%rbp), %xmm0
mulsd %xmm0, %xmm1
addsd 0x10(%rax), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rax), %xmm1
divsd 0x8c0d(%rip), %xmm1     # 0xd040
addsd -0x80(%rbp), %xmm1
movq (%r12), %rdx
movl -0x4c(%rbp), %ecx
movl -0x48(%rbp), %r8d
movl -0x44(%rbp), %r9d
movl -0x40(%rbp), %eax
movl -0x3c(%rbp), %esi
movsd -0x68(%rbp), %xmm0
movl %esi, 0x8(%rsp)
movl %eax, (%rsp)
movl $0x1, 0x10(%rsp)
movq -0x58(%rbp), %rdi
leaq 0x8d8b(%rip), %rsi      # 0xd1f7
movb $0x2, %al
callq 0x33e0
jmp 0x4513
movl $0x1f, %edx
movq 0xdb54(%rip), %r14      # 0x11fd8
movq %r14, %rdi
leaq 0x8d20(%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 0x9bb4(%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 0x8b15(%rip), %xmm2     # 0xd030
movapd 0x8b5d(%rip), %xmm3     # 0xd080
movq -0x60(%rbp), %r15
addq $0x20, %r12
cmpq %r15, %r12
jne 0x4311
movl -0x2c(%rbp), %edi
movsd -0x38(%rbp), %xmm0
movsd 0x8adc(%rip), %xmm1     # 0xd020
leaq -0x2c(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0xb6d4
movsd 0x8ad7(%rip), %xmm1     # 0xd030
movl -0x2c(%rbp), %eax
subl 0x4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
addsd -0x38(%rbp), %xmm0
subsd 0x18(%rbx), %xmm0
ucomisd 0x8acc(%rip), %xmm0     # 0xd048
jb 0x42bd
movq -0x58(%rbp), %rdi
callq 0x32c0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xda34(%rip), %rdi      # 0x11fd8
leaq 0x8b18(%rip), %rsi      # 0xd0c3
callq 0x32b0
leaq -0x120(%rbp), %rsi
movq %rax, %rdi
callq 0x32b0
leaq 0x8ba0(%rip), %rsi      # 0xd166
movq %rax, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3170
movl $0x1, %edi
callq 0x3370