// File: DoubleString[P]eph_converter/src/B2bDecoder.cpp
// Function: B2b::m_geneph_brd()
void B2b::m_geneph_brd(){
	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*****************/
			if(!(nav.v_readOrbit(cprn.c_str(),mjd,sod,xsat_out))){
				cout << "ssr do not match ephemeris for " << cprn << " " << mjd << " " << sod << endl;
				continue;
			}
			for (int i = 0; i < 6; i++) {
				xsat[i] = xsat_out[i];
			}
			/**************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,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
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movq $0x0, -0x10(%rbp)
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x31a0
movsd 0x118ab(%rip), %xmm0    # 0x17048
movsd %xmm0, -0x208(%rbp)
movsd 0x11873(%rip), %xmm0    # 0x17020
movsd %xmm0, -0x220(%rbp)
movq 0x1a81c(%rip), %rdi     # 0x1ffd8
leaq 0x11954(%rip), %rsi     # 0x17117
callq 0x32a0
movq %rax, %rdi
movq 0x1a7f6(%rip), %rsi     # 0x1ffc8
callq 0x3300
movq -0x2b0(%rbp), %rax
movl (%rax), %ecx
movl %ecx, -0x114(%rbp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x200(%rbp)
movsd -0x200(%rbp), %xmm0
divsd -0x208(%rbp), %xmm0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
mulsd -0x208(%rbp), %xmm0
movsd %xmm0, -0x200(%rbp)
movl -0x114(%rbp), %edi
movsd -0x200(%rbp), %xmm0
leaq -0x118(%rbp), %rsi
leaq -0x11c(%rbp), %rdx
leaq -0x120(%rbp), %rcx
leaq -0x124(%rbp), %r8
leaq -0x128(%rbp), %r9
leaq -0x1f8(%rbp), %rax
movq %rax, (%rsp)
callq 0x162e0
movl -0x118(%rbp), %edi
movl -0x11c(%rbp), %esi
movl -0x120(%rbp), %edx
leaq -0x12c(%rbp), %rcx
leaq -0x130(%rbp), %r8
callq 0x145a0
leaq -0x110(%rbp), %rdi
movl -0x12c(%rbp), %edx
movl -0x130(%rbp), %ecx
leaq 0x1189b(%rip), %rsi     # 0x17136
movb $0x0, %al
callq 0x3080
leaq -0x110(%rbp), %rdi
leaq 0x11894(%rip), %rsi     # 0x17144
callq 0x3340
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x5909
movq 0x1a712(%rip), %rdi     # 0x1ffd8
leaq 0x117d6(%rip), %rsi     # 0x170a3
callq 0x32a0
movq %rax, %rdi
leaq -0x110(%rbp), %rsi
callq 0x32a0
movq %rax, %rdi
leaq 0x1185b(%rip), %rsi     # 0x17146
callq 0x32a0
movq %rax, %rdi
movq 0x1a6ce(%rip), %rsi     # 0x1ffc8
callq 0x3300
movl $0x1, %edi
callq 0x3360
movq -0x2b0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5600
movl -0x114(%rbp), %edi
movsd -0x200(%rbp), %xmm0
leaq -0x118(%rbp), %rsi
leaq -0x11c(%rbp), %rdx
leaq -0x120(%rbp), %rcx
leaq -0x124(%rbp), %r8
leaq -0x128(%rbp), %r9
leaq -0x1f8(%rbp), %rax
movq %rax, (%rsp)
callq 0x162e0
movq -0x10(%rbp), %rdi
movl -0x118(%rbp), %edx
movl -0x11c(%rbp), %ecx
movl -0x120(%rbp), %r8d
movl -0x124(%rbp), %r9d
movl -0x128(%rbp), %eax
movsd -0x1f8(%rbp), %xmm0
leaq 0x117c4(%rip), %rsi     # 0x17151
movl %eax, (%rsp)
movb $0x1, %al
callq 0x3400
movq -0x2b0(%rbp), %rax
addq $0xd78, %rax            # imm = 0xD78
movq %rax, -0x288(%rbp)
movq -0x288(%rbp), %rdi
callq 0x68a0
movq %rax, -0x290(%rbp)
movq -0x288(%rbp), %rdi
callq 0x68d0
movq %rax, -0x298(%rbp)
leaq -0x290(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x6900
testb $0x1, %al
jne 0x59ed
jmp 0x5b84
leaq -0x290(%rbp), %rdi
callq 0x6940
movq %rax, %rcx
movq -0x2b0(%rbp), %rax
movq %rcx, -0x2a0(%rbp)
addq $0x20, %rax
movq %rax, -0x2b8(%rbp)
movq -0x2a0(%rbp), %rdi
callq 0x3130
movq -0x2b8(%rbp), %rdi
movq %rax, %rsi
movl -0x114(%rbp), %edx
movsd -0x200(%rbp), %xmm0
leaq -0x250(%rbp), %rcx
callq 0x13280
cmpl $0x0, %eax
jne 0x5abc
movq 0x1a587(%rip), %rdi     # 0x1ffd8
leaq 0x11736(%rip), %rsi     # 0x1718e
callq 0x32a0
movq %rax, %rdi
movq -0x2a0(%rbp), %rsi
callq 0x3250
movq %rax, %rdi
leaq 0x125fd(%rip), %rsi     # 0x18073
callq 0x32a0
movq %rax, %rdi
movl -0x114(%rbp), %esi
callq 0x34a0
movq %rax, %rdi
leaq 0x125e0(%rip), %rsi     # 0x18073
callq 0x32a0
movq %rax, %rdi
movsd -0x200(%rbp), %xmm0
callq 0x3510
movq %rax, %rdi
movq 0x1a516(%rip), %rsi     # 0x1ffc8
callq 0x3300
jmp 0x5b73
movl $0x0, -0x2a4(%rbp)
cmpl $0x6, -0x2a4(%rbp)
jge 0x5b00
movslq -0x2a4(%rbp), %rax
movsd -0x250(%rbp,%rax,8), %xmm0
movslq -0x2a4(%rbp), %rax
movsd %xmm0, -0x280(%rbp,%rax,8)
movl -0x2a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a4(%rbp)
jmp 0x5ac6
movq -0x10(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movq -0x2a0(%rbp), %rdi
callq 0x3130
movq -0x2c0(%rbp), %rdi
movq %rax, %rdx
movsd -0x280(%rbp), %xmm0
movsd 0x11527(%rip), %xmm1    # 0x17058
divsd %xmm1, %xmm0
movsd -0x278(%rbp), %xmm1
movsd 0x11513(%rip), %xmm2    # 0x17058
divsd %xmm2, %xmm1
movsd -0x270(%rbp), %xmm2
movsd 0x114ff(%rip), %xmm3    # 0x17058
divsd %xmm3, %xmm2
leaq 0x11609(%rip), %rsi     # 0x1716d
movsd 0x114e4(%rip), %xmm3    # 0x17050
movb $0x4, %al
callq 0x3400
leaq -0x290(%rbp), %rdi
callq 0x6e00
jmp 0x59d1
movl -0x114(%rbp), %edi
movsd -0x200(%rbp), %xmm0
movsd -0x208(%rbp), %xmm1
leaq -0x114(%rbp), %rsi
leaq -0x200(%rbp), %rdx
callq 0x15590
movq -0x2b0(%rbp), %rax
movl -0x114(%rbp), %ecx
subl 0x4(%rax), %ecx
cvtsi2sd %ecx, %xmm0
movsd -0x200(%rbp), %xmm1
movsd 0x1145f(%rip), %xmm2    # 0x17030
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
subsd 0x18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5be9
jmp 0x5bee
jmp 0x5919
movq -0x10(%rbp), %rdi
callq 0x32b0
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq