// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rnxbrd/BroadcastEphUtils.cpp
// Function: bamboo::BroadcastEphUtils::m_gls2xyz(char const*, char const*, int, double, double*, double*, double*, int*)
int BroadcastEphUtils::m_gls2xyz(const char* mode,const char* cprn,int wk,double sow,double* xsat,double* clk,double* dtmin,int* iode){
	double dt = 0.0, dt1 = 0.0, dt2 = 0.0, x[6],sod,intv;
	int i, nsign,lfind,mjd;
	list<GLSEPH>::iterator glsItr;
	GLSEPH* ephr;
	lfind = 0;
	*clk = 0.0;
	*dtmin = 12.0;
	wksow2mjd(wk,sow,&mjd,&sod);
	memset(x, 0, sizeof(double) * 6);
	double tmax = 0.0,ttag;
	intv = 2.0;
	for(glsItr = this->glsEph.begin();glsItr != this->glsEph.end();++glsItr){
		if(strstr((*glsItr).cprn,cprn)){
			dt = (mjd - (*glsItr).mjd) * 24.0
					+ (sod - (*glsItr).sod) / 3600.0;
			if (*iode >= 0) {
				if (*iode == (*glsItr).aode) {
					*dtmin = fabs(dt);
					ephr = &(*glsItr);
					lfind = 1;
					break;
				}
			} else if(*iode == -1){
				if (fabs(dt) <= *dtmin) {
					*dtmin = fabs(dt);
					ephr = &(*glsItr);
					lfind = 1;
				}
			} else if(*iode == -2){
				ttag = (*glsItr).mjd * 86400.0 + (*glsItr).sod;
				if (ttag > tmax && fabs(dt) <= intv) {
					tmax = ttag;
					*dtmin = fabs(dt);
					ephr = &(*glsItr);
					lfind = 1;
				}
			}
		}
	}
	if(!lfind)
		return 0;
	*iode = ephr->aode;
	dt = (mjd - ephr->mjd) * 86400.0 + sod - ephr->sod;
	*clk = ephr->tau + ephr->gamma * dt;
	if (strstr(mode, "ynn") != NULL)
		return 1;

	dt1 = dt - (int) (dt / 60.0) * 60.0;
	dt2 = dt1;
	nsign = 1;
	if (dt < 0.0)
		nsign = -1;

	glsinit(x, *ephr);

	if (dt1 != 0.0)
		glsrkf4(dt1, x, *ephr);

	while (ABS(dt-dt1) >= 60.0) {
		if (dt - dt1 != 0.0) {
			glsrkf4(nsign * 60.0, x,  *ephr);
			dt1 = dt1 + nsign * 60.0;
		}
	}
	pz902wgs84(mjd, sod, x, xsat, "MCC");
	for (i = 0; i < 3; i++)
		xsat[i] = xsat[i] * 1e3;
	for (i = 3; i < 6; i++)
		xsat[i] = x[i] * 1e3;
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %r15
movq %r8, %r14
movq %rdx, %r13
movq %rsi, -0x88(%rbp)
movq %rdi, %rbx
movq 0x10(%rbp), %rdx
movq $0x0, (%r9)
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, (%rdx)
leaq -0x2c(%rbp), %rsi
leaq -0x48(%rbp), %rdx
movl %ecx, %edi
callq 0x1d1d9
xorpd %xmm0, %xmm0
movapd %xmm0, -0xa0(%rbp)
movapd %xmm0, -0xb0(%rbp)
movapd %xmm0, -0xc0(%rbp)
leaq 0xd0(%rbx), %r12
movq %rbx, -0x68(%rbp)
movq 0xd0(%rbx), %rbx
cmpq %r12, %rbx
je 0x65761
movq %r15, -0x78(%rbp)
movq %r14, -0x70(%rbp)
movl -0x2c(%rbp), %r14d
movl $0x0, -0x38(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x10(%rbx), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x8160
testq %rax, %rax
je 0x656d1
movl 0x14(%rbx), %eax
movl %r14d, %ecx
subl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x20(%rbx), %xmm2
movsd -0x60(%rbp), %xmm1
subsd %xmm2, %xmm1
divsd 0x520e(%rip), %xmm1     # 0x6a8c0
mulsd 0xf66e(%rip), %xmm0     # 0x74d28
addsd %xmm1, %xmm0
movq 0x18(%rbp), %rcx
movl (%rcx), %ecx
testl %ecx, %ecx
js 0x656db
cmpl 0x18(%rbx), %ecx
je 0x65769
movq (%rbx), %rbx
cmpq %r12, %rbx
jne 0x65679
jmp 0x6574c
cmpl $-0x2, %ecx
je 0x65702
cmpl $-0x1, %ecx
jne 0x656d1
andpd 0x4243(%rip), %xmm0     # 0x69930
movq 0x10(%rbp), %rax
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jb 0x656d1
movsd -0x40(%rbp), %xmm1
jmp 0x65732
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x51bf(%rip), %xmm1     # 0x6a8d0
addsd %xmm2, %xmm1
ucomisd -0x40(%rbp), %xmm1
jbe 0x656d1
andpd 0x420c(%rip), %xmm0     # 0x69930
movsd 0x6684(%rip), %xmm2     # 0x6bdb0
ucomisd %xmm0, %xmm2
jb 0x656d1
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x1, -0x38(%rbp)
movq %r15, -0x80(%rbp)
movsd %xmm1, -0x40(%rbp)
jmp 0x656d1
cmpl $0x0, -0x38(%rbp)
je 0x65761
movl -0x2c(%rbp), %r14d
movsd -0x48(%rbp), %xmm0
movq -0x80(%rbp), %r15
jmp 0x6577e
xorl %r12d, %r12d
jmp 0x6598b
andpd 0x41bf(%rip), %xmm0     # 0x69930
movq 0x10(%rbp), %rax
movlpd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm0
movl 0x8(%r15), %eax
movq 0x18(%rbp), %rcx
movl %eax, (%rcx)
subl 0x4(%r15), %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd 0x5134(%rip), %xmm1     # 0x6a8d0
addsd %xmm0, %xmm1
subsd 0x10(%r15), %xmm1
movsd 0x20(%r15), %xmm0
movsd %xmm1, -0x38(%rbp)
mulsd %xmm1, %xmm0
addsd 0x18(%r15), %xmm0
movq -0x78(%rbp), %rax
movsd %xmm0, (%rax)
leaq 0x13ca6(%rip), %rsi     # 0x79470
movq -0x88(%rbp), %rdi
callq 0x8160
movl $0x1, %r12d
testq %rax, %rax
jne 0x6598b
movsd -0x38(%rbp), %xmm3
movapd %xmm3, %xmm0
divsd 0x50c2(%rip), %xmm0     # 0x6a8b8
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm4
xorpd 0x52ca(%rip), %xmm4     # 0x6aad0
xorl %eax, %eax
movsd 0x30(%r15,%rax,8), %xmm0
movsd %xmm0, -0xc0(%rbp,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x65808
mulsd 0x508f(%rip), %xmm4     # 0x6a8b8
addsd %xmm3, %xmm4
movl $0x3, %eax
movsd 0x30(%r15,%rax,8), %xmm0
movsd %xmm0, -0xc0(%rbp,%rax,8)
incq %rax
cmpq $0x6, %rax
jne 0x65832
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
ucomisd %xmm3, %xmm0
seta %r14b
ucomisd %xmm0, %xmm4
jne 0x65861
jnp 0x65887
leaq -0xc0(%rbp), %rsi
movq -0x68(%rbp), %rdi
movapd %xmm4, %xmm0
movq %r15, %rdx
movapd %xmm4, -0x60(%rbp)
callq 0x659d4
movapd -0x60(%rbp), %xmm4
movsd -0x38(%rbp), %xmm3
movapd %xmm3, %xmm0
subsd %xmm4, %xmm0
movapd 0x5239(%rip), %xmm1     # 0x6aad0
xorpd %xmm0, %xmm1
movapd %xmm0, %xmm2
maxsd %xmm1, %xmm2
ucomisd 0x500d(%rip), %xmm2     # 0x6a8b8
jb 0x6592a
movb %r14b, %bl
leaq 0x7399(%rip), %rax      # 0x6cc50
movsd (%rax,%rbx,8), %xmm1
mulsd 0x4ff4(%rip), %xmm1     # 0x6a8b8
movsd %xmm1, -0x40(%rbp)
leaq -0xc0(%rbp), %r13
ucomisd 0x5030(%rip), %xmm0     # 0x6a908
jne 0x658dc
jnp 0x65904
movq -0x68(%rbp), %rdi
movsd -0x40(%rbp), %xmm0
movq %r13, %rsi
movq %r15, %rdx
movapd %xmm4, -0x60(%rbp)
callq 0x659d4
movapd -0x60(%rbp), %xmm4
movsd -0x38(%rbp), %xmm3
addsd -0x40(%rbp), %xmm4
movapd %xmm3, %xmm0
subsd %xmm4, %xmm0
movapd %xmm0, %xmm1
xorpd 0x51b8(%rip), %xmm1     # 0x6aad0
movapd %xmm0, %xmm2
maxsd %xmm1, %xmm2
ucomisd 0x4f90(%rip), %xmm2     # 0x6a8b8
jae 0x658d0
movl -0x2c(%rbp), %esi
movsd -0x48(%rbp), %xmm0
leaq 0x13b53(%rip), %r8      # 0x7948c
leaq -0xc0(%rbp), %rdx
movq -0x70(%rbp), %rbx
movq %rbx, %rcx
callq 0x65b3c
xorl %eax, %eax
movsd 0x5b22(%rip), %xmm0     # 0x6b478
movsd (%rbx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rbx,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x65956
xorl %eax, %eax
movsd -0xa8(%rbp,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rbx,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x6596f
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq