// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]eph_converter/src/Broadcast.cpp
// Function: 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;
	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 $0x88, %rsp
movq %r8, -0x60(%rbp)
movq %rdx, %r13
movq %rsi, -0x68(%rbp)
movq %rdi, %rbx
movq %r9, -0x70(%rbp)
andq $0x0, (%r9)
movq 0x10(%rbp), %rdx
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, (%rdx)
leaq -0x44(%rbp), %r14
leaq -0x78(%rbp), %r15
movl %ecx, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0xa660
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movq %rbx, -0x58(%rbp)
addq $0xd0, %rbx
movl (%r14), %r14d
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movb $0x1, %al
movl %eax, -0x38(%rbp)
movsd (%r15), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %rbx, %r12
movq (%r12), %r12
cmpq %rbx, %r12
je 0x8110
leaq 0x10(%r12), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x30b0
testq %rax, %rax
je 0x802e
movl 0x14(%r12), %eax
movl %r14d, %ecx
subl %eax, %ecx
cvtsi2sd %ecx, %xmm0
movsd 0x20(%r12), %xmm1
movsd -0x40(%rbp), %xmm2
subsd %xmm1, %xmm2
divsd 0x3f9a(%rip), %xmm2     # 0xc010
mulsd 0x4ce2(%rip), %xmm0     # 0xcd60
addsd %xmm2, %xmm0
movq 0x18(%rbp), %rcx
movl (%rcx), %ecx
testl %ecx, %ecx
js 0x8098
cmpl 0x18(%r12), %ecx
jne 0x802e
jmp 0x811f
cmpl $-0x2, %ecx
je 0x80be
cmpl $-0x1, %ecx
jne 0x802e
andpd 0x3fd6(%rip), %xmm0     # 0xc080
movq 0x10(%rbp), %rax
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jb 0x802e
jmp 0x80f8
cvtsi2sd %eax, %xmm2
mulsd 0x3f66(%rip), %xmm2     # 0xc030
addsd %xmm1, %xmm2
ucomisd -0x30(%rbp), %xmm2
jbe 0x802e
andpd 0x3f9f(%rip), %xmm0     # 0xc080
movsd 0x4c07(%rip), %xmm1     # 0xccf0
ucomisd %xmm0, %xmm1
jb 0x802e
movsd %xmm2, -0x30(%rbp)
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x0, -0x38(%rbp)
movq %r15, -0x50(%rbp)
jmp 0x802e
xorl %r13d, %r13d
testb $0x1, -0x38(%rbp)
movq -0x50(%rbp), %r15
je 0x812f
jmp 0x8181
andpd 0x3f59(%rip), %xmm0     # 0xc080
movq 0x10(%rbp), %rax
movlpd %xmm0, (%rax)
movl 0x8(%r15), %eax
movq 0x18(%rbp), %rcx
movl %eax, (%rcx)
subl 0x4(%r15), %r14d
cvtsi2sd %r14d, %xmm0
mulsd 0x3ee6(%rip), %xmm0     # 0xc030
addsd -0x40(%rbp), %xmm0
subsd 0x10(%r15), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x18(%r15), %xmm0
movq -0x70(%rbp), %rax
movsd %xmm0, (%rax)
leaq 0x4d91(%rip), %rsi      # 0xcf00
movq -0x68(%rbp), %rdi
callq 0x30b0
pushq $0x1
popq %r13
testq %rax, %rax
je 0x8196
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd -0x40(%rbp), %xmm2
ucomisd %xmm2, %xmm0
seta %al
movsd 0x3e58(%rip), %xmm1     # 0xc008
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm2
movsd %xmm2, -0x30(%rbp)
leaq 0x4c3c(%rip), %rcx      # 0xce10
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0xb0(%rbp), %rsi
movq %r15, %rdx
callq 0x830c
movsd -0x30(%rbp), %xmm4
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm4
movq -0x58(%rbp), %r14
jne 0x8202
jnp 0x8221
leaq -0xb0(%rbp), %rsi
movq %r14, %rdi
movapd %xmm4, %xmm0
movq %r15, %rdx
callq 0x8344
movsd -0x30(%rbp), %xmm4
xorpd %xmm3, %xmm3
movq %r15, %r12
movsd -0x38(%rbp), %xmm0
mulsd 0x3dd7(%rip), %xmm0     # 0xc008
movapd 0x4bc7(%rip), %xmm1     # 0xce00
leaq -0xb0(%rbp), %r15
movq -0x60(%rbp), %rbx
movsd -0x40(%rbp), %xmm5
subsd %xmm4, %xmm5
movapd %xmm5, %xmm2
xorpd %xmm1, %xmm2
movapd %xmm5, %xmm1
maxsd %xmm2, %xmm1
movsd 0x3da3(%rip), %xmm2     # 0xc008
ucomisd %xmm2, %xmm1
jb 0x82a7
ucomisd %xmm3, %xmm5
jne 0x8273
jnp 0x8265
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movsd %xmm4, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
callq 0x8344
movapd 0x4b6d(%rip), %xmm1     # 0xce00
movsd -0x38(%rbp), %xmm0
movsd -0x30(%rbp), %xmm4
xorpd %xmm3, %xmm3
addsd %xmm0, %xmm4
jmp 0x8244
movl -0x44(%rbp), %esi
movsd -0x78(%rbp), %xmm0
leaq 0x4c6a(%rip), %r8       # 0xcf20
leaq -0xb0(%rbp), %rdx
movq %rbx, %rcx
callq 0x84b6
xorl %eax, %eax
movsd 0x3d91(%rip), %xmm0     # 0xc060
cmpq $0x3, %rax
je 0x82e8
movsd (%rbx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rbx,%rax,8)
incq %rax
jmp 0x82cf
xorl %eax, %eax
cmpq $0x3, %rax
je 0x8181
movsd -0x98(%rbp,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rbx,%rax,8)
incq %rax
jmp 0x82ea