// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rnxobs/Com.cpp
// Function: bamboo::phase_windup(int*, double (*) [3], double (*) [3], double*, double*, double*, double*, double*, double*)
void phase_windup(int* lfirst, double (*rot_f2j)[3], double (*rot_l2f)[3],
		double* xbf, double* ybf, double* zbf, double* xrec2sat, double* dphi0,
		double* dphi) {

	int j, n;
	double x_f[3], y_f[3], x_j[3], y_j[3], dummy[3], rlength, kusi;
	double k[3], d_r[3], d_s[3];

	double x_l[3] = { 0.0, 1.0, 0.0 };
	double y_l[3] = { -1.0, 0.0, 0.0 };

	unit_vector(3, xrec2sat, k, &rlength);

	for (j = 0; j < 3; j++)
		k[j] = -k[j];

	/*equivalent antenna dipole for both receiver and satellite antenna
	 D = x_j - k (k . x_j) - k x y_j
	 k is the unit vector of signal transmitting direction

	 transfer the unit vector of the antenna dipole unit in local/antenna system to
	 inertial system.
	 For ground receiver local   => earth fixed      => inertial
	 For LEO    receiver antenna => spacecraft fixed => inertial*/
	matmpy((double*)rot_l2f, x_l, x_f, 3, 3, 1);
	matmpy((double*)rot_l2f, y_l, y_f, 3, 3, 1);
	matmpy((double*)rot_f2j, x_f, x_j, 3, 3, 1);
	matmpy((double*)rot_f2j, y_f, y_j, 3, 3, 1);

	// D = x_j - k(k . x_j) + k x y_j
	rlength = dot(3, k, x_j);
	cross(k, y_j, dummy);

	for (j = 0; j < 3; j++)
		d_r[j] = x_j[j] - rlength * k[j] + dummy[j];
	unit_vector(3, d_r, d_r, &rlength);

	// the same for the satellite antenna
	rlength = dot(3, k, xbf);
	cross(k, ybf, dummy);
	for (j = 0; j < 3; j++)
		d_s[j] = xbf[j] - rlength * k[j] - dummy[j];
	unit_vector(3, d_s, d_s, &rlength);

	cross(d_s, d_r, dummy);

	kusi = dot(3, k, dummy);
	*dphi = dot(3, d_s, d_r);

	if ((ABS(*dphi)) > 1.0)
		*dphi = NINT(*dphi) * 1.0;
	*dphi = SIGN(1.0,kusi) * acos(*dphi) / (2 * PI);

	if (*lfirst) {
		*lfirst = false;
		n = 0;
	} else
		n = NINT(*dphi0 - *dphi);
	*dphi = n + *dphi;

	// save for the next epoch
	(*dphi0) = (*dphi);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r8, -0x30(%rbp)
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, -0x80(%rbp)
movq %rdi, -0x88(%rbp)
movq 0x10(%rbp), %rsi
pushq $0x3
popq %rdi
leaq -0x50(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x1b27e
xorl %eax, %eax
movapd 0x451dc(%rip), %xmm0    # 0x60ac0
cmpq $0x3, %rax
je 0x1b8ff
movsd -0x50(%rbp,%rax,8), %xmm1
xorpd %xmm0, %xmm1
movlpd %xmm1, -0x50(%rbp,%rax,8)
incq %rax
jmp 0x1b8e4
leaq 0x4534a(%rip), %rsi     # 0x60c50
leaq -0x120(%rbp), %rdx
pushq $0x3
popq %rbx
pushq $0x1
popq %r15
movq %r13, %rdi
movl %ebx, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x1b061
leaq 0x45345(%rip), %rsi     # 0x60c70
leaq -0x100(%rbp), %rdx
movq %r13, %rdi
movl %ebx, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x1b061
leaq -0xc0(%rbp), %rdx
movq -0x80(%rbp), %r12
movq %r12, %rdi
leaq -0x120(%rbp), %rsi
movl %ebx, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x1b061
leaq -0x140(%rbp), %r13
movq %r12, %rdi
leaq -0x100(%rbp), %rsi
movq %r13, %rdx
movl %ebx, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x1b061
leaq -0x50(%rbp), %r15
movl %ebx, %edi
movq %r15, %rsi
leaq -0xc0(%rbp), %rdx
callq 0x1b2ff
movsd %xmm0, -0x38(%rbp)
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm2
movsd 0x10(%r13), %xmm3
movsd 0x10(%r15), %xmm4
movsd (%r13), %xmm5
movsd 0x8(%r13), %xmm6
movapd %xmm2, %xmm7
mulsd %xmm3, %xmm7
mulsd %xmm1, %xmm3
mulsd %xmm6, %xmm1
mulsd %xmm4, %xmm6
subsd %xmm6, %xmm7
mulsd %xmm5, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm2, %xmm5
subsd %xmm5, %xmm1
movsd %xmm7, -0x70(%rbp)
movsd %xmm4, -0x68(%rbp)
movsd %xmm1, -0x60(%rbp)
xorpd 0x450bf(%rip), %xmm0    # 0x60ac0
xorl %eax, %eax
cmpq $0x3, %rax
je 0x1ba30
movsd -0x50(%rbp,%rax,8), %xmm1
mulsd %xmm0, %xmm1
addsd -0xc0(%rbp,%rax,8), %xmm1
addsd -0x70(%rbp,%rax,8), %xmm1
movsd %xmm1, -0xa0(%rbp,%rax,8)
incq %rax
jmp 0x1ba03
pushq $0x3
popq %rbx
leaq -0xa0(%rbp), %rdx
leaq -0x38(%rbp), %r15
movl %ebx, %edi
movq %rdx, %rsi
movq %r15, %rcx
callq 0x1b27e
leaq -0x50(%rbp), %r12
movl %ebx, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1b2ff
movapd %xmm0, -0x80(%rbp)
movsd %xmm0, (%r15)
leaq -0x70(%rbp), %rdx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x1b226
movapd -0x80(%rbp), %xmm1
xorpd 0x4503d(%rip), %xmm1    # 0x60ac0
xorl %eax, %eax
cmpq $0x3, %rax
je 0x1baaf
movsd -0x50(%rbp,%rax,8), %xmm0
mulsd %xmm1, %xmm0
addsd (%r14,%rax,8), %xmm0
subsd -0x70(%rbp,%rax,8), %xmm0
movsd %xmm0, -0xe0(%rbp,%rax,8)
incq %rax
jmp 0x1ba85
pushq $0x3
popq %r14
leaq -0xe0(%rbp), %r15
leaq -0x38(%rbp), %rcx
movl %r14d, %edi
movq %r15, %rsi
movq %r15, %rdx
callq 0x1b27e
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
leaq -0xa0(%rbp), %r12
movsd 0x10(%r12), %xmm2
movsd 0x10(%r15), %xmm3
movsd (%r12), %xmm4
movsd 0x8(%r12), %xmm5
movapd %xmm1, %xmm6
mulsd %xmm2, %xmm6
mulsd %xmm0, %xmm2
mulsd %xmm5, %xmm0
mulsd %xmm3, %xmm5
subsd %xmm5, %xmm6
mulsd %xmm4, %xmm3
subsd %xmm2, %xmm3
mulsd %xmm1, %xmm4
subsd %xmm4, %xmm0
leaq -0x70(%rbp), %rdx
movsd %xmm6, (%rdx)
movsd %xmm3, 0x8(%rdx)
movsd %xmm0, 0x10(%rdx)
leaq -0x50(%rbp), %rsi
movl %r14d, %edi
callq 0x1b2ff
movsd %xmm0, -0x30(%rbp)
movl %r14d, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1b2ff
movapd 0x44f67(%rip), %xmm1    # 0x60ac0
xorpd %xmm0, %xmm1
movapd %xmm0, %xmm2
maxsd %xmm1, %xmm2
ucomisd 0x43db3(%rip), %xmm2    # 0x5f920
jbe 0x1bb90
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x44f4d(%rip), %rcx     # 0x60ad0
addsd (%rcx,%rax,8), %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
callq 0x85f0
movapd 0x44f23(%rip), %xmm2    # 0x60ac0
xorpd %xmm0, %xmm2
xorpd %xmm1, %xmm1
cmpltsd -0x30(%rbp), %xmm1
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
divsd 0x44d49(%rip), %xmm1    # 0x60908
xorpd %xmm0, %xmm0
movq 0x20(%rbp), %rsi
movsd %xmm1, (%rsi)
movq -0x88(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1bbe0
andl $0x0, (%rax)
movq 0x18(%rbp), %rdx
jmp 0x1bc0d
movq 0x18(%rbp), %rdx
movsd (%rdx), %xmm0
subsd %xmm1, %xmm0
xorpd %xmm2, %xmm2
xorl %eax, %eax
ucomisd %xmm2, %xmm0
seta %al
leaq 0x44ed0(%rip), %rcx     # 0x60ad0
addsd (%rcx,%rax,8), %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, (%rsi)
movsd %xmm1, (%rdx)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq