// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]eph_converter/src/B2bDecoder.cpp
// Function: B2b::m_genclock_brd()
void B2b::m_genclock_brd(){
	FILE* fp = NULL;
	char filename[128] = {0};
	int mjd,iyear,imon,iday,ih,im,gweek,gd;
	double sod,dintv = 300,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){
			if (!(nav.v_readClk(cprn.c_str(),mjd,sod,&xclk_out))){
				cout << "ssr do not match ephemeris for " << cprn << " " << mjd << " " << sod << endl;
				continue;
			}
			/*************update the eph here *****************/
			xclk = xclk_out;
			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, %r13
xorps %xmm0, %xmm0
leaq -0x120(%rbp), %rbx
movaps %xmm0, 0x70(%rbx)
movaps %xmm0, 0x60(%rbx)
movaps %xmm0, 0x50(%rbx)
movaps %xmm0, 0x40(%rbx)
movaps %xmm0, 0x30(%rbx)
movaps %xmm0, 0x20(%rbx)
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
movq 0xcd7d(%rip), %r14      # 0x11fd8
leaq 0x7f6c(%rip), %rsi      # 0xd1ce
movl $0x1a, %edx
movq %r14, %rdi
callq 0x3330
movq (%r14), %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
movl (%r13), %edi
movl %edi, -0x2c(%rbp)
movsd 0x10(%r13), %xmm0
movsd 0x7dc5(%rip), %xmm1     # 0xd070
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), %r14
leaq -0x48(%rbp), %r15
leaq -0x44(%rbp), %r12
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
movl %edi, -0x5c(%rbp)
movapd %xmm0, -0xa0(%rbp)
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xbdb1
movl (%r14), %edi
movl (%r15), %esi
movl (%r12), %edx
leaq -0x88(%rbp), %r14
leaq -0x84(%rbp), %r15
movq %r14, %rcx
movq %r15, %r8
callq 0xaa75
movl (%r14), %edx
movl (%r15), %ecx
leaq 0x7ec4(%rip), %rsi      # 0xd1e9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3080
leaq 0x7e2e(%rip), %rsi      # 0xd164
movq %rbx, %rdi
callq 0x3350
movq %rax, -0x58(%rbp)
testq %rax, %rax
je 0x5534
leaq 0x7f6e(%rip), %rdi      # 0xd2c0
movq -0x58(%rbp), %rbx
movq %rbx, %rsi
callq 0x3300
movq %rbx, %rdi
callq 0x3340
leaq 0x20(%r13), %r14
leaq -0x80(%rbp), %r12
movl -0x5c(%rbp), %edi
movapd -0xa0(%rbp), %xmm0
movq %r13, -0x70(%rbp)
movq %r14, -0x78(%rbp)
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 0xbdb1
movq 0xd78(%r13), %rbx
movq 0xd80(%r13), %r15
cmpq %r15, %rbx
je 0x54c3
movq (%rbx), %rsi
movl -0x2c(%rbp), %edx
movsd -0x38(%rbp), %xmm0
movq %r14, %rdi
movq %r12, %rcx
callq 0xa59c
testl %eax, %eax
je 0x5417
movsd -0x80(%rbp), %xmm1
movq (%rbx), %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 0x7dec(%rip), %rsi      # 0xd1f7
movb $0x2, %al
callq 0x33e0
jmp 0x54ba
movl $0x1f, %edx
movq 0xcbb5(%rip), %r13      # 0x11fd8
movq %r13, %rdi
leaq 0x7d81(%rip), %rsi      # 0xd1ae
callq 0x3330
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r13, %rdi
callq 0x3330
movq %r12, %r14
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x8c14(%rip), %r13      # 0xe06a
movq %r13, %rsi
callq 0x3330
movl -0x2c(%rbp), %esi
movq %r12, %rdi
callq 0x3480
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x3330
movsd -0x38(%rbp), %xmm0
movq %r12, %rdi
callq 0x3440
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r12, %rdi
movq %r14, %r12
movq -0x78(%rbp), %r14
callq 0x3030
movq %rax, %rdi
callq 0x31f0
addq $0x20, %rbx
jmp 0x53b0
movl -0x2c(%rbp), %edi
movsd -0x38(%rbp), %xmm0
movsd 0x7b9d(%rip), %xmm1     # 0xd070
leaq -0x2c(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0xb5a9
movl -0x2c(%rbp), %edi
movl %edi, %eax
movq -0x70(%rbp), %r13
subl 0x4(%r13), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd -0x38(%rbp), %xmm0
mulsd 0x7b2f(%rip), %xmm1     # 0xd030
addsd %xmm0, %xmm1
subsd 0x18(%r13), %xmm1
ucomisd 0x7b35(%rip), %xmm1     # 0xd048
jb 0x5381
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 0xca9d(%rip), %rdi      # 0x11fd8
leaq 0x7b81(%rip), %rsi      # 0xd0c3
callq 0x32b0
leaq -0x120(%rbp), %rsi
movq %rax, %rdi
callq 0x32b0
leaq 0x7c09(%rip), %rsi      # 0xd166
movq %rax, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x3170
movl $0x1, %edi
callq 0x3370
nop