// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rnxobs/Com.cpp
// Function: bamboo::ambslv_(int, double*, double*, double*, double*)
int ambslv_(int ncad, double* q22, double* bias,double* bias_sec,double* disall) {
	/**********************************************
	 * parameter:
	 * 	input:  ncad          -- # of candidate ambiguities
	 * 		    q22           -- cofactor matrix
	 * 	output: bias          -- float / fixed ambiguity estimates
	 *          disall        -- norm of optimum & suboptimum solutions
	 */
	double* F = (double*) calloc(2 * ncad, sizeof(double));
	double* s = (double*) calloc(2, sizeof(double));
	double dump,f;
	int info  = 0;
	if (ncad > 1) {
		if(!(info = lambda(ncad, 2, bias, q22, F, s))){
			if (s[0] < s[1]) {
				memcpy(bias, F, sizeof(double) * ncad);
				if(bias_sec!=NULL)
					memcpy(bias_sec,F + ncad,sizeof(double) * ncad);
				disall[0] = s[0];
				disall[1] = s[1];
			} else {
				memcpy(bias, F + ncad, sizeof(double) * ncad);
				if(bias_sec!=NULL)
					memcpy(bias_sec,F,sizeof(double) * ncad);
				disall[0] = s[1];
				disall[1] = s[0];
			}
		}
	} else {
		f = dump = bias[0];
		bias[0] = NINT(bias[0]) * 1.0;
		dump = bias[0] - dump;
		disall[0] = dump * dump / q22[0];

		dump = 1.0 - fabs(dump);
		disall[1] = dump * dump / q22[0];
		if(bias_sec !=NULL)
			bias_sec[0] = fabs(bias[0] + 1.0 - f) < fabs(bias[0] - 1.0 -f) ? bias[0] + 1.0 : bias[0] - 1.0;
	}
	free(F);
	free(s);
	return info;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r15
movq %rcx, -0x38(%rbp)
movq %rdx, %r14
movq %rsi, -0x30(%rbp)
movl %edi, %ebx
leal (%rbx,%rbx), %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x8440
movq %rax, %r12
movl $0x2, %edi
movl $0x8, %esi
callq 0x8440
movq %rax, %r13
cmpl $0x2, %ebx
movq %r12, -0x40(%rbp)
jl 0x1fdcc
movq %r15, -0x50(%rbp)
movl %ebx, %edi
movl $0x2, %esi
movq %r14, %rdx
movq -0x30(%rbp), %rcx
movq %r12, %r8
movq %r13, %r9
callq 0x32d4c
movl %eax, %r15d
testl %eax, %eax
jne 0x1fedb
movsd (%r13), %xmm0
movsd 0x8(%r13), %xmm1
movsd %xmm0, -0x30(%rbp)
movsd %xmm1, -0x48(%rbp)
ucomisd %xmm0, %xmm1
movl %ebx, %ebx
jbe 0x1fe96
leaq (,%rbx,8), %r15
movq %r14, %rdi
movq -0x40(%rbp), %r12
movq %r12, %rsi
movq %r15, %rdx
callq 0x84f0
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x1fdb5
leaq (%r12,%rbx,8), %rsi
movq %r15, %rdx
callq 0x84f0
movq -0x50(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x48(%rbp), %xmm0
jmp 0x1fed3
movsd (%r14), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x4acfb(%rip), %rcx     # 0x6aae0
movsd (%rcx,%rax,8), %xmm1
addsd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm1
cvtdq2pd %xmm1, %xmm1
movlpd %xmm1, (%r14)
subsd %xmm0, %xmm1
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movq -0x30(%rbp), %rax
divsd (%rax), %xmm2
movsd %xmm2, (%r15)
andpd 0x49b14(%rip), %xmm1    # 0x69930
movsd 0x49afc(%rip), %xmm2    # 0x69920
subsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
divsd (%rax), %xmm2
movsd %xmm2, 0x8(%r15)
xorl %r15d, %r15d
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x1fedb
movsd (%r14), %xmm1
movsd 0x49acd(%rip), %xmm2    # 0x69920
addsd %xmm1, %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
movapd 0x49ac9(%rip), %xmm4    # 0x69930
andpd %xmm4, %xmm3
addsd 0x4ab3d(%rip), %xmm1    # 0x6a9b0
movapd %xmm1, %xmm5
subsd %xmm0, %xmm5
andpd %xmm4, %xmm5
cmpltsd %xmm5, %xmm3
andpd %xmm3, %xmm2
andnpd %xmm1, %xmm3
orpd %xmm2, %xmm3
movlpd %xmm3, (%rax)
jmp 0x1fedb
movq -0x40(%rbp), %r15
leaq (%r15,%rbx,8), %rsi
shlq $0x3, %rbx
movq %r14, %rdi
movq %rbx, %rdx
callq 0x84f0
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x1fec1
movq %r15, %rsi
movq %rbx, %rdx
callq 0x84f0
movq -0x50(%rbp), %rax
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
xorl %r15d, %r15d
movq -0x40(%rbp), %rdi
callq 0x87b0
movq %r13, %rdi
callq 0x87b0
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq