// File: 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
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
movl $0x98, %edx
callq 0x93d0
movq -0x10(%rbp), %rax
addq $0x81a90, %rax          # imm = 0x81A90
addq $0x6, %rax
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movl -0x14(%rbp), %edi
leaq -0xcc(%rbp), %rsi
callq 0x8b3b0
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %eax
movl -0x18(%rbp), %ecx
addl $0x18, %ecx
cmpl %ecx, %eax
jge 0xae173
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %edx
movl $0x2, %edi
leaq 0x1dc33(%rip), %rsi     # 0xcbd93
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xae4af
movl $0x0, -0xc4(%rbp)
movl $0x0, -0xbc(%rbp)
cmpl $0x4, -0xbc(%rbp)
jge 0xae20e
movl $0x0, -0xc0(%rbp)
cmpl $0x4, -0xc0(%rbp)
jge 0xae1e6
movq -0xd8(%rbp), %rax
movl $0x3, %ecx
subl -0xc0(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movl -0xc4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0xc4(%rbp)
cltq
movb %cl, -0x120(%rbp,%rax)
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0xae19a
jmp 0xae1e8
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
movq -0xd8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xd8(%rbp)
jmp 0xae187
leaq -0x120(%rbp), %rdi
callq 0x64b40
cmpl $0x0, %eax
jne 0xae241
movl -0x14(%rbp), %edx
movl $0x2, %edi
leaq 0x1db8d(%rip), %rsi     # 0xcbdbb
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xae4af
leaq -0x120(%rbp), %rdi
movl $0x1, %esi
movl $0x4, %edx
callq 0x8bfc0
movl %eax, -0xc8(%rbp)
cmpl $0x1, -0xc8(%rbp)
jl 0xae273
movl $0xf, %eax
cmpl -0xc8(%rbp), %eax
jge 0xae295
movl -0x14(%rbp), %edx
movl $0x2, %edi
leaq 0x1db69(%rip), %rsi     # 0xcbdeb
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xae4af
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
addq $0x96, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movzbl (%rax), %eax
movzbl -0x114(%rbp), %ecx
cmpl %ecx, %eax
jne 0xae2ea
movq -0x128(%rbp), %rax
movzbl 0x1(%rax), %eax
movzbl -0x113(%rbp), %ecx
cmpl %ecx, %eax
je 0xae354
movl $0x0, -0xbc(%rbp)
cmpl $0x4, -0xbc(%rbp)
jge 0xae343
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
imull $0xa, -0xbc(%rbp), %eax
cltq
addq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x93d0
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0xae2f4
movq -0x128(%rbp), %rax
movw -0x114(%rbp), %cx
movw %cx, (%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
movl -0xc8(%rbp), %ecx
subl $0x1, %ecx
imull $0xa, %ecx, %ecx
movslq %ecx, %rcx
movq -0x120(%rbp), %rdx
movq %rdx, (%rax,%rcx)
movw -0x118(%rbp), %dx
movw %dx, 0x8(%rax,%rcx)
cmpl $0x4, -0xc8(%rbp)
je 0xae3ac
movl $0x0, -0x4(%rbp)
jmp 0xae4af
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x90(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
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 -0xb8(%rbp), %rsi
callq 0x64c10
cmpl $0x0, %eax
je 0xae3fe
movl -0xb8(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0xae40a
movl $0x0, -0x4(%rbp)
jmp 0xae4af
movl -0x1c(%rbp), %eax
subl $0x7, %eax
movl %eax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x10437(%rip), %rsi     # 0xbe85f
callq 0x91b0
cmpq $0x0, %rax
jne 0xae46a
movl -0xb4(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x1d88(%rcx), %rcx
movl -0xcc(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x98, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0xae468
movl $0x0, -0x4(%rbp)
jmp 0xae4af
jmp 0xae46a
movq -0x10(%rbp), %rax
movq 0x1d88(%rax), %rdi
movl -0xcc(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x98, %rax, %rax
addq %rax, %rdi
leaq -0xb8(%rbp), %rsi
movl $0x98, %edx
callq 0x9610
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x70e40(%rax)
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax,%rax)