// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rtklib/ublox.cpp
// Function: bamboo::decode_cnav(bamboo::raw_t*, int, int)
static int decode_cnav(raw_t *raw, int sat, int off)
{
    eph_t eph={0};
    unsigned int words[10];
    int i,id,pgn,prn;
    unsigned char *p=raw->buff+6+off;
    
    if (raw->len<48+off) {
        trace(2,"ubx rawsfrbx length error: sat=%d len=%d\n",sat,raw->len);
        return -1;
    }
    for (i=0;i<10;i++,p+=4) words[i]=U4(p)&0x3FFFFFFF; /* 30 bits */
    
    satsys(sat,&prn);
    id=(words[0]>>12)&0x07; /* subframe id (3bit) */
    if (id<1||5<id) {
        trace(2,"ubx rawsfrbx subfrm id error: sat=%2d\n",sat);
        return -1;
    }
    if (prn>5&&prn<59) { /* IGSO/MEO */
        
        for (i=0;i<10;i++) {
            setbitu(raw->subfrm[sat-1]+(id-1)*38,i*30,30,words[i]);
        }
        if (id!=3) return 0;
        
        /* decode beidou D1 ephemeris */
        if (!decode_bds_d1(raw->subfrm[sat-1],&eph)) return 0;
    }
    else { /* GEO (C01-05, C59-63) */
        if (id!=1) return 0;
        
        /* subframe 1 */
        pgn=(words[1]>>14)&0x0F; /* page number (4bit) */
        if (pgn<1||10<pgn) {
            trace(2,"ubx rawsfrbx page number error: sat=%2d\n",sat);
            return -1;
        }
        for (i=0;i<10;i++) {
            setbitu(raw->subfrm[sat-1]+(pgn-1)*38,i*30,30,words[i]);
        }
        if (pgn!=10) return 0;
        
        /* decode beidou D2 ephemeris */
        if (!decode_bds_d2(raw->subfrm[sat-1],&eph)) return 0;
    }
    if (!strstr(raw->opt,"-EPHALL")) {
        if (timediff(eph.toe,raw->nav.eph[sat-1].toe)==0.0&&
            eph.iode==raw->nav.eph[sat-1].iode&&
            eph.iodc==raw->nav.eph[sat-1].iodc) return 0; /* unchanged */
    }
    eph.sat=sat;
    raw->nav.eph[sat-1]=eph;
    raw->ephsat=sat;
    return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movl %edx, %r15d
movl %esi, %ebx
movq %rdi, %r14
leaq -0x190(%rbp), %rdi
movl $0x120, %edx            # imm = 0x120
xorl %esi, %esi
callq 0x8390
movl 0x81a78(%r14), %ecx
leal 0x30(%r15), %eax
cmpl %eax, %ecx
jge 0x62690
leaq 0x16863(%rip), %rsi     # 0x78ee3
movl $0x2, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4ded0
jmp 0x626ea
movl %r15d, %eax
addq %r14, %rax
addq $0x81a96, %rax          # imm = 0x81A96
xorl %ecx, %ecx
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl (%rax,%rcx,4), %esi
andl %edx, %esi
movl %esi, -0x70(%rbp,%rcx,4)
incq %rcx
cmpq $0xa, %rcx
jne 0x626a3
leaq -0x34(%rbp), %rsi
movl %ebx, %edi
callq 0x4dc2a
movl -0x70(%rbp), %r13d
shrl $0xc, %r13d
andl $0x7, %r13d
leal -0x6(%r13), %eax
cmpl $-0x6, %eax
ja 0x62705
leaq 0x16917(%rip), %rsi     # 0x78ff3
movl $0x2, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4ded0
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x34(%rbp), %eax
addl $-0x6, %eax
cmpl $0x34, %eax
ja 0x627f3
movq %rbx, -0x40(%rbp)
leal -0x1(%rbx), %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
movq %rax, -0x30(%rbp)
addq %r14, %rax
imulq $0x26, %r13, %rcx
leaq (%rcx,%rax), %r15
addq $0x70f4a, %r15          # imm = 0x70F4A
leaq -0x70(%rbp), %rbx
xorl %r12d, %r12d
movl (%rbx), %ecx
movq %r15, %rdi
movl %r12d, %esi
movl $0x1e, %edx
callq 0x4e403
addq $0x1e, %r12
addq $0x4, %rbx
cmpq $0x12c, %r12            # imm = 0x12C
jne 0x62741
xorl %r15d, %r15d
cmpl $0x3, %r13d
jne 0x626f0
movq -0x30(%rbp), %rax
leaq (%r14,%rax), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
leaq -0x190(%rbp), %rsi
callq 0x34129
testl %eax, %eax
je 0x626f0
leaq 0x82a90(%r14), %rdi
leaq 0x9f29(%rip), %rsi      # 0x6c6c7
callq 0x8160
testq %rax, %rax
movq -0x40(%rbp), %r15
je 0x6289b
leaq -0x190(%rbp), %rsi
movl %r15d, (%rsi)
movq 0x1d80(%r14), %rax
movslq %r15d, %rcx
leaq (%rcx,%rcx,8), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x120, %rdi           # imm = 0xFEE0
movl $0x120, %edx            # imm = 0x120
callq 0x84f0
movl %r15d, 0x70e40(%r14)
movl $0x2, %r15d
jmp 0x626f0
cmpl $0x1, %r13d
jne 0x6290d
movl -0x6c(%rbp), %ecx
shrl $0xe, %ecx
andl $0xf, %ecx
leal -0xb(%rcx), %eax
cmpl $-0xa, %eax
jae 0x6281a
leaq 0x16805(%rip), %rsi     # 0x7901a
jmp 0x626dc
movq %rbx, -0x40(%rbp)
leal -0x1(%rbx), %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
movq %rax, -0x30(%rbp)
addq %r14, %rax
movq %rcx, %rbx
imulq $0x26, %rcx, %rcx
leaq (%rcx,%rax), %r15
addq $0x70f4a, %r15          # imm = 0x70F4A
leaq -0x70(%rbp), %r13
xorl %r12d, %r12d
movl (%r13), %ecx
movq %r15, %rdi
movl %r12d, %esi
movl $0x1e, %edx
callq 0x4e403
addq $0x1e, %r12
addq $0x4, %r13
cmpq $0x12c, %r12            # imm = 0x12C
jne 0x6284a
xorl %r15d, %r15d
cmpl $0xa, %ebx
jne 0x626f0
movq -0x30(%rbp), %rax
leaq (%r14,%rax), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
leaq -0x190(%rbp), %rsi
callq 0x3493f
jmp 0x62788
movq -0x170(%rbp), %rdi
movsd -0x168(%rbp), %xmm0
movq 0x1d80(%r14), %rax
leal -0x1(%r15), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,8), %rbx
shlq $0x5, %rbx
movq 0x20(%rax,%rbx), %rsi
movsd 0x28(%rax,%rbx), %xmm1
callq 0x4fe97
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x627b0
jp 0x627b0
movl -0x18c(%rbp), %ecx
movq 0x1d80(%r14), %rax
cmpl 0x4(%rax,%rbx), %ecx
jne 0x627b0
addq %rbx, %rax
movl -0x188(%rbp), %ecx
cmpl 0x8(%rax), %ecx
jne 0x627b0
xorl %r15d, %r15d
jmp 0x626f0