// File: /workspace/github_cpp_makefile_star2_O2/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, %r14d
movq %rdi, %r12
leaq -0x190(%rbp), %rdi
movl $0x120, %edx            # imm = 0x120
xorl %esi, %esi
callq 0x8390
movl 0x81a78(%r12), %ecx
leal 0x30(%r15), %eax
cmpl %eax, %ecx
jge 0x5843e
leaq 0x16a60(%rip), %rsi     # 0x6ee8f
pushq $0x2
popq %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x455bc
jmp 0x58496
movl %r15d, %eax
addq %r12, %rax
addq $0x81a96, %rax          # imm = 0x81A96
xorl %ecx, %ecx
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
cmpq $0xa, %rcx
je 0x58465
movl (%rax,%rcx,4), %esi
andl %edx, %esi
movl %esi, -0x70(%rbp,%rcx,4)
incq %rcx
jmp 0x58451
leaq -0x3c(%rbp), %rsi
movl %r14d, %edi
callq 0x45362
movl -0x70(%rbp), %ebx
shrl $0xc, %ebx
andl $0x7, %ebx
leal -0x6(%rbx), %eax
cmpl $-0x6, %eax
ja 0x584af
leaq 0x16b16(%rip), %rsi     # 0x6ef9f
pushq $0x2
popq %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x455bc
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x3c(%rbp), %eax
addl $-0x6, %eax
cmpl $0x34, %eax
ja 0x5851e
movq %r14, -0x38(%rbp)
leal -0x1(%r14), %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
leaq (%r12,%rax), %rcx
movq %r12, -0x48(%rbp)
addq %r12, %rax
addq $0x70f70, %rax          # imm = 0x70F70
movq %rax, -0x30(%rbp)
imulq $0x26, %rbx, %rax
leaq (%rax,%rcx), %r15
addq $0x70f4a, %r15          # imm = 0x70F4A
leaq -0x70(%rbp), %r14
xorl %r13d, %r13d
pushq $0x1e
popq %r12
cmpq $0x12c, %r13            # imm = 0x12C
je 0x58548
movl (%r14), %ecx
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x45a69
addq $0x1e, %r13
addq $0x4, %r14
jmp 0x584fa
cmpl $0x1, %ebx
jne 0x586cc
movl -0x6c(%rbp), %edx
shrl $0xe, %edx
andl $0xf, %edx
leal -0xb(%rdx), %eax
cmpl $-0xa, %eax
jae 0x585ce
leaq 0x16a83(%rip), %rsi     # 0x6efc6
jmp 0x58489
xorl %r15d, %r15d
cmpl $0x3, %ebx
jne 0x5849a
leaq -0x190(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2e0d2
testl %eax, %eax
movq -0x38(%rbp), %r14
je 0x5849a
movq -0x48(%rbp), %r15
leaq 0x82a90(%r15), %rdi
leaq 0xa145(%rip), %rsi      # 0x626c7
callq 0x8170
testq %rax, %rax
je 0x5865b
leaq -0x190(%rbp), %rsi
movl %r14d, (%rsi)
movq 0x1d80(%r15), %rax
movslq %r14d, %rcx
imulq $0x120, %rcx, %rcx      # imm = 0x120
leaq (%rax,%rcx), %rdi
addq $-0x120, %rdi           # imm = 0xFEE0
movl $0x120, %edx            # imm = 0x120
callq 0x84f0
movl %r14d, 0x70e40(%r15)
pushq $0x2
jmp 0x58498
leal -0x1(%r14), %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
leaq (%r12,%rax), %rcx
movq %r12, -0x48(%rbp)
addq %r12, %rax
addq $0x70f70, %rax          # imm = 0x70F70
movq %rax, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
imulq $0x26, %rdx, %rax
leaq (%rax,%rcx), %r15
addq $0x70f4a, %r15          # imm = 0x70F4A
leaq -0x70(%rbp), %rbx
xorl %r13d, %r13d
pushq $0x1e
popq %r12
cmpq $0x12c, %r13            # imm = 0x12C
je 0x58631
movl (%rbx), %ecx
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x45a69
addq $0x1e, %r13
addq $0x4, %rbx
jmp 0x5860e
xorl %r15d, %r15d
cmpl $0xa, -0x38(%rbp)
jne 0x5849a
leaq -0x190(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2e81c
testl %eax, %eax
jne 0x58570
jmp 0x5849a
movq -0x170(%rbp), %rdi
movsd -0x168(%rbp), %xmm0
movq 0x1d80(%r15), %rax
leal -0x1(%r14), %ecx
movslq %ecx, %rcx
imulq $0x120, %rcx, %rbx      # imm = 0x120
movq 0x20(%rax,%rbx), %rsi
movsd 0x28(%rax,%rbx), %xmm1
callq 0x47322
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x58590
jp 0x58590
movl -0x18c(%rbp), %ecx
movq 0x1d80(%r15), %rax
cmpl 0x4(%rax,%rbx), %ecx
jne 0x58590
addq %rbx, %rax
movl -0x188(%rbp), %ecx
cmpl 0x8(%rax), %ecx
jne 0x58590
xorl %r15d, %r15d
jmp 0x5849a