// File: /workspace/github_cpp_makefile_star2_O3/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 0x61a78
leaq 0x17453(%rip), %rsi     # 0x78ebb
movl $0x2, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4d55d
jmp 0x61ad3
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 0x61a8b
leaq -0x34(%rbp), %rsi
movl %ebx, %edi
callq 0x4d2f2
movl -0x70(%rbp), %r12d
shrl $0xc, %r12d
andl $0x7, %r12d
leal -0x6(%r12), %eax
cmpl $-0x6, %eax
ja 0x61aee
leaq 0x17506(%rip), %rsi     # 0x78fcb
movl $0x2, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4d55d
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 0x61bdf
movq %rbx, -0x40(%rbp)
leal -0x1(%rbx), %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
leaq (%r14,%rax), %rcx
addq %r14, %rax
addq $0x70f70, %rax          # imm = 0x70F70
movq %rax, -0x30(%rbp)
imulq $0x26, %r12, %rax
leaq (%rax,%rcx), %r15
addq $0x70f4a, %r15          # imm = 0x70F4A
leaq -0x70(%rbp), %rbx
xorl %r13d, %r13d
movl (%rbx), %ecx
movq %r15, %rdi
movl %r13d, %esi
movl $0x1e, %edx
callq 0x4da98
addq $0x1e, %r13
addq $0x4, %rbx
cmpq $0x12c, %r13            # imm = 0x12C
jne 0x61b34
xorl %r15d, %r15d
cmpl $0x3, %r12d
jne 0x61ad9
leaq -0x190(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x33af1
testl %eax, %eax
je 0x61ad9
leaq 0x82a90(%r14), %rdi
leaq 0xab3d(%rip), %rsi      # 0x6c6c7
callq 0x8160
testq %rax, %rax
movq -0x40(%rbp), %r15
je 0x61c86
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 0x61ad9
cmpl $0x1, %r12d
jne 0x61cf8
movl -0x6c(%rbp), %edx
shrl $0xe, %edx
andl $0xf, %edx
leal -0xb(%rdx), %eax
cmpl $-0xa, %eax
jae 0x61c06
leaq 0x173f1(%rip), %rsi     # 0x78ff2
jmp 0x61ac5
movq %rbx, -0x40(%rbp)
leal -0x1(%rbx), %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
leaq (%r14,%rax), %rcx
addq %r14, %rax
addq $0x70f70, %rax          # imm = 0x70F70
movq %rax, -0x30(%rbp)
movq %rdx, %rbx
imulq $0x26, %rdx, %rax
leaq (%rax,%rcx), %r15
addq $0x70f4a, %r15          # imm = 0x70F4A
leaq -0x70(%rbp), %r12
xorl %r13d, %r13d
movl (%r12), %ecx
movq %r15, %rdi
movl %r13d, %esi
movl $0x1e, %edx
callq 0x4da98
addq $0x1e, %r13
addq $0x4, %r12
cmpq $0x12c, %r13            # imm = 0x12C
jne 0x61c40
xorl %r15d, %r15d
cmpl $0xa, %ebx
jne 0x61ad9
leaq -0x190(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x34306
jmp 0x61b74
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 0x4f51b
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x61b9c
jp 0x61b9c
movl -0x18c(%rbp), %ecx
movq 0x1d80(%r14), %rax
cmpl 0x4(%rax,%rbx), %ecx
jne 0x61b9c
addq %rbx, %rax
movl -0x188(%rbp), %ecx
cmpl 0x8(%rax), %ecx
jne 0x61b9c
xorl %r15d, %r15d
jmp 0x61ad9