// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]eph_converter/src/B2bDecoder.cpp
// Function: B2b::m_geneph()
void B2b::m_geneph(){
	FILE* fp = NULL;
	char filename[256] = {0};
	int mjd,iyear,imon,iday,ih,im,gweek,gd;
	double dx[6],length,A[3],Cr[3],R[3],dxx[6],sec;
	double sod,dintv = 900,dt,dtmin,dtlimit =120,xsat_out[6],xsat[6];
	/******** generate the ephemeris here *****************/
	cout << "begin to recover ephemeris ..." << 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.sp3",gweek,gd);
	if(!(fp = fopen(filename,"w"))){cout << "can't open file " << filename << " to write!" << endl;exit(1);}
	m_wtephheader(fp);
	while(true){
		mjd2date(mjd,sod,&iyear,&imon,&iday,&ih,&im,&sec);
		fprintf(fp,"*   %4d%3d%3d%3d%3d%12.8lf\n",iyear,imon,iday,ih,im,sec);
		for(auto& cprn : cprn_list){
			/*************get the minus ssr*****************/
			dtmin = 9e9;
			orbit* ssr_selected = nullptr;
			for(auto& ssr : ORB_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->ORB.find(cprn) == ssr_selected->ORB.end()) continue;
			if(!(nav.v_readOrbit(cprn.c_str(),mjd,sod,xsat_out,&ssr_selected->ORB[cprn].iode))){
//				cout << "ssr do not match ephemeris for " << cprn << " " << mjd << " " << sod << endl;
				continue;
			}
			/*************update the eph here *****************/
			memcpy(dx,ssr_selected->ORB[cprn].orb,sizeof(double) * 6);
			unit_vector(3,xsat_out,R,&length);
			cross(xsat_out,xsat_out + 3,Cr);
			unit_vector(3, Cr, Cr, &length);
			cross(Cr, R, A);
			unit_vector(3, A, A, &length);

//			unit_vector(3, xsat_out + 3, A, &length);
//			cross(xsat_out, xsat_out + 3, Cr);
//			unit_vector(3, Cr, Cr, &length);
//			cross(A, Cr, R);
//			unit_vector(3, R, R, &length);

			memset(dxx, 0, sizeof(dxx));
			dxx[0] = R[0] * dx[0] + A[0] * dx[1] + Cr[0] * dx[2];
			dxx[1] = R[1] * dx[0] + A[1] * dx[1] + Cr[1] * dx[2];
			dxx[2] = R[2] * dx[0] + A[2] * dx[1] + Cr[2] * dx[2];

			// velocity
			dxx[3] = R[0] * dx[3] + A[0] * dx[4] + Cr[0] * dx[5];
			dxx[4] = R[1] * dx[3] + A[1] * dx[4] + Cr[1] * dx[5];
			dxx[5] = R[2] * dx[3] + A[2] * dx[4] + Cr[2] * dx[5];

			for (int i = 0; i < 6; i++) {
				xsat[i] = xsat_out[i] - dxx[i];
			}
			double clock_sp3 = 999.0;
			/**** clock part *****/
			{
				double xclk_out,c[3],dclk;
				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){
					/*************request for the brdm *****************/
					if (ssr_selected->CLK.find(cprn) != ssr_selected->CLK.end()){
						if ((nav.v_readClk(cprn.c_str(), mjd, sod, &xclk_out, &ssr_selected->CLK[cprn].iode))) {
							/*************update the eph here *****************/
							memcpy(c, ssr_selected->CLK[cprn].clk, sizeof(double) * 3);
							dclk = c[0] + dtmin * (c[1] + dtmin * c[2]);
							clock_sp3 = xclk_out - dclk / VEL_LIGHT;
						}
					}
				}
			}
			/**************write it into orbit file *********/
			fprintf(fp,"P%s%14.6lf%14.6lf%14.6lf%14.6lf\n",cprn.c_str(), xsat[0] / 1000.0 , xsat[1] / 1000.0,xsat[2] / 1000.0,clock_sp3 != 999.0 ? clock_sp3 * 1E6 : 999.0);
		}
		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 $0x2a8, %rsp            # imm = 0x2A8
movq %rdi, %rbx
leaq -0x2c0(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x31b0
movq 0xd9c9(%rip), %r15      # 0x11fd8
leaq 0x8b21(%rip), %rsi      # 0xd137
movl $0x1e, %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 0x89f2(%rip), %xmm1     # 0xd050
divsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, (%rsp)
leaq -0x4c(%rbp), %r15
leaq -0x48(%rbp), %r13
leaq -0x44(%rbp), %r14
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
movl %r12d, %edi
movapd %xmm0, -0x80(%rbp)
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0xbdb1
movl (%r15), %edi
movl (%r13), %esi
movl (%r14), %edx
leaq -0xc8(%rbp), %r14
leaq -0xc4(%rbp), %r15
movq %r14, %rcx
movq %r15, %r8
callq 0xaa75
movl (%r14), %edx
movl (%r15), %ecx
leaq 0x8a7e(%rip), %rsi      # 0xd156
leaq -0x2c0(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x3080
leaq 0x8a74(%rip), %rsi      # 0xd164
movq %r14, %rdi
callq 0x3350
testq %rax, %rax
je 0x4d47
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4d8a
leaq 0x20(%rbx), %rax
movq %rax, -0x90(%rbp)
movapd -0x80(%rbp), %xmm0
movq %r14, -0x88(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, (%rsp)
movl %r12d, %edi
leaq -0x4c(%rbp), %rsi
leaq -0x48(%rbp), %rdx
leaq -0x44(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
callq 0xbdb1
movl -0x4c(%rbp), %edx
movl -0x48(%rbp), %ecx
movl -0x44(%rbp), %r8d
movl -0x40(%rbp), %r9d
movl -0x3c(%rbp), %eax
movsd -0x98(%rbp), %xmm0
movl %eax, (%rsp)
movq %r14, %rdi
leaq 0x89fe(%rip), %rsi      # 0xd171
movb $0x1, %al
callq 0x33e0
movsd 0x88ae(%rip), %xmm3     # 0xd030
movq 0xd78(%rbx), %r12
movq 0xd80(%rbx), %r13
cmpq %r13, %r12
movapd 0x88e5(%rip), %xmm4     # 0xd080
movq %r13, -0x80(%rbp)
je 0x4cd0
movq 0xd48(%rbx), %rax
movq 0xd50(%rbx), %rcx
cmpq %rcx, %rax
je 0x4cc3
movl -0x2c(%rbp), %edx
movsd -0x38(%rbp), %xmm0
movsd 0x885c(%rip), %xmm1     # 0xd028
xorl %r14d, %r14d
movapd %xmm1, %xmm2
movl (%rax), %esi
subl %edx, %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm3, %xmm1
addsd 0x8(%rax), %xmm1
subsd %xmm0, %xmm1
andpd %xmm4, %xmm1
ucomisd %xmm1, %xmm2
cmovaq %rax, %r14
minsd %xmm2, %xmm1
addq $0x40, %rax
cmpq %rcx, %rax
jne 0x47cf
ucomisd 0x882c(%rip), %xmm1     # 0xd038
seta %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x4cc3
leaq 0x10(%r14), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x6f42
movapd 0x884c(%rip), %xmm4     # 0xd080
movsd 0x87f4(%rip), %xmm3     # 0xd030
addq $0x18, %r14
cmpq %r14, %rax
je 0x4cc3
movq (%r12), %r13
movl -0x2c(%rbp), %r14d
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x59e0
leaq 0x4(%rax), %r8
movq -0x90(%rbp), %rdi
movq %r13, %rsi
movq -0x80(%rbp), %r13
movl %r14d, %edx
movsd -0x70(%rbp), %xmm0
leaq -0x1c0(%rbp), %rcx
callq 0xa7a6
movapd 0x87ec(%rip), %xmm4     # 0xd080
movsd 0x8794(%rip), %xmm3     # 0xd030
testl %eax, %eax
je 0x4cc3
movq %r15, %rdi
movq %r12, %rsi
callq 0x59e0
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd 0x30(%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movl $0x3, %edi
leaq -0x1c0(%rbp), %r14
movq %r14, %rsi
leaq -0xe0(%rbp), %r15
movq %r15, %rdx
leaq -0x158(%rbp), %r13
movq %r13, %rcx
callq 0xbf01
movq %r14, %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x100(%rbp), %r14
movq %r14, %rdx
callq 0xbf99
movl $0x3, %edi
movq %r14, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0xbf01
movq %r14, %rdi
movq %r15, %rsi
leaq -0x120(%rbp), %r14
movq %r14, %rdx
callq 0xbf99
movl $0x3, %edi
movq %r14, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0xbf01
movsd -0x120(%rbp), %xmm3
movsd -0x118(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm8
movapd %xmm8, %xmm2
mulsd %xmm3, %xmm2
movsd -0xe0(%rbp), %xmm4
movsd -0xd8(%rbp), %xmm1
movapd %xmm4, %xmm5
movsd -0xa8(%rbp), %xmm11
mulsd %xmm11, %xmm5
addsd %xmm2, %xmm5
movsd -0x100(%rbp), %xmm6
movsd -0xf8(%rbp), %xmm2
movapd %xmm6, %xmm7
movsd -0xb0(%rbp), %xmm10
mulsd %xmm10, %xmm7
addsd %xmm5, %xmm7
movsd %xmm7, -0x150(%rbp)
movapd %xmm8, %xmm5
movapd %xmm8, %xmm9
mulsd %xmm0, %xmm5
movapd %xmm1, %xmm7
mulsd %xmm11, %xmm7
addsd %xmm5, %xmm7
movapd %xmm2, %xmm5
mulsd %xmm10, %xmm5
addsd %xmm7, %xmm5
movsd %xmm5, -0x148(%rbp)
movsd -0xd0(%rbp), %xmm5
movsd -0x110(%rbp), %xmm8
mulsd %xmm8, %xmm9
movapd %xmm11, %xmm7
mulsd %xmm5, %xmm7
addsd %xmm9, %xmm7
movapd %xmm7, %xmm9
movsd -0xf0(%rbp), %xmm7
mulsd %xmm7, %xmm10
addsd %xmm9, %xmm10
movsd %xmm10, -0x140(%rbp)
movsd -0xb8(%rbp), %xmm9
mulsd %xmm9, %xmm3
movsd -0x58(%rbp), %xmm10
mulsd %xmm10, %xmm4
addsd %xmm3, %xmm4
movsd -0x70(%rbp), %xmm3
mulsd %xmm3, %xmm6
addsd %xmm4, %xmm6
movsd %xmm6, -0x138(%rbp)
mulsd %xmm9, %xmm0
mulsd %xmm10, %xmm1
addsd %xmm0, %xmm1
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, -0x130(%rbp)
mulsd %xmm8, %xmm9
mulsd %xmm10, %xmm5
addsd %xmm9, %xmm5
mulsd %xmm3, %xmm7
addsd %xmm5, %xmm7
movsd %xmm7, -0x128(%rbp)
xorl %eax, %eax
movsd -0x1c0(%rbp,%rax,8), %xmm0
subsd -0x150(%rbp,%rax,8), %xmm0
movsd %xmm0, -0x190(%rbp,%rax,8)
incq %rax
cmpq $0x6, %rax
jne 0x4ace
movq 0xd60(%rbx), %rax
movq 0xd68(%rbx), %rcx
movsd 0x8550(%rip), %xmm5     # 0xd058
movapd %xmm5, %xmm3
cmpq %rcx, %rax
movq -0x80(%rbp), %r13
je 0x4c51
movl -0x2c(%rbp), %edx
movsd -0x38(%rbp), %xmm0
xorl %r14d, %r14d
movsd 0x84fc(%rip), %xmm4     # 0xd028
movsd 0x84fc(%rip), %xmm2     # 0xd030
movapd 0x8544(%rip), %xmm3     # 0xd080
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 0x4b3c
movsd 0x84bf(%rip), %xmm0     # 0xd038
movapd %xmm4, -0x70(%rbp)
ucomisd %xmm4, %xmm0
seta %al
testq %r14, %r14
setne %cl
movapd %xmm5, %xmm3
testb %cl, %al
je 0x4c51
leaq 0x10(%r14), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x70ce
movsd 0x84aa(%rip), %xmm5     # 0xd058
addq $0x18, %r14
movapd %xmm5, %xmm3
cmpq %r14, %rax
je 0x4c51
movq (%r12), %r14
movl -0x2c(%rbp), %r13d
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x5a60
leaq 0x4(%rax), %r8
movq -0x90(%rbp), %rdi
movq %r14, %rsi
movl %r13d, %edx
movq -0x80(%rbp), %r13
movsd -0x58(%rbp), %xmm0
leaq -0xc0(%rbp), %rcx
callq 0xa862
movsd 0x844e(%rip), %xmm5     # 0xd058
movapd %xmm5, %xmm3
testl %eax, %eax
je 0x4c51
movq %r15, %rdi
movq %r12, %rsi
callq 0x5a60
movsd 0x8433(%rip), %xmm5     # 0xd058
movsd 0x18(%rax), %xmm3
movapd -0x70(%rbp), %xmm0
mulsd %xmm0, %xmm3
addsd 0x10(%rax), %xmm3
mulsd %xmm0, %xmm3
addsd 0x8(%rax), %xmm3
divsd 0x83f7(%rip), %xmm3     # 0xd040
addsd -0xc0(%rbp), %xmm3
movq (%r12), %rdx
movsd -0x190(%rbp), %xmm0
movsd -0x188(%rbp), %xmm1
movsd 0x83f3(%rip), %xmm4     # 0xd060
divsd %xmm4, %xmm0
divsd %xmm4, %xmm1
movsd -0x180(%rbp), %xmm2
divsd %xmm4, %xmm2
movapd %xmm3, %xmm4
mulsd 0x83db(%rip), %xmm4     # 0xd068
cmpneqsd %xmm5, %xmm3
andpd %xmm3, %xmm4
andnpd %xmm5, %xmm3
orpd %xmm4, %xmm3
movq -0x88(%rbp), %rdi
leaq 0x84e1(%rip), %rsi      # 0xd18d
movb $0x4, %al
callq 0x33e0
movsd 0x8375(%rip), %xmm3     # 0xd030
movapd 0x83bd(%rip), %xmm4     # 0xd080
addq $0x20, %r12
cmpq %r13, %r12
jne 0x47a5
movl -0x2c(%rbp), %edi
movsd -0x38(%rbp), %xmm0
movsd 0x8370(%rip), %xmm1     # 0xd050
leaq -0x2c(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0xb5a9
movsd 0x833b(%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 0x8328(%rip), %xmm2     # 0xd048
movq -0x88(%rbp), %r14
jb 0x4726
movq %r14, %rdi
callq 0x32c0
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd28a(%rip), %rdi      # 0x11fd8
leaq 0x836e(%rip), %rsi      # 0xd0c3
callq 0x32b0
leaq -0x2c0(%rbp), %rsi
movq %rax, %rdi
callq 0x32b0
leaq 0x83f6(%rip), %rsi      # 0xd166
movq %rax, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3170
movl $0x1, %edi
callq 0x3370