// File: DoubleString[P]RtConverter/src/Rtklib/ublox.cpp
// Function: bamboo::decode_enav(bamboo::raw_t*, int, int)
static int decode_enav(raw_t *raw, int sat, int off)
{
    eph_t eph={0};
    unsigned char *p=raw->buff+6+off,buff[32],crc_buff[26]={0};
    int i,j,k,part1,page1,part2,page2,type;
    
    if (raw->len<44+off) {
        trace(2,"ubx rawsfrbx length error: sat=%d len=%d\n",sat,raw->len);
        return -1;
    }
    for (i=k=0;i<8;i++,p+=4) for (j=0;j<4;j++) {
        buff[k++]=p[3-j];
    }
    part1=getbitu(buff   ,0,1);
    page1=getbitu(buff   ,1,1);
    part2=getbitu(buff+16,0,1);
    page2=getbitu(buff+16,1,1);
    
    /* skip alert page */
    if (page1==1||page2==1) return 0;
    
    /* test even-odd parts */
    if (part1!=0||part2!=1) {
        trace(2,"ubx rawsfrbx gal page even/odd error: sat=%2d\n",sat);
        return -1;
    }
    /* test crc (4(pad) + 114 + 82 bits) */
    for (i=0,j=  4;i<15;i++,j+=8) setbitu(crc_buff,j,8,getbitu(buff   ,i*8,8));
    for (i=0,j=118;i<11;i++,j+=8) setbitu(crc_buff,j,8,getbitu(buff+16,i*8,8));
    if (rtk_crc24q(crc_buff,25)!=getbitu(buff+16,82,24)) {
        trace(2,"ubx rawsfrbx gal page crc error: sat=%2d\n",sat);
        return -1;
    }
    type=getbitu(buff,2,6); /* word type */
    
    /* skip word except for ephemeris, iono, utc parameters */
    if (type>6) return 0;
    
    /* clear word 0-6 flags */
    if (type==2) raw->subfrm[sat-1][112]=0;
    
    /* save page data (112 + 16 bits) to frame buffer */
    k=type*16;
    for (i=0,j=2;i<14;i++,j+=8) raw->subfrm[sat-1][k++]=getbitu(buff   ,j,8);
    for (i=0,j=2;i< 2;i++,j+=8) raw->subfrm[sat-1][k++]=getbitu(buff+16,j,8);
    
    /* test word 0-6 flags */
    raw->subfrm[sat-1][112]|=(1<<type);
    if (raw->subfrm[sat-1][112]!=0x7F) return 0;
    
    if (strstr(raw->opt,"-GALFNAV")) {
        return 0;
    }
    /* decode galileo inav ephemeris */
    if (!decode_gal_inav(raw->subfrm[sat-1],&eph)) {
        return 0;
    }
    /* test svid consistency */
    if (eph.sat!=sat) {
        trace(2,"ubx rawsfrbx gal svid error: sat=%2d %2d\n",sat,eph.sat);
        return -1;
    }
    if (!strstr(raw->opt,"-EPHALL")) {
        if (eph.iode==raw->nav.eph[sat-1].iode&& /* unchanged */
            timediff(eph.toe,raw->nav.eph[sat-1].toe)==0.0&&
            timediff(eph.toc,raw->nav.eph[sat-1].toc)==0.0) return 0;
    }
    eph.sat=sat;
    raw->nav.eph[sat-1]=eph;
    raw->ephsat=sat;
    return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
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, -0x140(%rbp)
leaq -0x180(%rbp), %rdi
xorl %esi, %esi
movl $0x1a, %edx
callq 0x93d0
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %eax
movl -0x18(%rbp), %ecx
addl $0x2c, %ecx
cmpl %ecx, %eax
jge 0xad547
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %ecx
movl $0x2, %edi
leaq 0x1e6ff(%rip), %rsi     # 0xcbc33
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xadc3c
movl $0x0, -0x18c(%rbp)
movl $0x0, -0x184(%rbp)
cmpl $0x8, -0x184(%rbp)
jge 0xad5e2
movl $0x0, -0x188(%rbp)
cmpl $0x4, -0x188(%rbp)
jge 0xad5ba
movq -0x140(%rbp), %rax
movl $0x3, %ecx
subl -0x188(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movl -0x18c(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18c(%rbp)
cltq
movb %cl, -0x160(%rbp,%rax)
movl -0x188(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x188(%rbp)
jmp 0xad56e
jmp 0xad5bc
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
movq -0x140(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x140(%rbp)
jmp 0xad55b
leaq -0x160(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x190(%rbp)
leaq -0x160(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x8bfc0
movl %eax, -0x194(%rbp)
leaq -0x160(%rbp), %rdi
addq $0x10, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x198(%rbp)
leaq -0x160(%rbp), %rdi
addq $0x10, %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x8bfc0
movl %eax, -0x19c(%rbp)
cmpl $0x1, -0x194(%rbp)
je 0xad660
cmpl $0x1, -0x19c(%rbp)
jne 0xad66c
movl $0x0, -0x4(%rbp)
jmp 0xadc3c
cmpl $0x0, -0x190(%rbp)
jne 0xad67e
cmpl $0x1, -0x198(%rbp)
je 0xad6a0
movl -0x14(%rbp), %edx
movl $0x2, %edi
leaq 0x1e633(%rip), %rsi     # 0xcbcc0
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xadc3c
movl $0x0, -0x184(%rbp)
movl $0x4, -0x188(%rbp)
cmpl $0xf, -0x184(%rbp)
jge 0xad72a
leaq -0x180(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movl -0x188(%rbp), %eax
movl %eax, -0x1e4(%rbp)
leaq -0x160(%rbp), %rdi
movl -0x184(%rbp), %esi
shll $0x3, %esi
movl $0x8, %edx
callq 0x8bfc0
movq -0x1f0(%rbp), %rdi
movl -0x1e4(%rbp), %esi
movl %eax, %ecx
movl $0x8, %edx
callq 0x8c0d0
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
movl -0x188(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x188(%rbp)
jmp 0xad6b4
movl $0x0, -0x184(%rbp)
movl $0x76, -0x188(%rbp)
cmpl $0xb, -0x184(%rbp)
jge 0xad7b8
leaq -0x180(%rbp), %rax
movq %rax, -0x200(%rbp)
movl -0x188(%rbp), %eax
movl %eax, -0x1f4(%rbp)
leaq -0x160(%rbp), %rdi
addq $0x10, %rdi
movl -0x184(%rbp), %esi
shll $0x3, %esi
movl $0x8, %edx
callq 0x8bfc0
movq -0x200(%rbp), %rdi
movl -0x1f4(%rbp), %esi
movl %eax, %ecx
movl $0x8, %edx
callq 0x8c0d0
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
movl -0x188(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x188(%rbp)
jmp 0xad73e
leaq -0x180(%rbp), %rdi
movl $0x19, %esi
callq 0x8c2d0
movl %eax, -0x204(%rbp)
leaq -0x160(%rbp), %rdi
addq $0x10, %rdi
movl $0x52, %esi
movl $0x18, %edx
callq 0x8bfc0
movl %eax, %ecx
movl -0x204(%rbp), %eax
cmpl %ecx, %eax
je 0xad817
movl -0x14(%rbp), %edx
movl $0x2, %edi
leaq 0x1e4eb(%rip), %rsi     # 0xcbcef
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xadc3c
leaq -0x160(%rbp), %rdi
movl $0x2, %esi
movl $0x6, %edx
callq 0x8bfc0
movl %eax, -0x1a0(%rbp)
cmpl $0x6, -0x1a0(%rbp)
jle 0xad848
movl $0x0, -0x4(%rbp)
jmp 0xadc3c
cmpl $0x2, -0x1a0(%rbp)
jne 0xad872
movq -0x10(%rbp), %rax
addq $0x70f70, %rax          # imm = 0x70F70
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
addq %rcx, %rax
movb $0x0, 0x70(%rax)
movl -0x1a0(%rbp), %eax
shll $0x4, %eax
movl %eax, -0x18c(%rbp)
movl $0x0, -0x184(%rbp)
movl $0x2, -0x188(%rbp)
cmpl $0xe, -0x184(%rbp)
jge 0xad90b
leaq -0x160(%rbp), %rdi
movl -0x188(%rbp), %esi
movl $0x8, %edx
callq 0x8bfc0
movb %al, %dl
movq -0x10(%rbp), %rax
addq $0x70f70, %rax          # imm = 0x70F70
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
addq %rcx, %rax
movl -0x18c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
movl -0x188(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x188(%rbp)
jmp 0xad895
movl $0x0, -0x184(%rbp)
movl $0x2, -0x188(%rbp)
cmpl $0x2, -0x184(%rbp)
jge 0xad999
leaq -0x160(%rbp), %rdi
addq $0x10, %rdi
movl -0x188(%rbp), %esi
movl $0x8, %edx
callq 0x8bfc0
movb %al, %dl
movq -0x10(%rbp), %rax
addq $0x70f70, %rax          # imm = 0x70F70
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
addq %rcx, %rax
movl -0x18c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
movl -0x188(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x188(%rbp)
jmp 0xad91f
movl -0x1a0(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movq -0x10(%rbp), %rax
addq $0x70f70, %rax          # imm = 0x70F70
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
addq %rcx, %rax
movzbl 0x70(%rax), %ecx
orl %edx, %ecx
movb %cl, 0x70(%rax)
movq -0x10(%rbp), %rax
addq $0x70f70, %rax          # imm = 0x70F70
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
addq %rcx, %rax
movzbl 0x70(%rax), %eax
cmpl $0x7f, %eax
je 0xad9fe
movl $0x0, -0x4(%rbp)
jmp 0xadc3c
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x10f3b(%rip), %rsi     # 0xbe94b
callq 0x91b0
cmpq $0x0, %rax
je 0xada27
movl $0x0, -0x4(%rbp)
jmp 0xadc3c
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 0x62640
cmpl $0x0, %eax
jne 0xada61
movl $0x0, -0x4(%rbp)
jmp 0xadc3c
movl -0x138(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0xada94
movl -0x14(%rbp), %edx
movl -0x138(%rbp), %ecx
movl $0x2, %edi
leaq 0x1e298(%rip), %rsi     # 0xcbd19
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xadc3c
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x10db9(%rip), %rsi     # 0xbe85f
callq 0x91b0
cmpq $0x0, %rax
jne 0xadbf1
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 0xadbef
movq -0x118(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x1a8(%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, -0x1c0(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x1b8(%rbp)
movq -0x1b0(%rbp), %rdi
movsd -0x1a8(%rbp), %xmm0
movq -0x1c0(%rbp), %rsi
movsd -0x1b8(%rbp), %xmm1
callq 0x8e8e0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xadbef
jp 0xadbef
movq -0x108(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x1c8(%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 0x30(%rax), %rcx
movq %rcx, -0x1e0(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d0(%rbp), %rdi
movsd -0x1c8(%rbp), %xmm0
movq -0x1e0(%rbp), %rsi
movsd -0x1d8(%rbp), %xmm1
callq 0x8e8e0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xadbef
jp 0xadbef
movl $0x0, -0x4(%rbp)
jmp 0xadc3c
jmp 0xadbf1
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 $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopl (%rax,%rax)