// File: 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
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
leaq -0x138(%rbp), %rdi
xorl %esi, %esi
movl $0x120, %edx            # imm = 0x120
callq 0x93d0
movq -0x10(%rbp), %rax
addq $0x81a90, %rax          # imm = 0x81A90
addq $0x6, %rax
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %eax
movl -0x18(%rbp), %ecx
addl $0x30, %ecx
cmpl %ecx, %eax
jge 0xadcd4
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %ecx
movl $0x2, %edi
leaq 0x1df72(%rip), %rsi     # 0xcbc33
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xae0cc
movl $0x0, -0x164(%rbp)
cmpl $0xa, -0x164(%rbp)
jge 0xadd2c
movq -0x178(%rbp), %rdi
callq 0xac7b0
movl %eax, %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movslq -0x164(%rbp), %rax
movl %ecx, -0x160(%rbp,%rax,4)
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
movq -0x178(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x178(%rbp)
jmp 0xadcde
movl -0x14(%rbp), %edi
leaq -0x170(%rbp), %rsi
callq 0x8b3b0
movl -0x160(%rbp), %eax
shrl $0xc, %eax
andl $0x7, %eax
movl %eax, -0x168(%rbp)
cmpl $0x1, -0x168(%rbp)
jl 0xadd63
movl $0x5, %eax
cmpl -0x168(%rbp), %eax
jge 0xadd85
movl -0x14(%rbp), %edx
movl $0x2, %edi
leaq 0x1dfd1(%rip), %rsi     # 0xcbd43
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xae0cc
cmpl $0x5, -0x170(%rbp)
jle 0xade64
cmpl $0x3b, -0x170(%rbp)
jge 0xade64
movl $0x0, -0x164(%rbp)
cmpl $0xa, -0x164(%rbp)
jge 0xade10
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
movl -0x168(%rbp), %eax
subl $0x1, %eax
imull $0x26, %eax, %eax
cltq
addq %rax, %rdi
imull $0x1e, -0x164(%rbp), %esi
movslq -0x164(%rbp), %rax
movl -0x160(%rbp,%rax,4), %ecx
movl $0x1e, %edx
callq 0x8c0d0
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0xadda9
cmpl $0x3, -0x168(%rbp)
je 0xade25
movl $0x0, -0x4(%rbp)
jmp 0xae0cc
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
leaq -0x138(%rbp), %rsi
callq 0x63080
cmpl $0x0, %eax
jne 0xade5f
movl $0x0, -0x4(%rbp)
jmp 0xae0cc
jmp 0xadf85
cmpl $0x1, -0x168(%rbp)
je 0xade79
movl $0x0, -0x4(%rbp)
jmp 0xae0cc
movl -0x15c(%rbp), %eax
shrl $0xe, %eax
andl $0xf, %eax
movl %eax, -0x16c(%rbp)
cmpl $0x1, -0x16c(%rbp)
jl 0xadea1
movl $0xa, %eax
cmpl -0x16c(%rbp), %eax
jge 0xadec3
movl -0x14(%rbp), %edx
movl $0x2, %edi
leaq 0x1deba(%rip), %rsi     # 0xcbd6a
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xae0cc
movl $0x0, -0x164(%rbp)
cmpl $0xa, -0x164(%rbp)
jge 0xadf34
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
movl -0x16c(%rbp), %eax
subl $0x1, %eax
imull $0x26, %eax, %eax
cltq
addq %rax, %rdi
imull $0x1e, -0x164(%rbp), %esi
movslq -0x164(%rbp), %rax
movl -0x160(%rbp,%rax,4), %ecx
movl $0x1e, %edx
callq 0x8c0d0
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0xadecd
cmpl $0xa, -0x16c(%rbp)
je 0xadf49
movl $0x0, -0x4(%rbp)
jmp 0xae0cc
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
leaq -0x138(%rbp), %rsi
callq 0x63be0
cmpl $0x0, %eax
jne 0xadf83
movl $0x0, -0x4(%rbp)
jmp 0xae0cc
jmp 0xadf85
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x108c8(%rip), %rsi     # 0xbe85f
callq 0x91b0
cmpq $0x0, %rax
jne 0xae081
movq -0x118(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x10(%rbp), %rax
movq 0x1d80(%rax), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x120, %rcx, %rcx      # imm = 0x120
addq %rcx, %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x198(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x190(%rbp)
movq -0x188(%rbp), %rdi
movsd -0x180(%rbp), %xmm0
movq -0x198(%rbp), %rsi
movsd -0x190(%rbp), %xmm1
callq 0x8e8e0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xae07f
jp 0xae07f
movl -0x134(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x1d80(%rcx), %rcx
movl -0x14(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x120, %rdx, %rdx      # imm = 0x120
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xae07f
movl -0x130(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x1d80(%rcx), %rcx
movl -0x14(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x120, %rdx, %rdx      # imm = 0x120
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0xae07f
movl $0x0, -0x4(%rbp)
jmp 0xae0cc
jmp 0xae081
movl -0x14(%rbp), %eax
movl %eax, -0x138(%rbp)
movq -0x10(%rbp), %rax
movq 0x1d80(%rax), %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x120, %rax, %rax      # imm = 0x120
addq %rax, %rdi
leaq -0x138(%rbp), %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x9610
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x70e40(%rax)
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopl (%rax,%rax)