// File: DoubleString[P]RtConverter/src/Rnxobs/Com.cpp
// Function: bamboo::betau(double*, double*, double*, double*)
void betau(double* xsat, double* xsun, double* beta, double* u) {
	double xsat_unit[3], nop_unit[3];
	double xsun_unit[3], vsat_unit[3], det;
	unit_vector(3, xsat, xsat_unit, &det);
	cross(xsat, xsat + 3, nop_unit);
	unit_vector(3, nop_unit, nop_unit, &det);
	unit_vector(3, xsun, xsun_unit, &det);
	*beta = PI / 2.0 - acos(dot(3, nop_unit, xsun_unit));

	*u = acos(dot(3, xsat_unit, xsun_unit) / cos(*beta));

	unit_vector(3, xsat + 3, vsat_unit, &det);

	if (dot(3, vsat_unit, xsun_unit)
			> dot(3, vsat_unit, xsat_unit) * dot(3, xsat_unit, xsun_unit))
		*u = -(*u);
	*u = *u - PI;

	while (*u < 0)
		*u = *u + 2 * PI;
	while (*u > 2 * PI)
		*u = *u - 2 * PI;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x40(%rbp), %rdx
movl $0x3, %edi
leaq -0xa8(%rbp), %rcx
callq 0x356a0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x18, %rsi
leaq -0x60(%rbp), %rdx
callq 0x35590
leaq -0x60(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movl $0x3, %edi
leaq -0xa8(%rbp), %rcx
callq 0x356a0
movq -0x10(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl $0x3, %edi
leaq -0xa8(%rbp), %rcx
callq 0x356a0
leaq -0x60(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl $0x3, %edi
callq 0x35770
callq 0x9720
movaps %xmm0, %xmm1
movsd 0x8755b(%rip), %xmm0    # 0xbce78
subsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl $0x3, %edi
callq 0x35770
movsd %xmm0, -0xc0(%rbp)
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
callq 0x9e00
movaps %xmm0, %xmm1
movsd -0xc0(%rbp), %xmm0
divsd %xmm1, %xmm0
callq 0x9720
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x8(%rbp), %rsi
addq $0x18, %rsi
leaq -0xa0(%rbp), %rdx
movl $0x3, %edi
leaq -0xa8(%rbp), %rcx
callq 0x356a0
leaq -0xa0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl $0x3, %edi
callq 0x35770
movsd %xmm0, -0xb0(%rbp)
leaq -0xa0(%rbp), %rsi
leaq -0x40(%rbp), %rdx
movl $0x3, %edi
callq 0x35770
movsd %xmm0, -0xb8(%rbp)
leaq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl $0x3, %edi
callq 0x35770
movsd -0xb8(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0xb0(%rbp), %xmm0
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x35a1c
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x8742c(%rip), %xmm1    # 0xbce58
subsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jbe 0x35a5f
movq -0x20(%rbp), %rax
movsd 0x8740f(%rip), %xmm0    # 0xbce60
addsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x35a38
jmp 0x35a61
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x873ef(%rip), %xmm1    # 0xbce60
ucomisd %xmm1, %xmm0
jbe 0x35a95
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x873d9(%rip), %xmm1    # 0xbce60
subsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x35a61
addq $0xc0, %rsp
popq %rbp
retq
nop