// File: /workspace/github_cpp_makefile_star2_O3/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 0x4ddc1
movq %rax, -0x60(%rbp)
movl %r15d, %edi
movl $0x1, %esi
callq 0x4dc73
movq %rax, %r14
movl %r15d, %edi
movl $0x1, %esi
callq 0x4dc73
movq %rax, %r12
movl %r15d, %edi
movl $0x1, %esi
callq 0x4dc73
movq %rax, -0x58(%rbp)
movl %r15d, %edi
movl $0x1, %esi
callq 0x4dc73
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 0x38e66(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
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 0x39e03(%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 0x39dcd(%rip), %xmm4    # 0x6cc48
xorl %r8d, %r8d
movapd 0x37c4a(%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 0x32fbd
testq %rax, %rax
je 0x33012
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 0x32f31
movl %ebx, %ecx
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 0x32f0b
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 0x38d21(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
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 0x39cc5(%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 0x37b20(%rip), %xmm3    # 0x6aad0
movsd -0xb0(%rbp), %xmm4
jmp 0x33129
cmpl -0xa8(%rbp), %eax
je 0x3313f
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 0x33129
movl -0x3c(%rbp), %ebx
cmpl -0x38(%rbp), %ebx
jge 0x3306c
testl %ebx, %ebx
je 0x3302b
movslq -0x2c(%rbp), %rax
ucomisd (%r13,%rax,8), %xmm1
jbe 0x3302e
movl %ebx, -0x2c(%rbp)
testl %r15d, %r15d
jle 0x33058
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 0x33045
movslq %ebx, %rax
incl %ebx
movl %ebx, -0x3c(%rbp)
movsd %xmm1, (%r13,%rax,8)
jmp 0x330f2
movl -0x2c(%rbp), %edx
movslq %edx, %rax
movsd (%r13,%rax,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x330de
testl %r15d, %r15d
jle 0x330a8
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 0x33095
movsd %xmm1, (%r13,%rax,8)
cmpl $0x0, -0x38(%rbp)
jle 0x330dc
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rdx
movsd (%r13,%rax,8), %xmm0
ucomisd (%r13,%rdx,8), %xmm0
movl %eax, %edx
ja 0x330d0
movl %ecx, %edx
incq %rax
movl %edx, %ecx
cmpq %rax, %r12
jne 0x330b9
jmp 0x330de
xorl %edx, %edx
movl %edx, -0x2c(%rbp)
movslq %edx, %rax
movsd (%r13,%rax,8), %xmm4
leaq 0x39b5e(%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 0x32ea9
movl $0x2710, %r8d           # imm = 0x2710
movq %r8, -0x68(%rbp)
cmpl $0x2, -0x38(%rbp)
jl 0x331ea
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 0x331d0
movsd %xmm1, (%r13,%r8,8)
movsd %xmm0, (%r13,%r11,8)
testl %r15d, %r15d
jle 0x331d0
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 0x331b0
incq %r11
addq %rax, %r10
cmpq %r12, %r11
jne 0x33187
incq %rdx
addq %rax, %rcx
addl %r15d, %esi
cmpq -0x38(%rbp), %rdi
jne 0x33170
movq -0x60(%rbp), %rdi
callq 0x87a0
movq -0x90(%rbp), %rdi
callq 0x87a0
movq -0x88(%rbp), %rdi
callq 0x87a0
movq -0x58(%rbp), %rdi
callq 0x87a0
movq -0x50(%rbp), %rdi
callq 0x87a0
xorl %eax, %eax
cmpl $0x2710, -0x68(%rbp)    # imm = 0x2710
jae 0x3323a
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x8e9d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x33228