// File: /workspace/github_cpp_makefile_star2_O1/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, -0x48(%rbp)
movq %r8, -0x80(%rbp)
movq %rcx, -0x78(%rbp)
movq %rdx, -0x98(%rbp)
movq %rsi, -0x38(%rbp)
movl %edi, %r15d
movq 0x10(%rbp), %r13
movl %edi, %esi
callq 0x4e730
movq %rax, -0x60(%rbp)
movl %r15d, %edi
movl $0x1, %esi
callq 0x4e5e2
movq %rax, %r14
movl %r15d, %edi
movl $0x1, %esi
callq 0x4e5e2
movq %rax, %r12
movl %r15d, %edi
movl $0x1, %esi
callq 0x4e5e2
movq %rax, -0x58(%rbp)
movl %r15d, %edi
movl $0x1, %esi
callq 0x4e5e2
movq %rax, -0x50(%rbp)
leal -0x1(%r15), %ebx
movq $0x0, (%r14,%rbx,8)
movq -0x80(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%r12,%rbx,8)
addsd 0x38830(%rip), %xmm0    # 0x6bc78
callq 0x8ad0
movq -0x78(%rbp), %r11
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %r10
movq %r12, %r9
movq %r14, %rsi
movsd %xmm0, (%r10,%rbx,8)
movsd (%r12,%rbx,8), %xmm1
subsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
setae %al
leaq 0x397cd(%rip), %rdx     # 0x6cc50
movsd (%rdx,%rax,8), %xmm0
movsd %xmm0, (%rdi,%rbx,8)
leal 0x1(%r15), %eax
movl %eax, -0x6c(%rbp)
movslq %r15d, %rax
movl %eax, %r14d
movl -0x38(%rbp), %r12d
shlq $0x3, %rax
movq %rax, -0xa0(%rbp)
movsd 0x39797(%rip), %xmm4    # 0x6cc48
xorl %r8d, %r8d
movapd 0x37614(%rip), %xmm3    # 0x6aad0
movq %rbx, -0xa8(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x2c(%rbp)
movq %rsi, -0x90(%rbp)
movq %r9, -0x88(%rbp)
movl %ebx, %eax
mulsd %xmm1, %xmm1
divsd (%r11,%rax,8), %xmm1
addsd (%rsi,%rax,8), %xmm1
ucomisd %xmm1, %xmm4
jbe 0x335f4
testq %rax, %rax
je 0x33649
movsd %xmm4, -0xb0(%rbp)
movq %r8, -0x68(%rbp)
leal -0x1(%rax), %ebx
movsd %xmm1, (%rsi,%rbx,8)
testl %eax, %eax
movq -0xa0(%rbp), %r11
jle 0x33568
movslq %ebx, %rcx
movq -0x60(%rbp), %rdx
leaq (%rdx,%rcx,8), %rcx
leaq (%rdx,%rax,8), %rdx
movq -0x98(%rbp), %rsi
leaq (%rsi,%rax,8), %rsi
movq %rax, %rdi
xorl %r8d, %r8d
movsd (%r10,%rax,8), %xmm0
subsd (%r9,%rax,8), %xmm0
mulsd (%rsi,%r8), %xmm0
addsd (%rdx,%r8), %xmm0
movsd %xmm0, (%rcx,%r8)
addq %r11, %r8
decq %rdi
jne 0x33542
movq -0x80(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
movl %ebx, %eax
imull -0x6c(%rbp), %eax
movq -0x60(%rbp), %rcx
addsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r9,%rbx,8)
addsd 0x386ea(%rip), %xmm0    # 0x6bc78
callq 0x8ad0
movq -0x58(%rbp), %r10
movq -0x88(%rbp), %r9
movsd %xmm0, (%r10,%rbx,8)
movsd (%r9,%rbx,8), %xmm1
subsd %xmm0, %xmm1
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
setae %al
leaq 0x3968e(%rip), %rdx     # 0x6cc50
movsd (%rdx,%rax,8), %xmm0
movq -0x50(%rbp), %rdi
movsd %xmm0, (%rdi,%rbx,8)
movq -0x90(%rbp), %rsi
movq -0x68(%rbp), %r8
movq -0x78(%rbp), %r11
movapd 0x374e9(%rip), %xmm3    # 0x6aad0
movsd -0xb0(%rbp), %xmm4
jmp 0x33760
cmpl -0xa8(%rbp), %eax
je 0x33776
leal 0x1(%rax), %ebx
movsd 0x8(%rdi,%rax,8), %xmm0
addsd 0x8(%r10,%rax,8), %xmm0
movsd %xmm0, 0x8(%r10,%rax,8)
movsd 0x8(%r9,%rax,8), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rdi,%rax,8), %xmm0
movapd %xmm0, %xmm2
xorpd %xmm3, %xmm2
xorl %ecx, %ecx
ucomisd %xmm0, %xmm2
setae %cl
subsd (%rdx,%rcx,8), %xmm2
movsd %xmm2, 0x8(%rdi,%rax,8)
jmp 0x33760
movl -0x3c(%rbp), %ebx
cmpl -0x38(%rbp), %ebx
jge 0x336a3
testl %ebx, %ebx
je 0x33662
movslq -0x2c(%rbp), %rax
ucomisd (%r13,%rax,8), %xmm1
jbe 0x33665
movl %ebx, -0x2c(%rbp)
testl %r15d, %r15d
jle 0x3368f
movl %ebx, %eax
imull %r15d, %eax
cltq
movq -0x48(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
xorl %ecx, %ecx
movsd (%r10,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r14
jne 0x3367c
movslq %ebx, %rax
incl %ebx
movl %ebx, -0x3c(%rbp)
movsd %xmm1, (%r13,%rax,8)
jmp 0x33729
movl -0x2c(%rbp), %edx
movslq %edx, %rax
movsd (%r13,%rax,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x33715
testl %r15d, %r15d
jle 0x336df
imull %r15d, %edx
movslq %edx, %rcx
movq -0x48(%rbp), %rdx
leaq (%rdx,%rcx,8), %rcx
xorl %edx, %edx
movsd (%r10,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %r14
jne 0x336cc
movsd %xmm1, (%r13,%rax,8)
cmpl $0x0, -0x38(%rbp)
jle 0x33713
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rdx
movsd (%r13,%rax,8), %xmm0
ucomisd (%r13,%rdx,8), %xmm0
movl %eax, %edx
ja 0x33707
movl %ecx, %edx
incq %rax
movl %edx, %ecx
cmpq %rax, %r12
jne 0x336f0
jmp 0x33715
xorl %edx, %edx
movl %edx, -0x2c(%rbp)
movslq %edx, %rax
movsd (%r13,%rax,8), %xmm4
leaq 0x39527(%rip), %rdx     # 0x6cc50
movsd (%rdi), %xmm0
addsd (%r10), %xmm0
movsd %xmm0, (%r10)
movsd (%r9), %xmm1
subsd %xmm0, %xmm1
movsd (%rdi), %xmm0
movapd %xmm0, %xmm2
xorpd %xmm3, %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
setae %al
subsd (%rdx,%rax,8), %xmm2
movsd %xmm2, (%rdi)
xorl %ebx, %ebx
incl %r8d
cmpl $0x2710, %r8d           # imm = 0x2710
jne 0x334df
movl $0x2710, %r8d           # imm = 0x2710
movq %r8, -0x68(%rbp)
cmpl $0x2, -0x38(%rbp)
jl 0x33821
movq -0x38(%rbp), %rax
decl %eax
movq %rax, -0x38(%rbp)
leaq (,%r14,8), %rax
movq -0x48(%rbp), %rcx
leaq (%rcx,%r14,8), %rcx
movl $0x1, %edx
xorl %esi, %esi
xorl %edi, %edi
movq %rdi, %r8
movl %esi, %edi
movq -0x48(%rbp), %r9
leaq (%r9,%rdi,8), %r9
leaq 0x1(%r8), %rdi
movq %rcx, %r10
movq %rdx, %r11
movsd (%r13,%r8,8), %xmm0
movsd (%r13,%r11,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x33807
movsd %xmm1, (%r13,%r8,8)
movsd %xmm0, (%r13,%r11,8)
testl %r15d, %r15d
jle 0x33807
xorl %ebx, %ebx
movsd (%r9,%rbx,8), %xmm0
movsd (%r10,%rbx,8), %xmm1
movsd %xmm1, (%r9,%rbx,8)
movsd %xmm0, (%r10,%rbx,8)
incq %rbx
cmpq %rbx, %r14
jne 0x337e7
incq %r11
addq %rax, %r10
cmpq %r12, %r11
jne 0x337be
incq %rdx
addq %rax, %rcx
addl %r15d, %esi
cmpq -0x38(%rbp), %rdi
jne 0x337a7
movq -0x60(%rbp), %rdi
callq 0x87b0
movq -0x90(%rbp), %rdi
callq 0x87b0
movq -0x88(%rbp), %rdi
callq 0x87b0
movq -0x58(%rbp), %rdi
callq 0x87b0
movq -0x50(%rbp), %rdi
callq 0x87b0
xorl %eax, %eax
cmpl $0x2710, -0x68(%rbp)    # imm = 0x2710
jae 0x33871
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x8ea8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3385f