// File: 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
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl -0x4(%rbp), %eax
shll %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x94f0
movq %rax, -0x30(%rbp)
movl $0x2, %edi
movl $0x8, %esi
callq 0x94f0
movq %rax, -0x38(%rbp)
movl $0x0, -0x4c(%rbp)
cmpl $0x1, -0x4(%rbp)
jle 0x36c9a
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movl $0x2, %esi
callq 0x61340
movl %eax, -0x4c(%rbp)
cmpl $0x0, %eax
jne 0x36c95
movq -0x38(%rbp), %rax
movsd (%rax), %xmm1
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x36c35
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x4(%rbp), %rdx
shlq $0x3, %rdx
callq 0x9610
cmpq $0x0, -0x20(%rbp)
je 0x36c11
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x4(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movslq -0x4(%rbp), %rdx
shlq $0x3, %rdx
callq 0x9610
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x8(%rax)
jmp 0x36c93
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x4(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movslq -0x4(%rbp), %rdx
shlq $0x3, %rdx
callq 0x9610
cmpq $0x0, -0x20(%rbp)
je 0x36c71
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x4(%rbp), %rdx
shlq $0x3, %rdx
callq 0x9610
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x8(%rax)
jmp 0x36c95
jmp 0x36dcd
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
callq 0x39050
cvtsi2sd %eax, %xmm0
movsd 0x8519b(%rip), %xmm1    # 0xbbe60
mulsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x40(%rbp), %xmm1
movaps 0x86517(%rip), %xmm0    # 0xbd220
pand %xmm0, %xmm1
movsd 0x8514b(%rip), %xmm0    # 0xbbe60
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x8(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x36dcb
movq -0x18(%rbp), %rax
movsd 0x85110(%rip), %xmm1    # 0xbbe60
addsd (%rax), %xmm1
subsd -0x48(%rbp), %xmm1
movaps 0x864c0(%rip), %xmm0    # 0xbd220
pand %xmm0, %xmm1
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x850ec(%rip), %xmm2    # 0xbbe60
subsd %xmm2, %xmm0
subsd -0x48(%rbp), %xmm0
movaps 0x8649c(%rip), %xmm2    # 0xbd220
pand %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x36da5
movq -0x18(%rbp), %rax
movsd 0x850c6(%rip), %xmm0    # 0xbbe60
addsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x36dbe
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x850ab(%rip), %xmm1    # 0xbbe60
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x36dcd
movq -0x30(%rbp), %rdi
callq 0x9900
movq -0x38(%rbp), %rdi
callq 0x9900
movl -0x4c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)