// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rnxobs/Com.cpp
// Function: bamboo::xyzblh(double*, double, double, double, double, double, double, double*)
void xyzblh(double* x, double scale, double a0, double b0, double dx, double dy,
		double dz, double* geod) {
	double a, b;
	long double xp, yp, zp, s, e2, rhd, rbd, n, zps, tmp1, tmp2;
	int i;

	if (a0 == 0 || b0 == 0) {
		a = 6378137.0;
		b = 298.257223563;  //alpha = (a-b)/a
	} else {
		a = a0;
		b = b0;
	}
	for (i = 0; i < 3; i++)
		geod[i] = 0;
	xp = x[0] * scale + dx;
	yp = x[1] * scale + dy;
	zp = x[2] * scale + dz;

	if (b <= 6000000)
		b = a - a / b;
	e2 = (a * a - b * b) / (a * a);
	s = sqrt(xp * xp + yp * yp);
	geod[1] = atan(yp / xp);
	if (geod[1] < 0) {
		if (yp > 0)
			geod[1] += PI;
		if (yp < 0)
			geod[1] += 2 * PI;
	} else {
		if (yp < 0)
			geod[1] += PI;
	}
	zps = zp / s;
	geod[2] = sqrt(xp * xp + yp * yp + zp * zp) - a;
	geod[0] = atan(zps / (1.0 - e2 * a / (a + geod[2])));
	n = 1;
	rhd = rbd = 1;
	while (rbd * n > 1e-4 || rhd > 1e-4) {
		n = a / sqrt(1.0 - e2 * sin(geod[0]) * sin(geod[0]));
		tmp1 = geod[0];
		tmp2 = geod[2];
		geod[2] = s / cos(geod[0]) - n;
		geod[0] = atan(zps / (1.0 - e2 * n / (n + geod[2])));
		rbd = ABS(tmp1 - geod[0]);
		rhd = ABS(tmp2 - geod[2]);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %rbx
xorpd %xmm7, %xmm7
movapd %xmm2, %xmm6
cmpeqpd %xmm7, %xmm6
cmpeqpd %xmm1, %xmm7
orpd %xmm6, %xmm7
movd %xmm7, %eax
testb $0x1, %al
je 0x1ac68
movsd 0x45c78(%rip), %xmm2    # 0x608e0
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x1ac7a
andq $0x0, (%rbx,%rcx,8)
incq %rcx
jmp 0x1ac6a
testb $0x1, %al
je 0x1ac86
movsd 0x45c62(%rip), %xmm1    # 0x608e8
movsd (%rdi), %xmm6
mulsd %xmm0, %xmm6
addsd %xmm3, %xmm6
movsd %xmm6, -0xe8(%rbp)
fldl -0xe8(%rbp)
movsd 0x8(%rdi), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm4, %xmm3
movapd %xmm3, -0x50(%rbp)
movsd %xmm3, -0xd8(%rbp)
mulsd 0x10(%rdi), %xmm0
fldl -0xd8(%rbp)
addsd %xmm5, %xmm0
movsd %xmm0, -0xe0(%rbp)
fldl -0xe0(%rbp)
fstpt -0x2c(%rbp)
movapd %xmm1, %xmm0
divsd %xmm2, %xmm0
movapd %xmm1, %xmm4
subsd %xmm0, %xmm4
movapd %xmm2, %xmm0
cmpnlesd 0x45bf9(%rip), %xmm0    # 0x608f0
movapd %xmm0, %xmm3
andnpd %xmm4, %xmm3
andpd %xmm2, %xmm0
orpd %xmm3, %xmm0
mulsd %xmm0, %xmm0
movapd %xmm1, -0x40(%rbp)
mulsd %xmm1, %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, -0xd0(%rbp)
fldl -0xd0(%rbp)
fstpt -0x20(%rbp)
fld %st(0)
fmul %st(1), %st
fld %st(2)
fmul %st(3), %st
faddp %st, %st(1)
fld %st(0)
fstpt -0x14(%rbp)
fsqrt
fstpt -0x5c(%rbp)
fdivp %st, %st(1)
fstpt (%rsp)
callq 0x8aa0
fstpl -0xc8(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd %xmm0, 0x8(%rbx)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1adbc
movapd -0x50(%rbp), %xmm5
ucomisd %xmm1, %xmm5
movapd -0x40(%rbp), %xmm4
je 0x1add9
movsd 0x45b7c(%rip), %xmm2    # 0x60900
addsd %xmm0, %xmm2
xorpd %xmm3, %xmm3
cmpltsd %xmm5, %xmm3
andpd %xmm3, %xmm2
andnpd %xmm0, %xmm3
orpd %xmm2, %xmm3
cmpltsd %xmm1, %xmm5
movapd %xmm5, %xmm0
andnpd %xmm3, %xmm0
addsd 0x45b56(%rip), %xmm3    # 0x60908
andpd %xmm3, %xmm5
orpd %xmm0, %xmm5
jmp 0x1add4
ucomisd -0x50(%rbp), %xmm1
movapd -0x40(%rbp), %xmm4
jbe 0x1add9
addsd 0x45b30(%rip), %xmm0    # 0x60900
movapd %xmm0, %xmm5
movsd %xmm5, 0x8(%rbx)
fldt -0x2c(%rbp)
fld %st(0)
fmul %st(1), %st
fldt -0x14(%rbp)
faddp %st, %st(1)
fsqrt
movsd %xmm4, -0xc0(%rbp)
fldl -0xc0(%rbp)
fsubr %st, %st(1)
fxch %st(1)
fstpl -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, 0x10(%rbx)
fldt -0x20(%rbp)
fld %st(1)
fstpt -0x14(%rbp)
fmulp %st, %st(1)
addsd %xmm0, %xmm4
movsd %xmm4, -0xb0(%rbp)
fdivl -0xb0(%rbp)
fldt -0x5c(%rbp)
fdivrp %st, %st(2)
fld1
fsubp %st, %st(1)
fld %st(1)
fstpt -0x10c(%rbp)
fdivrp %st, %st(1)
fstpt (%rsp)
callq 0x8aa0
fstpl -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, (%rbx)
fldt -0x20(%rbp)
fchs
fstpt -0x100(%rbp)
fldl 0x45aaa(%rip)           # 0x60910
fld1
fld %st(0)
fld %st(2)
fstpt -0xf4(%rbp)
fucompi %st(2), %st
ja 0x1ae86
fucompi %st(1), %st
fstp %st(0)
fldz
fldz
fxch %st(1)
jbe 0x1af85
fstp %st(0)
fstp %st(0)
callq 0x8160
movsd %xmm0, -0xa0(%rbp)
movsd (%rbx), %xmm0
callq 0x8160
movsd %xmm0, -0x98(%rbp)
fldt -0x100(%rbp)
fmull -0xa0(%rbp)
fmull -0x98(%rbp)
fld1
faddp %st, %st(1)
fstpt (%rsp)
callq 0x88b0
fldt -0x14(%rbp)
fdivp %st, %st(1)
fstpt -0x40(%rbp)
movsd (%rbx), %xmm0
movsd %xmm0, -0x90(%rbp)
fldl -0x90(%rbp)
fstpt -0x50(%rbp)
fldl 0x10(%rbx)
fstpt -0x2c(%rbp)
callq 0x8bf0
movsd %xmm0, -0x88(%rbp)
fldt -0x5c(%rbp)
fdivl -0x88(%rbp)
fldt -0x40(%rbp)
fsubr %st, %st(1)
fxch %st(1)
fstpl -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, 0x10(%rbx)
movsd %xmm0, -0x78(%rbp)
fld %st(0)
faddl -0x78(%rbp)
fldt -0x20(%rbp)
fmulp %st, %st(2)
fdivrp %st, %st(1)
fld1
fsubp %st, %st(1)
fldt -0x10c(%rbp)
fdivp %st, %st(1)
fstpt (%rsp)
callq 0x8aa0
fstpl -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rbx)
movsd %xmm0, -0x68(%rbp)
fldt -0x50(%rbp)
fsubl -0x68(%rbp)
fld %st(0)
fchs
fxch %st(1)
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
fldt -0x2c(%rbp)
fsubl 0x10(%rbx)
fld %st(0)
fchs
fxch %st(1)
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
fldt -0xf4(%rbp)
fldt -0x40(%rbp)
fmulp %st, %st(3)
fxch %st(2)
fxch %st(1)
jmp 0x1ae72
fstp %st(0)
fstp %st(0)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %rbp
retq