// File: DoubleString[P]RtConverter/src/Rnxobs/Com.cpp
// Function: bamboo::ambslv(int, double*, double*, double*)
int ambslv(int ncad, double* q22, double* bias, 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;
	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);
				disall[0] = s[0];
				disall[1] = s[1];
			} else {
				memcpy(bias, F + ncad, sizeof(double) * ncad);
				disall[0] = s[1];
				disall[1] = s[0];
			}
		}
	} else {
		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];
	}
	free(F);
	free(s);
	return info;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl -0x4(%rbp), %eax
shll %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x94f0
movq %rax, -0x28(%rbp)
movl $0x2, %edi
movl $0x8, %esi
callq 0x94f0
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x1, -0x4(%rbp)
jle 0x36a83
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
movl $0x2, %esi
callq 0x61340
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jne 0x36a7e
movq -0x30(%rbp), %rax
movsd (%rax), %xmm1
movq -0x30(%rbp), %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x36a3a
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x4(%rbp), %rdx
shlq $0x3, %rdx
callq 0x9610
movq -0x30(%rbp), %rax
movsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x8(%rax)
jmp 0x36a7c
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x4(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movslq -0x4(%rbp), %rdx
shlq $0x3, %rdx
callq 0x9610
movq -0x30(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rax
movsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x8(%rax)
jmp 0x36a7e
jmp 0x36b1d
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
callq 0x39050
cvtsi2sd %eax, %xmm0
movsd 0x853b7(%rip), %xmm1    # 0xbbe60
mulsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
subsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x38(%rbp), %xmm1
movaps 0x86733(%rip), %xmm0    # 0xbd220
pand %xmm0, %xmm1
movsd 0x85367(%rip), %xmm0    # 0xbbe60
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movq -0x28(%rbp), %rdi
callq 0x9900
movq -0x30(%rbp), %rdi
callq 0x9900
movl -0x3c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)