// File: DoubleString[P]RtConverter/src/Rtklib/binex.cpp
// Function: bamboo::decode_bnx_7f_05(bamboo::raw_t*, unsigned char*, int)
static int decode_bnx_7f_05(raw_t *raw, unsigned char *buff, int len)
{
    obsd_t data={{0}};
    double clkoff=0.0,toff[16]={0};
    char *msg;
    unsigned char *p=buff;
    unsigned int flag;
    int i,nsat,nobs,prn,sys,sat,clkrst=0,rsys=0,nsys=0,tsys[16]={0};
    
    trace(4,"decode_bnx_7f_05\n");
    
    raw->obs.n=0;
    flag=U1(p++);
    nsat=(int)(flag&0x3F)+1;
    
    if (flag&0x80) { /* rxclkoff */
        clkrst=getbitu(p,0, 2);
        clkoff=getbits(p,2,22)*1E-9; p+=3;
    }
    if (flag&0x40) { /* systime */
        nsys=getbitu(p,0,4);
        rsys=getbitu(p,4,4); p++;
        for (i=0;i<nsys;i++) {
            toff[i]=getbits(p,0,24)*1E-9;
            tsys[i]=getbitu(p,28,4); p+=4;
        }
    }
    for (i=0;i<nsat;i++) {
        prn =U1(p++);
        nobs=getbitu(p,1,3);
        sys =getbitu(p,4,4); p++;
        
        trace(5,"binex 0x7F-05 PRN=%3d SYS=%d NOBS=%d\n",prn,sys,nobs);
        
        switch (sys) {
            case 0: sat=satno(SYS_GPS,prn); break;
            case 1: sat=satno(SYS_GLO,prn); break;
            case 2: sat=satno(SYS_SBS,prn); break;
            case 3: sat=satno(SYS_GAL,prn); break;
            case 4: sat=satno(SYS_CMP,prn); break;
            case 5: sat=satno(SYS_QZS,prn); break;
            default: sat=0; break;
        }
        /* decode binex mesaage 0x7F-05 obs data */
        if (!(p=decode_bnx_7f_05_obs(raw,p,sat,nobs,&data))) return -1;
        
        if ((int)(p-buff)>len) {
            trace(2,"binex 0x7F-05 length error: nsat=%2d len=%d\n",nsat,len);
            return -1;
        }
        /* save obs data to obs buffer */
        if (data.sat&&raw->obs.n<MAXOBS) {
            raw->obs.data[raw->obs.n++]=data;
        }
    }
    if (raw->outtype) {
        msg=raw->msgtype+strlen(raw->msgtype);
        sprintf(msg," nsat=%2d",nsat);
    }
    return raw->obs.n>0?1:0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0x93d0
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x93d0
movq -0x18(%rbp), %rax
movq %rax, -0x120(%rbp)
movl $0x0, -0x140(%rbp)
movl $0x0, -0x144(%rbp)
movl $0x0, -0x148(%rbp)
leaq -0x190(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x93d0
movl $0x4, %edi
leaq 0x5edb7(%rip), %rsi     # 0xbec23
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rax
movl $0x0, 0x1d20(%rax)
movq -0x120(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x120(%rbp)
movzbl (%rax), %eax
movl %eax, -0x124(%rbp)
movl -0x124(%rbp), %eax
andl $0x3f, %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
movl -0x124(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x5ff1a
movq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x8bfc0
movl %eax, -0x140(%rbp)
movq -0x120(%rbp), %rdi
movl $0x2, %esi
movl $0x16, %edx
callq 0x8c050
cvtsi2sd %eax, %xmm0
movsd 0x5dea4(%rip), %xmm1    # 0xbdda0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x120(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x120(%rbp)
movl -0x124(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x60009
movq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x8bfc0
movl %eax, -0x148(%rbp)
movq -0x120(%rbp), %rdi
movl $0x4, %edx
movl %edx, %esi
callq 0x8bfc0
movl %eax, -0x144(%rbp)
movq -0x120(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x120(%rbp)
movl $0x0, -0x128(%rbp)
movl -0x128(%rbp), %eax
cmpl -0x148(%rbp), %eax
jge 0x60007
movq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x8c050
cvtsi2sd %eax, %xmm0
movsd 0x5ddf9(%rip), %xmm1    # 0xbdda0
mulsd %xmm1, %xmm0
movslq -0x128(%rbp), %rax
movsd %xmm0, -0x110(%rbp,%rax,8)
movq -0x120(%rbp), %rdi
movl $0x1c, %esi
movl $0x4, %edx
callq 0x8bfc0
movl %eax, %ecx
movslq -0x128(%rbp), %rax
movl %ecx, -0x190(%rbp,%rax,4)
movq -0x120(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x120(%rbp)
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
jmp 0x5ff7a
jmp 0x60009
movl $0x0, -0x128(%rbp)
movl -0x128(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x6024d
movq -0x120(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x120(%rbp)
movzbl (%rax), %eax
movl %eax, -0x134(%rbp)
movq -0x120(%rbp), %rdi
movl $0x1, %esi
movl $0x3, %edx
callq 0x8bfc0
movl %eax, -0x130(%rbp)
movq -0x120(%rbp), %rdi
movl $0x4, %edx
movl %edx, %esi
callq 0x8bfc0
movl %eax, -0x138(%rbp)
movq -0x120(%rbp), %rax
incq %rax
movq %rax, -0x120(%rbp)
movl -0x134(%rbp), %edx
movl -0x138(%rbp), %ecx
movl -0x130(%rbp), %r8d
leaq 0x5eb93(%rip), %rsi     # 0xbec35
xorl %eax, %eax
movl $0x5, %edi
callq 0x8b980
movl -0x138(%rbp), %eax
movq %rax, -0x198(%rbp)
subq $0x5, %rax
ja 0x6016f
movq -0x198(%rbp), %rax
leaq 0x5df69(%rip), %rcx     # 0xbe03c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x134(%rbp), %esi
movl $0x1, %edi
callq 0x8b1b0
movl %eax, -0x13c(%rbp)
jmp 0x60179
movl -0x134(%rbp), %esi
movl $0x4, %edi
callq 0x8b1b0
movl %eax, -0x13c(%rbp)
jmp 0x60179
movl -0x134(%rbp), %esi
movl $0x2, %edi
callq 0x8b1b0
movl %eax, -0x13c(%rbp)
jmp 0x60179
movl -0x134(%rbp), %esi
movl $0x8, %edi
callq 0x8b1b0
movl %eax, -0x13c(%rbp)
jmp 0x60179
movl -0x134(%rbp), %esi
movl $0x20, %edi
callq 0x8b1b0
movl %eax, -0x13c(%rbp)
jmp 0x60179
movl -0x134(%rbp), %esi
movl $0x10, %edi
callq 0x8b1b0
movl %eax, -0x13c(%rbp)
jmp 0x60179
movl $0x0, -0x13c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x120(%rbp), %rsi
movl -0x13c(%rbp), %edx
movl -0x130(%rbp), %ecx
leaq -0x80(%rbp), %r8
callq 0x602d0
movq %rax, -0x120(%rbp)
cmpq $0x0, %rax
jne 0x601b2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x602c4
movq -0x120(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
cmpl -0x1c(%rbp), %eax
jle 0x601ed
movl -0x12c(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x2, %edi
leaq 0x5ea81(%rip), %rsi     # 0xbec5b
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x602c4
cmpb $0x0, -0x70(%rbp)
je 0x60237
movq -0x10(%rbp), %rax
cmpl $0x40, 0x1d20(%rax)
jge 0x60237
movq -0x10(%rbp), %rax
movq 0x1d28(%rax), %rdi
movq -0x10(%rbp), %rcx
movl 0x1d20(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x1d20(%rcx)
cltq
imulq $0x60, %rax, %rax
addq %rax, %rdi
leaq -0x80(%rbp), %rsi
movl $0x60, %edx
callq 0x9610
jmp 0x60239
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
jmp 0x60013
movq -0x10(%rbp), %rax
cmpl $0x0, 0x81a8c(%rax)
je 0x602aa
movq -0x10(%rbp), %rax
addq $0x70e70, %rax          # imm = 0x70E70
movq %rax, -0x1a0(%rbp)
movq -0x10(%rbp), %rdi
addq $0x70e70, %rdi          # imm = 0x70E70
callq 0x92e0
movq %rax, %rcx
movq -0x1a0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
movl -0x12c(%rbp), %edx
leaq 0x682cf(%rip), %rsi     # 0xc8572
movb $0x0, %al
callq 0x9150
movq -0x10(%rbp), %rax
movl 0x1d20(%rax), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovgl %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq