// File: 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
subq $0x110, %rsp            # imm = 0x110
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movsd %xmm0, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xe8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13a50
movl $0x0, -0xac(%rbp)
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rbp), %rax
movsd 0x8551(%rip), %xmm0     # 0x17d70
movsd %xmm0, (%rax)
movl -0x24(%rbp), %edi
movsd -0x30(%rbp), %xmm0
leaq -0xb0(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x146c0
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x31a0
movq -0xe8(%rbp), %rdi
xorps %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0x84e5(%rip), %xmm0     # 0x17d50
movsd %xmm0, -0xa0(%rbp)
addq $0xd0, %rdi
callq 0x13a70
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xe8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x13ad0
movq %rax, -0xe0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x13aa0
testb $0x1, %al
jne 0xf8ca
jmp 0xfb24
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x30c0
cmpq $0x0, %rax
je 0xfb11
movl -0xb0(%rbp), %eax
movl %eax, -0xfc(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movq %rax, %rcx
movl -0xfc(%rbp), %eax
subl 0x4(%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movsd -0xf8(%rbp), %xmm1
movsd -0xf0(%rbp), %xmm0
subsd 0x10(%rax), %xmm1
movsd 0x76b3(%rip), %xmm2     # 0x17008
divsd %xmm2, %xmm1
movsd 0x8417(%rip), %xmm2     # 0x17d78
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
jl 0xf9dc
movq 0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x100(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movq %rax, %rcx
movl -0x100(%rbp), %eax
cmpl 0x8(%rcx), %eax
jne 0xf9d7
movsd -0x48(%rbp), %xmm0
movaps 0x76c7(%rip), %xmm1     # 0x17070
pand %xmm1, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movq %rax, -0xc0(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0xfb24
jmp 0xfb0f
movq 0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0xfa3d
movsd -0x48(%rbp), %xmm1
movaps 0x767f(%rip), %xmm0     # 0x17070
pand %xmm0, %xmm1
movq 0x10(%rbp), %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0xfa38
movsd -0x48(%rbp), %xmm0
movaps 0x7661(%rip), %xmm1     # 0x17070
pand %xmm1, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movq %rax, -0xc0(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0xfb0d
movq 0x18(%rbp), %rax
cmpl $-0x2, (%rax)
jne 0xfb0b
leaq -0xb8(%rbp), %rdi
callq 0x13b00
cvtsi2sdl 0x4(%rax), %xmm0
movsd %xmm0, -0x108(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movsd -0x108(%rbp), %xmm0
movsd 0x10(%rax), %xmm1
movsd 0x75ac(%rip), %xmm2     # 0x17030
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
ucomisd -0xc8(%rbp), %xmm0
jbe 0xfb09
movsd -0x48(%rbp), %xmm1
movaps 0x75be(%rip), %xmm0     # 0x17070
pand %xmm0, %xmm1
movsd -0xa0(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xfb09
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x48(%rbp), %xmm0
movaps 0x7590(%rip), %xmm1     # 0x17070
pand %xmm1, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x13b00
movq %rax, -0xc0(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0xfb0b
jmp 0xfb0d
jmp 0xfb0f
jmp 0xfb11
jmp 0xfb13
leaq -0xb8(%rbp), %rdi
callq 0x13b20
jmp 0xf894
cmpl $0x0, -0xac(%rbp)
jne 0xfb39
movl $0x0, -0x4(%rbp)
jmp 0xfdcf
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0xb0(%rbp), %eax
movq -0xc0(%rbp), %rcx
subl 0x4(%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd -0x98(%rbp), %xmm1
movsd 0x74c3(%rip), %xmm2     # 0x17030
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0xc0(%rbp), %rax
subsd 0x10(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0xc0(%rbp), %rax
movsd 0x18(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rdi
leaq 0x8394(%rip), %rsi      # 0x17f39
callq 0x30c0
cmpq $0x0, %rax
je 0xfbbc
movl $0x1, -0x4(%rbp)
jmp 0xfdcf
movsd -0x48(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
movsd 0x7442(%rip), %xmm2     # 0x17010
divsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x7417(%rip), %xmm2     # 0x17010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x1, -0xa8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0xfc2e
movl $0xffffffff, -0xa8(%rbp) # imm = 0xFFFFFFFF
movq -0xe8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0xfde0
movsd -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xfc5a
jp 0xfc5a
jmp 0xfc79
movq -0xe8(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
leaq -0x90(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0xfe60
jmp 0xfc7b
movsd -0x48(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
callq 0x13b40
movsd 0x737e(%rip), %xmm1     # 0x17010
ucomisd %xmm1, %xmm0
jb 0xfd04
movsd -0x48(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xfcaf
jp 0xfcaf
jmp 0xfcff
movq -0xe8(%rbp), %rdi
cvtsi2sdl -0xa8(%rbp), %xmm0
movsd 0x734a(%rip), %xmm1     # 0x17010
mulsd %xmm1, %xmm0
leaq -0x90(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0xfe60
movsd -0x50(%rbp), %xmm1
cvtsi2sdl -0xa8(%rbp), %xmm0
movsd 0x731e(%rip), %xmm2     # 0x17010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0xfc7b
movq -0xe8(%rbp), %rdi
movl -0xb0(%rbp), %esi
movsd -0x98(%rbp), %xmm0
leaq -0x90(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x822e(%rip), %r8       # 0x17f59
callq 0x10080
movl $0x0, -0xa4(%rbp)
cmpl $0x3, -0xa4(%rbp)
jge 0xfd7c
movq -0x38(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movsd 0x7302(%rip), %xmm0     # 0x17058
mulsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0xfd3a
movl $0x3, -0xa4(%rbp)
cmpl $0x6, -0xa4(%rbp)
jge 0xfdc8
movslq -0xa4(%rbp), %rax
movsd 0x72ba(%rip), %xmm0     # 0x17058
mulsd -0x90(%rbp,%rax,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0xfd86
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)