// File: 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
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x140(%rbp)
movq $0x0, -0x10(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x31a0
movsd 0x1142b(%rip), %xmm0    # 0x17068
movsd %xmm0, -0xc0(%rbp)
movsd 0x113d3(%rip), %xmm0    # 0x17020
movsd %xmm0, -0xd8(%rbp)
movq 0x1a37c(%rip), %rdi     # 0x1ffd8
leaq 0x1154b(%rip), %rsi     # 0x171ae
callq 0x32a0
movq %rax, %rdi
movq 0x1a356(%rip), %rsi     # 0x1ffc8
callq 0x3300
movq -0x140(%rbp), %rax
movl (%rax), %ecx
movl %ecx, -0x94(%rbp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
divsd -0xc0(%rbp), %xmm0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
mulsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movl -0x94(%rbp), %edi
movsd -0xb8(%rbp), %xmm0
leaq -0x98(%rbp), %rsi
leaq -0x9c(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
leaq -0xa4(%rbp), %r8
leaq -0xa8(%rbp), %r9
leaq -0x118(%rbp), %rax
movq %rax, (%rsp)
callq 0x162e0
movl -0x98(%rbp), %edi
movl -0x9c(%rbp), %esi
movl -0xa0(%rbp), %edx
leaq -0xac(%rbp), %rcx
leaq -0xb0(%rbp), %r8
callq 0x145a0
leaq -0x90(%rbp), %rdi
movl -0xac(%rbp), %edx
movl -0xb0(%rbp), %ecx
leaq 0x1148e(%rip), %rsi     # 0x171c9
movb $0x0, %al
callq 0x3080
leaq -0x90(%rbp), %rdi
leaq 0x113f4(%rip), %rsi     # 0x17144
callq 0x3340
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x5da9
movq 0x1a272(%rip), %rdi     # 0x1ffd8
leaq 0x11336(%rip), %rsi     # 0x170a3
callq 0x32a0
movq %rax, %rdi
leaq -0x90(%rbp), %rsi
callq 0x32a0
movq %rax, %rdi
leaq 0x113bb(%rip), %rsi     # 0x17146
callq 0x32a0
movq %rax, %rdi
movq 0x1a22e(%rip), %rsi     # 0x1ffc8
callq 0x3300
movl $0x1, %edi
callq 0x3360
movq -0x140(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x6030
movl -0x94(%rbp), %edi
movsd -0xb8(%rbp), %xmm0
leaq -0x98(%rbp), %rsi
leaq -0x9c(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
leaq -0xa4(%rbp), %r8
leaq -0xa8(%rbp), %r9
leaq -0x118(%rbp), %rax
movq %rax, (%rsp)
callq 0x162e0
movq -0x140(%rbp), %rax
addq $0xd78, %rax            # imm = 0xD78
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rdi
callq 0x68a0
movq %rax, -0x128(%rbp)
movq -0x120(%rbp), %rdi
callq 0x68d0
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x6900
testb $0x1, %al
jne 0x5e50
jmp 0x5fb0
leaq -0x128(%rbp), %rdi
callq 0x6940
movq %rax, %rcx
movq -0x140(%rbp), %rax
movq %rcx, -0x138(%rbp)
addq $0x20, %rax
movq %rax, -0x148(%rbp)
movq -0x138(%rbp), %rdi
callq 0x3130
movq -0x148(%rbp), %rdi
movq %rax, %rsi
movl -0x94(%rbp), %edx
movsd -0xb8(%rbp), %xmm0
leaq -0xe8(%rbp), %rcx
callq 0x133c0
cmpl $0x0, %eax
jne 0x5f1f
movq 0x1a124(%rip), %rdi     # 0x1ffd8
leaq 0x112d3(%rip), %rsi     # 0x1718e
callq 0x32a0
movq %rax, %rdi
movq -0x138(%rbp), %rsi
callq 0x3250
movq %rax, %rdi
leaq 0x1219a(%rip), %rsi     # 0x18073
callq 0x32a0
movq %rax, %rdi
movl -0x94(%rbp), %esi
callq 0x34a0
movq %rax, %rdi
leaq 0x1217d(%rip), %rsi     # 0x18073
callq 0x32a0
movq %rax, %rdi
movsd -0xb8(%rbp), %xmm0
callq 0x3510
movq %rax, %rdi
movq 0x1a0b3(%rip), %rsi     # 0x1ffc8
callq 0x3300
jmp 0x5f9f
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x138(%rbp), %rdi
callq 0x3130
movq -0x150(%rbp), %rdi
movq %rax, %rdx
movl -0x98(%rbp), %ecx
movl -0x9c(%rbp), %r8d
movl -0xa0(%rbp), %r9d
movl -0xa4(%rbp), %r10d
movl -0xa8(%rbp), %eax
movsd -0x118(%rbp), %xmm0
movsd -0xe0(%rbp), %xmm1
leaq 0x1124f(%rip), %rsi     # 0x171d7
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movb $0x2, %al
callq 0x3400
leaq -0x128(%rbp), %rdi
callq 0x6e00
jmp 0x5e34
movl -0x94(%rbp), %edi
movsd -0xb8(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm1
leaq -0x94(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x15590
movq -0x140(%rbp), %rax
movl -0x94(%rbp), %ecx
subl 0x4(%rax), %ecx
cvtsi2sd %ecx, %xmm0
movsd -0xb8(%rbp), %xmm1
movsd 0x11033(%rip), %xmm2    # 0x17030
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
subsd 0x18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x6015
jmp 0x601a
jmp 0x5db9
movq -0x10(%rbp), %rdi
callq 0x32b0
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax)