// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/lambda.cpp
// Function: bamboo::search(int, int, double const*, double const*, double const*, double*, double*)
static int search(int n, int m, const double *L, const double *D,
                  const double *zs, double *zn, double *s)
{
    int i,j,k,c,nn=0,imax=0;
    double newdist,maxdist=1E99,y;
    double *S=zeros(n,n),*dist=mat(n,1),*zb=mat(n,1),*z=mat(n,1),*step=mat(n,1);
    
    k=n-1; dist[k]=0.0;
    zb[k]=zs[k];
    z[k]=ROUND(zb[k]); y=zb[k]-z[k]; step[k]=SGN(y);
    for (c=0;c<LOOPMAX;c++) {
        newdist=dist[k]+y*y/D[k];
        if (newdist<maxdist) {
            if (k!=0) {
                dist[--k]=newdist;
                for (i=0;i<=k;i++)
                    S[k+i*n]=S[k+1+i*n]+(z[k+1]-zb[k+1])*L[k+1+i*n];
                zb[k]=zs[k]+S[k+k*n];
                z[k]=ROUND(zb[k]); y=zb[k]-z[k]; step[k]=SGN(y);
            }
            else {
                if (nn<m) {
                    if (nn==0||newdist>s[imax]) imax=nn;
                    for (i=0;i<n;i++) zn[i+nn*n]=z[i];
                    s[nn++]=newdist;
                }
                else {
                    if (newdist<s[imax]) {
                        for (i=0;i<n;i++) zn[i+imax*n]=z[i];
                        s[imax]=newdist;
                        for (i=imax=0;i<m;i++) if (s[imax]<s[i]) imax=i;
                    }
                    maxdist=s[imax];
                }
                z[0]+=step[0]; y=zb[0]-z[0]; step[0]=-step[0]-SGN(step[0]);
            }
        }
        else {
            if (k==n-1) break;
            else {
                k++;
                z[k]+=step[k]; y=zb[k]-z[k]; step[k]=-step[k]-SGN(step[k]);
            }
        }
    }
    for (i=0;i<m-1;i++) { /* sort by s */
        for (j=i+1;j<m;j++) {
            if (s[i]<s[j]) continue;
            SWAP(s[i],s[j]);
            for (k=0;k<n;k++) SWAP(zn[k+i*n],zn[k+j*n]);
        }
    }
    free(S); free(dist); free(zb); free(z); free(step);
    
    if (c>=LOOPMAX) {
        fprintf(stderr,"%s : search loop count overflow\n",__FILE__);
        return -1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %rbx
movq %r8, -0x78(%rbp)
movq %rcx, -0x70(%rbp)
movq %rdx, -0x90(%rbp)
movq %rsi, -0x80(%rbp)
movl %edi, %r15d
movq 0x10(%rbp), %r14
movl %edi, %esi
callq 0x45d86
movq %rax, -0x58(%rbp)
pushq $0x1
popq %r12
movl %r15d, %edi
movl %r12d, %esi
callq 0x45c3a
movq %rax, -0x50(%rbp)
movl %r15d, %edi
movl %r12d, %esi
callq 0x45c3a
movq %rax, %r13
movl %r15d, %edi
movl %r12d, %esi
callq 0x45c3a
movq %rax, -0x38(%rbp)
movl %r15d, %edi
movl %r12d, %esi
callq 0x45c3a
movq %rax, -0x48(%rbp)
leal -0x1(%r15), %r12d
movq -0x50(%rbp), %rax
andq $0x0, (%rax,%r12,8)
movq -0x78(%rbp), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, (%r13,%r12,8)
addsd 0x34819(%rip), %xmm0    # 0x61c78
callq 0x8ac0
movq -0x70(%rbp), %r8
movq -0x48(%rbp), %rsi
movq %r13, %r11
pushq $0x1
popq %r10
movq -0x50(%rbp), %rdi
movq -0x80(%rbp), %r9
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax,%r12,8)
movsd (%r13,%r12,8), %xmm1
subsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
setae %al
leaq 0x357ac(%rip), %rcx     # 0x62c50
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rsi,%r12,8)
leal 0x1(%r15), %eax
movl %eax, -0x5c(%rbp)
movq %r15, -0x68(%rbp)
movslq %r15d, %rax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
testl %r9d, %r9d
movl $0x0, %ecx
cmovgl %r9d, %ecx
movq %rcx, -0xb0(%rbp)
movq %rax, -0x88(%rbp)
leaq (,%rax,8), %r15
movsd 0x35755(%rip), %xmm4    # 0x62c48
movapd 0x335c5(%rip), %xmm3    # 0x60ac0
xorl %edx, %edx
movl $0x0, -0x3c(%rbp)
xorl %ecx, %ecx
movq %r12, -0xa0(%rbp)
movl %r12d, %eax
movq %r11, -0x98(%rbp)
movl %ecx, -0x2c(%rbp)
cmpl $0x2710, %ecx           # imm = 0x2710
je 0x2d7ba
movl %eax, %ecx
mulsd %xmm1, %xmm1
divsd (%r8,%rcx,8), %xmm1
addsd (%rdi,%rcx,8), %xmm1
ucomisd %xmm1, %xmm4
jbe 0x2d5a7
testl %eax, %eax
je 0x2d6a9
movl %edx, -0x30(%rbp)
leal -0x1(%rax), %r12d
movslq %eax, %rsi
testl %eax, %eax
movl $0x0, %edx
cmovlel %edx, %eax
movsd %xmm1, (%rdi,%r12,8)
movq -0x58(%rbp), %rdx
leaq (%rdx,%rsi,8), %rdx
addq $-0x8, %rdx
movq -0x90(%rbp), %rdi
leaq (%rdi,%rsi,8), %rsi
xorl %edi, %edi
movq -0x38(%rbp), %r8
subq $0x1, %rax
jb 0x2d60e
movsd (%r8,%rcx,8), %xmm0
subsd (%r11,%rcx,8), %xmm0
mulsd (%rsi,%rdi), %xmm0
addsd 0x8(%rdx,%rdi), %xmm0
movsd %xmm0, (%rdx,%rdi)
addq %r15, %rdi
jmp 0x2d57c
cmpl -0xa0(%rbp), %eax
je 0x2d7ba
movl %edx, -0x30(%rbp)
incl %eax
movsd 0x8(%rsi,%rcx,8), %xmm0
movq -0x38(%rbp), %rdx
addsd 0x8(%rdx,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rdx,%rcx,8)
movsd 0x8(%r11,%rcx,8), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rsi,%rcx,8), %xmm0
movapd %xmm0, %xmm2
xorpd %xmm3, %xmm2
xorl %edx, %edx
ucomisd %xmm0, %xmm2
setae %dl
leaq 0x35659(%rip), %r12     # 0x62c50
subsd (%r12,%rdx,8), %xmm2
movsd %xmm2, 0x8(%rsi,%rcx,8)
movl %eax, %r12d
movl -0x2c(%rbp), %ecx
jmp 0x2d7ad
movq -0x78(%rbp), %rax
movsd (%rax,%r12,8), %xmm0
movl %r12d, %eax
imull -0x5c(%rbp), %eax
movq -0x58(%rbp), %rcx
addsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r11,%r12,8)
addsd 0x34642(%rip), %xmm0    # 0x61c78
movsd %xmm4, -0xa8(%rbp)
callq 0x8ac0
movsd -0xa8(%rbp), %xmm4
movapd 0x3346d(%rip), %xmm3    # 0x60ac0
movq -0x98(%rbp), %r11
pushq $0x1
popq %r10
movq -0x80(%rbp), %r9
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax,%r12,8)
movsd (%r11,%r12,8), %xmm1
subsd %xmm0, %xmm1
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
setae %al
leaq 0x355c6(%rip), %rcx     # 0x62c50
movsd (%rcx,%rax,8), %xmm0
movq -0x48(%rbp), %rsi
movsd %xmm0, (%rsi,%r12,8)
movq -0x50(%rbp), %rdi
movl -0x2c(%rbp), %ecx
movq -0x70(%rbp), %r8
jmp 0x2d7ad
movslq %edx, %rax
movl -0x3c(%rbp), %ecx
cmpl %r9d, %ecx
jge 0x2d6eb
testl %ecx, %ecx
je 0x2d6c0
ucomisd (%r14,%rax,8), %xmm1
jbe 0x2d6c2
movl %ecx, %edx
movl %edx, -0x30(%rbp)
movl %ecx, %eax
imull -0x68(%rbp), %eax
cltq
leaq (%rbx,%rax,8), %rax
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0x2d71c
movq -0x38(%rbp), %rdx
movsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
jmp 0x2d6d3
movsd (%r14,%rax,8), %xmm4
ucomisd %xmm1, %xmm4
jbe 0x2d766
imull -0x68(%rbp), %edx
movslq %edx, %rcx
leaq (%rbx,%rcx,8), %rcx
xorl %edx, %edx
cmpq %rdx, %r13
je 0x2d72f
movq -0x38(%rbp), %rsi
movsd (%rsi,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
jmp 0x2d704
movl -0x3c(%rbp), %ecx
movslq %ecx, %rax
incl %ecx
movl %ecx, -0x3c(%rbp)
movsd %xmm1, (%r14,%rax,8)
jmp 0x2d769
movsd %xmm1, (%r14,%rax,8)
xorl %eax, %eax
xorl %edx, %edx
movq -0x48(%rbp), %rsi
movslq %edx, %rcx
movsd (%r14,%rcx,8), %xmm4
cmpq %rax, -0xb0(%rbp)
je 0x2d766
movsd (%r14,%rax,8), %xmm0
ucomisd %xmm4, %xmm0
movl %eax, %ecx
ja 0x2d75f
movl %edx, %ecx
incq %rax
movl %ecx, %edx
jmp 0x2d73d
movl %edx, -0x30(%rbp)
movl -0x2c(%rbp), %ecx
movsd (%rsi), %xmm0
movq -0x38(%rbp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd (%r11), %xmm1
subsd %xmm0, %xmm1
movsd (%rsi), %xmm0
movapd %xmm0, %xmm2
xorpd %xmm3, %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
setae %al
leaq 0x354af(%rip), %rdx     # 0x62c50
subsd (%rdx,%rax,8), %xmm2
movsd %xmm2, (%rsi)
xorl %r12d, %r12d
incl %ecx
movl %r12d, %eax
movl -0x30(%rbp), %edx
jmp 0x2d517
movslq %r9d, %rax
cmpl $0x2, %r9d
cmovll %r10d, %r9d
decl %r9d
movq -0x88(%rbp), %rcx
leaq (%rbx,%rcx,8), %rcx
xorl %edx, %edx
cmpq %r9, %rdx
je 0x2d83e
movslq %r10d, %rsi
movq %rcx, %rdi
cmpq %rax, %rsi
jge 0x2d830
movsd (%r14,%rdx,8), %xmm0
movsd (%r14,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2d7ff
incq %rsi
addq %r15, %rdi
jmp 0x2d7e0
movsd %xmm1, (%r14,%rdx,8)
movsd %xmm0, (%r14,%rsi,8)
xorl %r8d, %r8d
cmpq %r8, %r13
je 0x2d7f7
movsd (%rbx,%r8,8), %xmm0
movsd (%rdi,%r8,8), %xmm1
movsd %xmm1, (%rbx,%r8,8)
movsd %xmm0, (%rdi,%r8,8)
incq %r8
jmp 0x2d80e
incq %rdx
incl %r10d
addq %r15, %rcx
addq %r15, %rbx
jmp 0x2d7d5
movq -0x58(%rbp), %rdi
movq %r11, %rbx
callq 0x8780
movq -0x50(%rbp), %rdi
callq 0x8780
movq %rbx, %rdi
callq 0x8780
movq -0x38(%rbp), %rdi
callq 0x8780
movq -0x48(%rbp), %rdi
callq 0x8780
xorl %eax, %eax
cmpl $0x2710, -0x2c(%rbp)    # imm = 0x2710
jae 0x2d88a
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5873f(%rip), %rax     # 0x85fd0
movq (%rax), %rdi
leaq 0x353fc(%rip), %rsi     # 0x62c97
leaq 0x353de(%rip), %rdx     # 0x62c80
xorl %eax, %eax
callq 0x88c0
pushq $-0x1
popq %rax
jmp 0x2d878