// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3.cpp
// Function: bamboo::sigindex(int, unsigned char const*, int const*, int, char const*, int*)
static void sigindex(int sys, const unsigned char *code, const int *freq, int n,
                     const char *opt, int *ind)
{
    int i,nex,pri,pri_h[8]={0},index[8]={0},ex[32]={0};
    
    /* test code priority */
    for (i=0;i<n;i++) {
        if (!code[i]) continue;
        
        if (freq[i]>NFREQ) { /* save as extended signal if freq > NFREQ */
            ex[i]=1;
            continue;
        }
        /* code priority */
        pri=getcodepri(sys,code[i],opt);
        
        /* select highest priority signal */
        if (pri>pri_h[freq[i]-1]) {
            if (index[freq[i]-1]) ex[index[freq[i]-1]-1]=1;
            pri_h[freq[i]-1]=pri;
            index[freq[i]-1]=i+1;
        }
        else ex[i]=1;
    }
    /* signal index in obs data */
    for (i=nex=0;i<n;i++) {
        if (ex[i]==0) ind[i]=freq[i]-1;
        else if (nex<NEXOBS) ind[i]=NFREQ+nex++;
        else { /* no space in obs data */
            trace(2,"rtcm msm: no space in obs data sys=%d code=%d\n",sys,code[i]);
            ind[i]=-1;
        }
#if 0
        trace(2,"sig pos: sys=%d code=%d ex=%d ind=%d\n",sys,code[i],ex[i],ind[i]);
#endif
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x93d0
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x93d0
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x93d0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7c6f0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x7c60a
jmp 0x7c6e2
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpl $0x3, (%rax,%rcx,4)
jle 0x7c62c
movslq -0x34(%rbp), %rax
movl $0x1, -0x100(%rbp,%rax,4)
jmp 0x7c6e2
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb (%rax,%rcx), %al
movq -0x28(%rbp), %rdx
movzbl %al, %esi
callq 0x8bdb0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl -0x60(%rbp,%rcx,4), %eax
jle 0x7c6d1
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
cltq
cmpl $0x0, -0x80(%rbp,%rax,4)
je 0x7c69e
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
cltq
movl -0x80(%rbp,%rax,4), %eax
subl $0x1, %eax
cltq
movl $0x1, -0x100(%rbp,%rax,4)
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rdx
movl (%rax,%rdx,4), %eax
subl $0x1, %eax
cltq
movl %ecx, -0x60(%rbp,%rax,4)
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rdx
movl (%rax,%rdx,4), %eax
subl $0x1, %eax
cltq
movl %ecx, -0x80(%rbp,%rax,4)
jmp 0x7c6e0
movslq -0x34(%rbp), %rax
movl $0x1, -0x100(%rbp,%rax,4)
jmp 0x7c6e2
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x7c5eb
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7c797
movslq -0x34(%rbp), %rax
cmpl $0x0, -0x100(%rbp,%rax,4)
jne 0x7c733
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edx
subl $0x1, %edx
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x7c787
cmpl $0x0, -0x38(%rbp)
jge 0x7c754
movl -0x38(%rbp), %edx
movl %edx, %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
addl $0x3, %edx
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x7c785
movl -0x4(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movl $0x2, %edi
leaq 0x4558f(%rip), %rsi     # 0xc1cfe
movb $0x0, %al
callq 0x8b980
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x7c787
jmp 0x7c789
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x7c6fe
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq