// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rtklib/ublox.cpp
// Function: bamboo::decode_gnav(bamboo::raw_t*, int, int, int)
static int decode_gnav(raw_t *raw, int sat, int off, int frq)
{
    geph_t geph={0};
    int i,j,k,m,prn;
    unsigned char *p=raw->buff+6+off,buff[64],*fid;
    
    satsys(sat,&prn);
    
    if (raw->len<24+off) {
        trace(2,"ubx rawsfrbx gnav length error: len=%d\n",raw->len);
        return -1;
    }
    for (i=k=0;i<4;i++,p+=4) for (j=0;j<4;j++) {
        buff[k++]=p[3-j];
    }
    /* test hamming of glonass string */
    if (!test_glostr(buff)) {
        trace(2,"ubx rawsfrbx glo string hamming error: sat=%2d\n",sat);
        return -1;
    }
    m=getbitu(buff,1,4);
    if (m<1||15<m) {
        trace(2,"ubx rawsfrbx glo string no error: sat=%2d\n",sat);
        return -1;
    }
    /* flush frame buffer if frame-id changed */
    fid=raw->subfrm[sat-1]+150;
    if (fid[0]!=buff[12]||fid[1]!=buff[13]) {
        for (i=0;i<4;i++) memset(raw->subfrm[sat-1]+i*10,0,10);
        memcpy(fid,buff+12,2); /* save frame-id */
    }
    memcpy(raw->subfrm[sat-1]+(m-1)*10,buff,10);
    
    if (m!=4) return 0;
    
    /* decode glonass ephemeris strings */
    geph.tof=raw->time;
    if (!decode_glostr(raw->subfrm[sat-1],&geph)||geph.sat!=sat) return 0;
    geph.frq=frq-7;
    
    if (!strstr(raw->opt,"-EPHALL")) {
        if (geph.iode==raw->nav.geph[prn-1].iode) return 0; /* unchanged */
    }
    raw->nav.geph[prn-1]=geph;
    raw->ephsat=sat;
    return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %ecx, %r15d
movl %edx, %r12d
movl %esi, %ebx
movq %rdi, %r14
leaq -0x108(%rbp), %rdi
xorl %r13d, %r13d
movl $0x98, %edx
xorl %esi, %esi
callq 0x8390
leaq -0x2c(%rbp), %rsi
movl %ebx, %edi
callq 0x4d2f2
movl 0x81a78(%r14), %edx
leal 0x18(%r12), %eax
cmpl %eax, %edx
jge 0x61d5e
leaq 0x172c4(%rip), %rsi     # 0x7901b
movl $0x2, %edi
jmp 0x61dd2
movl %r12d, %eax
addq %r14, %rax
addq $0x81a99, %rax          # imm = 0x81A99
xorl %ecx, %ecx
movslq %ecx, %rcx
xorl %edx, %edx
movb (%rax,%rdx), %sil
movb %sil, -0x70(%rbp,%rcx)
incq %rcx
decq %rdx
cmpq $-0x4, %rdx
jne 0x61d71
incl %r13d
addq $0x4, %rax
cmpl $0x4, %r13d
jne 0x61d6c
leaq -0x70(%rbp), %rdi
callq 0x34f9f
testl %eax, %eax
je 0x61dc4
leaq -0x70(%rbp), %rdi
movl $0x1, %esi
movl $0x4, %edx
callq 0x4d9d6
leal -0x10(%rax), %ecx
cmpl $-0x10, %ecx
ja 0x61df4
leaq 0x172b1(%rip), %rsi     # 0x79073
jmp 0x61dcb
leaq 0x17278(%rip), %rsi     # 0x79043
movl $0x2, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4d55d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal -0x1(%rbx), %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
leaq (%r14,%rcx), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movb 0x96(%rdi), %cl
cmpb -0x64(%rbp), %cl
jne 0x61e22
movb 0x97(%rdi), %cl
cmpb -0x63(%rbp), %cl
je 0x61e3f
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movq $0x0, 0x20(%rdi)
movzwl -0x64(%rbp), %ecx
movw %cx, 0x96(%rdi)
leal (%rax,%rax), %ecx
leal (%rcx,%rcx,4), %ecx
movzwl -0x68(%rbp), %edx
movw %dx, -0x2(%rdi,%rcx)
movq -0x70(%rbp), %rdx
movq %rdx, -0xa(%rdi,%rcx)
xorl %r12d, %r12d
cmpl $0x4, %eax
jne 0x61ddf
movups (%r14), %xmm0
leaq -0x108(%rbp), %rsi
movups %xmm0, 0x28(%rsi)
callq 0x35012
testl %eax, %eax
je 0x61ddf
cmpl %ebx, -0x108(%rbp)
jne 0x61ddf
addl $-0x7, %r15d
movl %r15d, -0x100(%rbp)
leaq 0x82a90(%r14), %rdi
leaq 0xa827(%rip), %rsi      # 0x6c6c7
callq 0x8160
testq %rax, %rax
je 0x61eb7
movq 0x1d88(%r14), %rax
movslq -0x2c(%rbp), %rcx
jmp 0x61edc
movl -0x104(%rbp), %edx
movq 0x1d88(%r14), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x98, %rcx, %rsi
cmpl -0x94(%rax,%rsi), %edx
je 0x61ddf
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $-0x98, %rdi
leaq -0x108(%rbp), %rsi
movl $0x98, %edx
callq 0x84f0
movl %ebx, 0x70e40(%r14)
movl $0x2, %r12d
jmp 0x61ddf