// File: 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
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 0x54af0
movl $0x0, -0xac(%rbp)
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rbp), %rax
movsd 0x7179(%rip), %xmm0     # 0xbd778
movsd %xmm0, (%rax)
movl -0x24(%rbp), %edi
movsd -0x30(%rbp), %xmm0
leaq -0xb0(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x33bf0
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x93d0
movq -0xe8(%rbp), %rdi
xorps %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0x7105(%rip), %xmm0     # 0xbd750
movsd %xmm0, -0xa0(%rbp)
addq $0xd0, %rdi
callq 0x54b10
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xe8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x54b70
movq %rax, -0xe0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x54b40
testb $0x1, %al
jne 0xb66aa
jmp 0xb6904
leaq -0xb8(%rbp), %rdi
callq 0x54c70
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x91b0
cmpq $0x0, %rax
je 0xb68f1
movl -0xb0(%rbp), %eax
movl %eax, -0xfc(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x54c70
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 0x54c70
movsd -0xf8(%rbp), %xmm1
movsd -0xf0(%rbp), %xmm0
subsd 0x10(%rax), %xmm1
movsd 0x66db(%rip), %xmm2     # 0xbce10
divsd %xmm2, %xmm1
movsd 0x10e5f(%rip), %xmm2    # 0xc75a0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
jl 0xb67bc
movq 0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x100(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x54c70
movq %rax, %rcx
movl -0x100(%rbp), %eax
cmpl 0x8(%rcx), %eax
jne 0xb67b7
movsd -0x48(%rbp), %xmm0
movaps 0x6a97(%rip), %xmm1     # 0xbd220
pand %xmm1, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x54c70
movq %rax, -0xc0(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0xb6904
jmp 0xb68ef
movq 0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0xb681d
movsd -0x48(%rbp), %xmm1
movaps 0x6a4f(%rip), %xmm0     # 0xbd220
pand %xmm0, %xmm1
movq 0x10(%rbp), %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0xb6818
movsd -0x48(%rbp), %xmm0
movaps 0x6a31(%rip), %xmm1     # 0xbd220
pand %xmm1, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x54c70
movq %rax, -0xc0(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0xb68ed
movq 0x18(%rbp), %rax
cmpl $-0x2, (%rax)
jne 0xb68eb
leaq -0xb8(%rbp), %rdi
callq 0x54c70
cvtsi2sdl 0x4(%rax), %xmm0
movsd %xmm0, -0x108(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x54c70
movsd -0x108(%rbp), %xmm0
movsd 0x10(%rax), %xmm1
movsd 0x65bc(%rip), %xmm2     # 0xbce20
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
ucomisd -0xc8(%rbp), %xmm0
jbe 0xb68e9
movsd -0x48(%rbp), %xmm1
movaps 0x698e(%rip), %xmm0     # 0xbd220
pand %xmm0, %xmm1
movsd -0xa0(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xb68e9
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x48(%rbp), %xmm0
movaps 0x6960(%rip), %xmm1     # 0xbd220
pand %xmm1, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0xb8(%rbp), %rdi
callq 0x54c70
movq %rax, -0xc0(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0xb68eb
jmp 0xb68ed
jmp 0xb68ef
jmp 0xb68f1
jmp 0xb68f3
leaq -0xb8(%rbp), %rdi
callq 0x54ee0
jmp 0xb6674
cmpl $0x0, -0xac(%rbp)
jne 0xb6919
movl $0x0, -0x4(%rbp)
jmp 0xb6bc8
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 0x64d3(%rip), %xmm2     # 0xbce20
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), %xmm1
movq -0xc0(%rbp), %rax
movsd 0x20(%rax), %xmm0
movsd -0x48(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rdi
leaq 0x15887(%rip), %rsi     # 0xcc225
callq 0x91b0
cmpq $0x0, %rax
je 0xb69b5
movl $0x1, -0x4(%rbp)
jmp 0xb6bc8
movsd -0x48(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
movsd 0x6451(%rip), %xmm2     # 0xbce18
divsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x6426(%rip), %xmm2     # 0xbce18
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 0xb6a27
movl $0xffffffff, -0xa8(%rbp) # imm = 0xFFFFFFFF
movq -0xe8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0xb6be0
movsd -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xb6a53
jp 0xb6a53
jmp 0xb6a72
movq -0xe8(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
leaq -0x90(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0xb6c60
jmp 0xb6a74
movsd -0x48(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
callq 0x39000
movsd 0x638d(%rip), %xmm1     # 0xbce18
ucomisd %xmm1, %xmm0
jb 0xb6afd
movsd -0x48(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xb6aa8
jp 0xb6aa8
jmp 0xb6af8
movq -0xe8(%rbp), %rdi
cvtsi2sdl -0xa8(%rbp), %xmm0
movsd 0x6359(%rip), %xmm1     # 0xbce18
mulsd %xmm1, %xmm0
leaq -0x90(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0xb6c60
movsd -0x50(%rbp), %xmm1
cvtsi2sdl -0xa8(%rbp), %xmm0
movsd 0x632d(%rip), %xmm2     # 0xbce18
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0xb6a74
movq -0xe8(%rbp), %rdi
movl -0xb0(%rbp), %esi
movsd -0x98(%rbp), %xmm0
leaq -0x90(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x1571d(%rip), %r8      # 0xcc241
callq 0xb6e80
movl $0x0, -0xa4(%rbp)
cmpl $0x3, -0xa4(%rbp)
jge 0xb6b75
movq -0x38(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movsd 0x68d9(%rip), %xmm0     # 0xbd428
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 0xb6b33
movl $0x3, -0xa4(%rbp)
cmpl $0x6, -0xa4(%rbp)
jge 0xb6bc1
movslq -0xa4(%rbp), %rax
movsd 0x6891(%rip), %xmm0     # 0xbd428
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 0xb6b7f
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)