// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rtklib/skytraq.cpp
// Function: bamboo::decode_stqrawx(bamboo::raw_t*)
static int decode_stqrawx(raw_t *raw)
{
    unsigned char *p=raw->buff+4,ind;
    double tow,peri,pr1,cp1;
    int i,j,ver,week,nsat,sys,sig,prn,sat,n=0;
    int gnss_type, signal_type;
    
    trace(4,"decode_stqraw: len=%d\n",raw->len);
    
    if (raw->outtype) {
        sprintf(raw->msgtype,"SKYTRAQ RAWX  (%4d): nsat=%2d",raw->len,U1(p+13));
    }
    ver=U1(p+1);
    raw->iod=U1(p+2);
    week=U2(p+3);
    tow =U4(p+5)*0.001;
    raw->time=gpst2time(week,tow);
    peri=U2(p+9)*0.001;
    nsat=U1(p+13);
    if (raw->len<19+31*nsat) {
        trace(2,"stq raw length error: len=%d nsat=%d\n",raw->len,nsat);
        return -1;
    }
    for (i=0,p+=14;i<nsat&&i<MAXOBS;i++,p+=31) {
        gnss_type=U1(p)&0xF;
        signal_type=(U1(p)>>4)&0xF;
        if (gnss_type==0) { /* GPS */
            sys=SYS_GPS;
            switch (signal_type) {
                case  1: sig=CODE_L1X; break;
                case  2: sig=CODE_L2X; break;
                case  4: sig=CODE_L5X; break;
                default: sig=CODE_L1C; break;
            }
            prn=U1(p+1);
        }
        else if (gnss_type==1) { /* SBAS */
            sys=SYS_SBS;
            sig=CODE_L1C;
            prn=U1(p+1);
        }
        else if (gnss_type==2) { /* GLONASS */
            sys=SYS_GLO;
            switch (signal_type) {
                case  2: sig=CODE_L2C; break;
                case  4: sig=CODE_L3X; break;
                default: sig=CODE_L1C; break;
            }
            prn=U1(p+1);
        }
        else if (gnss_type==3) { /* Galileo */
            sys=SYS_GAL;
            switch (signal_type) {
                case  4: sig=CODE_L5X; break;
                case  5: sig=CODE_L7X; break;
                case  6: sig=CODE_L6X; break;
                default: sig=CODE_L1C; break;
            }
            prn=U1(p+1);
        }
        else if (gnss_type==4) { /* QZSS */
            sys=SYS_QZS;
            switch (signal_type) {
                case  1: sig=CODE_L1X; break;
                case  2: sig=CODE_L2X; break;
                case  4: sig=CODE_L5X; break;
                case  6: sig=CODE_L6X; break;
                default: sig=CODE_L1C; break;
            }
            prn=U1(p+1);
        }
        else if (gnss_type==5) { /* BeiDou */
            sys=SYS_CMP;
            switch (signal_type) {
                case  4: sig=CODE_L7I; break;
                case  6: sig=CODE_L6I; break;
                default: sig=CODE_L2I; break;
            }
            prn=U1(p+1);
        }
        else {
            trace(2,"stq rawx gnss type error: type=%d\n",U1(p));
            continue;
        }
        if (!(sat=satno(sys,prn))) {
            trace(2,"stq raw satellite number error: sys=%d prn=%d\n",sys,prn);
            continue;
        }
        /* set glonass freq channel number */
        if (gnss_type==2) {
            raw->nav.geph[prn-1].frq=(int)(U1(p+2)&0xF)-7;
        }
        ind=U2(p+27);
        pr1=!(ind&1)?0.0:R8(p+ 4);
        cp1=!(ind&4)?0.0:R8(p+12);
        cp1-=floor((cp1+1E9)/2E9)*2E9; /* -10^9 < cp1 < 10^9 */
        
        raw->obs.data[n].P[0]=pr1;
        raw->obs.data[n].L[0]=cp1;
        raw->obs.data[n].D[0]=!(ind&2)?0.0:R4(p+20);
        raw->obs.data[n].SNR[0]=U1(p+3)*4;
        raw->obs.data[n].LLI[0]=0;
        raw->obs.data[n].code[0]=sys==SYS_CMP?CODE_L1I:CODE_L1C;
        
        raw->lockt[sat-1][0]=ind&8?1:0; /* cycle slip */
        
        if (raw->obs.data[n].L[0]!=0.0) {
            raw->obs.data[n].LLI[0]=(unsigned char)raw->lockt[sat-1][0];
            raw->lockt[sat-1][0]=0;
        }
        /* receiver dependent options */
        if (strstr(raw->opt,"-INVCP")) {
            raw->obs.data[n].L[0]*=-1.0;
        }
        raw->obs.data[n].time=raw->time;
        raw->obs.data[n].sat =sat;
        
        for (j=1;j<NFREQ+NEXOBS;j++) {
            raw->obs.data[n].L[j]=raw->obs.data[n].P[j]=0.0;
            raw->obs.data[n].D[j]=0.0;
            raw->obs.data[n].SNR[j]=raw->obs.data[n].LLI[j]=0;
            raw->obs.data[n].code[j]=CODE_NONE;
        }
        n++;
    }
    raw->obs.n=n;
    return n>0?1:0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl 0x81a78(%rdi), %edx
leaq 0x1eb7a(%rip), %rsi     # 0x756e0
movl $0x4, %edi
xorl %eax, %eax
callq 0x4d55d
cmpl $0x0, 0x81a8c(%rbx)
je 0x56b9d
leaq 0x70e70(%rbx), %rdi
movl 0x81a78(%rbx), %edx
movzbl 0x81aa1(%rbx), %ecx
leaq 0x1ec20(%rip), %rsi     # 0x757b6
xorl %eax, %eax
callq 0x8120
movzbl 0x81a96(%rbx), %eax
movl %eax, 0x81a7c(%rbx)
movzbl 0x81a97(%rbx), %edi
movzbl 0x81a98(%rbx), %eax
movl $0x81a99, %ecx          # imm = 0x81A99
leaq -0x35(%rbp), %rdx
movb (%rbx,%rcx), %sil
movb %sil, (%rdx)
decq %rdx
incq %rcx
cmpl $0x81a9d, %ecx          # imm = 0x81A9D
jne 0x56bc1
shll $0x8, %edi
orl %eax, %edi
movl -0x38(%rbp), %eax
cvtsi2sd %rax, %xmm0
mulsd 0x1518d(%rip), %xmm0    # 0x6bd78
callq 0x4f24a
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
movzbl 0x81aa1(%rbx), %ecx
movl 0x81a78(%rbx), %edx
movl %ecx, %eax
shll $0x5, %eax
subl %ecx, %eax
addl $0x13, %eax
cmpl %eax, %edx
jge 0x56c30
leaq 0x1eb18(%rip), %rsi     # 0x75732
movl $0x2, %edi
xorl %eax, %eax
callq 0x4d55d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x56fb3
cmpl $0x40, %ecx
movl $0x40, %r15d
cmovbl %ecx, %r15d
testl %ecx, %ecx
je 0x56f9c
leaq 0x81aa2(%rbx), %rsi
leaq 0x7f670(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0x82a90(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x81aa6(%rbx), %rdx
leaq 0x81aae(%rbx), %rax
movq %rax, -0x70(%rbp)
leaq 0x81ab6(%rbx), %r12
xorl %r13d, %r13d
xorl %eax, %eax
movl $0x0, -0x2c(%rbp)
movl %r15d, -0x54(%rbp)
movl %eax, -0x3c(%rbp)
movq %rdx, -0x60(%rbp)
movzbl (%rsi), %edx
movl %edx, %r14d
andl $0xf, %r14d
cmpl $0x6, %r14d
movq %rsi, -0x50(%rbp)
jae 0x56f36
leal (,%r14,8), %ecx
movabsq $0x2f0101010101, %rax   # imm = 0x2F0101010101
shrq %cl, %rax
movq %rax, -0x90(%rbp)
leaq 0x1e87f(%rip), %rax     # 0x7554c
movl (%rax,%r14,4), %edi
movzbl 0x1(%rsi), %r15d
movl %edi, -0x48(%rbp)
movl %r15d, %esi
callq 0x4d28d
movq %rax, -0x68(%rbp)
testl %eax, %eax
je 0x56f72
cmpl $0x2, %r14d
movq -0x50(%rbp), %rsi
jne 0x56d19
movzbl 0x2(%rsi), %eax
andl $0xf, %eax
addl $-0x7, %eax
movq 0x1d88(%rbx), %rcx
movl %r15d, %edx
imulq $0x98, %rdx, %rdx
movl %eax, -0x90(%rcx,%rdx)
movzbl 0x1c(%rsi), %r14d
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
testb $0x1, %r14b
movq -0x60(%rbp), %rsi
je 0x56d4b
xorl %eax, %eax
leaq -0x31(%rbp), %rcx
movb (%rsi,%rax), %dl
movb %dl, (%rcx)
decq %rcx
incq %rax
cmpl $0x8, %eax
jne 0x56d36
movsd -0x38(%rbp), %xmm1
movsd %xmm1, -0x48(%rbp)
testb $0x4, %r14b
je 0x56d75
xorl %eax, %eax
leaq -0x31(%rbp), %rcx
movq -0x70(%rbp), %rsi
movb (%rsi,%rax), %dl
movb %dl, (%rcx)
decq %rcx
incq %rax
cmpl $0x8, %eax
jne 0x56d60
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
addsd 0x1de0b(%rip), %xmm0    # 0x74b90
movsd 0x1e7db(%rip), %xmm1    # 0x75568
divsd %xmm1, %xmm0
callq 0x8ac0
mulsd 0x1e7ca(%rip), %xmm0    # 0x75568
movsd -0x88(%rbp), %xmm1
subsd %xmm0, %xmm1
movq 0x1d28(%rbx), %rax
movslq -0x2c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x5, %rdx
movsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x38(%rax,%rdx)
movq %rdx, -0x48(%rbp)
movsd %xmm1, 0x20(%rax,%rdx)
xorpd %xmm0, %xmm0
testb $0x2, %r14b
je 0x56df9
xorl %edx, %edx
leaq -0x35(%rbp), %rsi
movb (%r12,%rdx), %dil
movb %dil, (%rsi)
decq %rsi
incq %rdx
cmpl $0x4, %edx
jne 0x56de2
movss -0x38(%rbp), %xmm0
shlq $0x5, %rcx
leaq (%rcx,%rcx,2), %r15
movss %xmm0, 0x50(%rax,%r15)
movq -0x50(%rbp), %rcx
movb 0x3(%rcx), %cl
shlb $0x2, %cl
movb %cl, 0x12(%rax,%r15)
movq 0x1d28(%rbx), %rax
movb $0x0, 0x15(%rax,%r15)
movq 0x1d28(%rbx), %rax
movq -0x90(%rbp), %rcx
movb %cl, 0x18(%rax,%r15)
shrl $0x3, %r14d
andl $0x1, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq -0x68(%rbp), %rax
decl %eax
cltq
leaq (%rax,%rax,2), %rax
movq -0x80(%rbp), %rcx
movsd %xmm0, (%rcx,%rax,8)
movl %r14d, %edx
movq 0x1d28(%rbx), %r14
movsd 0x20(%r14,%r15), %xmm0
ucomisd 0x13a93(%rip), %xmm0    # 0x6a908
jne 0x56e79
jnp 0x56e92
leaq (%rcx,%rax,8), %rax
addq %r15, %r14
movb %dl, 0x15(%r14)
movq $0x0, (%rax)
movq 0x1d28(%rbx), %r14
movq -0x78(%rbp), %rdi
leaq 0x1e912(%rip), %rsi     # 0x757af
callq 0x8160
testq %rax, %rax
je 0x56ec1
movq -0x48(%rbp), %rax
movsd 0x20(%r14,%rax), %xmm0
xorpd 0x13c16(%rip), %xmm0    # 0x6aad0
movlpd %xmm0, 0x20(%r14,%rax)
movupd (%rbx), %xmm0
movupd %xmm0, (%r14,%r15)
movq 0x1d28(%rbx), %rax
movq -0x68(%rbp), %rcx
movb %cl, 0x10(%rax,%r15)
xorl %eax, %eax
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x1d28(%rbx), %rcx
addq %r15, %rcx
movq %r13, 0x40(%rcx,%rax,8)
movq %r13, 0x28(%rcx,%rax,8)
movl $0x0, 0x54(%rcx,%rax,4)
movb %r13b, 0x16(%rax,%rcx)
movq 0x1d28(%rbx), %rcx
addq %r15, %rcx
movb %r13b, 0x13(%rax,%rcx)
movq 0x1d28(%rbx), %rcx
addq %r15, %rcx
movb %r13b, 0x19(%rax,%rcx)
incq %rax
cmpq $0x2, %rax
jne 0x56ee5
incl -0x2c(%rbp)
movl -0x54(%rbp), %r15d
jmp 0x56f51
movl $0x2, %edi
leaq 0x1e892(%rip), %rsi     # 0x757d4
xorl %eax, %eax
callq 0x4d55d
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl -0x3c(%rbp), %eax
incl %eax
addq $0x1f, %rsi
addq $0x1f, %rdx
addq $0x1f, -0x70(%rbp)
addq $0x1f, %r12
cmpl %r15d, %eax
jne 0x56c8b
jmp 0x56fa3
movl $0x2, %edi
leaq 0x1e802(%rip), %rsi     # 0x75780
movl -0x48(%rbp), %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4d55d
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl -0x3c(%rbp), %eax
movl -0x54(%rbp), %r15d
jmp 0x56f54
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x1d20(%rbx)
xorl %eax, %eax
testl %ecx, %ecx
setg %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq