// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3.cpp
// Function: bamboo::decode_msm6(bamboo::rtcm_t*, int)
static int decode_msm6(rtcm_t *rtcm, int sys)
{
    msm_h_t h={0};
    double r[64],pr[64],cp[64],cnr[64];
    int i,j,type,sync,iod,ncell,rng,rng_m,prv,cpv,lock[64],half[64];
    
    type=getbitu(rtcm->buff,24,12);
    
    /* decode msm header */
    if ((ncell=decode_msm_head(rtcm,sys,&sync,&iod,&h,&i))<0) return -1;
    
    if (i+h.nsat*18+ncell*65>rtcm->len*8) {
        trace(2,"rtcm3 %d length error: nsat=%d ncell=%d len=%d\n",type,h.nsat,
              ncell,rtcm->len);
        return -1;
    }
    for (j=0;j<h.nsat;j++) r[j]=0.0;
    for (j=0;j<ncell;j++) pr[j]=cp[j]=-1E16;
    
    /* decode satellite data */
    for (j=0;j<h.nsat;j++) { /* range */
        rng  =getbitu(rtcm->buff,i, 8); i+= 8;
        if (rng!=255) r[j]=rng*RANGE_MS;
    }
    for (j=0;j<h.nsat;j++) {
        rng_m=getbitu(rtcm->buff,i,10); i+=10;
        if (r[j]!=0.0) r[j]+=rng_m*P2_10*RANGE_MS;
    }
    /* decode signal data */
    for (j=0;j<ncell;j++) { /* pseudorange */
        prv=getbits(rtcm->buff,i,20); i+=20;
        if (prv!=-524288) pr[j]=prv*P2_29*RANGE_MS;
    }
    for (j=0;j<ncell;j++) { /* phaserange */
        cpv=getbits(rtcm->buff,i,24); i+=24;
        if (cpv!=-8388608) cp[j]=cpv*P2_31*RANGE_MS;
    }
    for (j=0;j<ncell;j++) { /* lock time */
        lock[j]=getbitu(rtcm->buff,i,10); i+=10;
    }
    for (j=0;j<ncell;j++) { /* half-cycle ambiguity */
        half[j]=getbitu(rtcm->buff,i,1); i+=1;
    }
    for (j=0;j<ncell;j++) { /* cnr */
        cnr[j]=getbitu(rtcm->buff,i,10)*0.0625; i+=10;
    }
    /* save obs data in msm message */
    save_msm_obs(rtcm,sys,&h,r,pr,cp,NULL,NULL,cnr,lock,NULL,half);
    
    rtcm->obsflag=!sync;
    return sync?0:1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xb28, %rsp            # imm = 0xB28
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
leaq -0xc4(%rbp), %rdi
xorl %esi, %esi
movl $0xa8, %edx
callq 0x93d0
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl $0x18, %esi
movl $0xc, %edx
callq 0x8bfc0
movl %eax, -0x8dc(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x8e0(%rbp), %rdx
leaq -0x8e4(%rbp), %rcx
leaq -0xc4(%rbp), %r8
leaq -0x8d4(%rbp), %r9
callq 0x7b250
movl %eax, -0x8e8(%rbp)
cmpl $0x0, %eax
jge 0x78815
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x78d78
movl -0x8d4(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
imull $0x12, %ecx, %ecx
addl %ecx, %eax
imull $0x41, -0x8e8(%rbp), %ecx
addl %ecx, %eax
movq -0x18(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
jle 0x7887f
movl -0x8dc(%rbp), %edx
movzbl -0xbe(%rbp), %ecx
movl -0x8e8(%rbp), %r8d
movq -0x18(%rbp), %rax
movl 0x9f0c0(%rax), %r9d
movl $0x2, %edi
leaq 0x493fc(%rip), %rsi     # 0xc1c68
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x78d78
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x788be
movslq -0x8d8(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, -0x2d0(%rbp,%rax,8)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x78889
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x78917
movslq -0x8d8(%rbp), %rax
movsd 0x4814b(%rip), %xmm0    # 0xc0a30
movsd %xmm0, -0x6d0(%rbp,%rax,8)
movslq -0x8d8(%rbp), %rax
movsd 0x48133(%rip), %xmm0    # 0xc0a30
movsd %xmm0, -0x4d0(%rbp,%rax,8)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x788c8
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x789a8
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0x8, %edx
callq 0x8bfc0
movl %eax, -0x8ec(%rbp)
movl -0x8d4(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x8d4(%rbp)
cmpl $0xff, -0x8ec(%rbp)
je 0x78992
cvtsi2sdl -0x8ec(%rbp), %xmm0
movsd 0x48062(%rip), %xmm1    # 0xc09e0
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x2d0(%rbp,%rax,8)
jmp 0x78994
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x78921
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x78a67
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0xa, %edx
callq 0x8bfc0
movl %eax, -0x8f0(%rbp)
movl -0x8d4(%rbp), %eax
addl $0xa, %eax
movl %eax, -0x8d4(%rbp)
movslq -0x8d8(%rbp), %rax
movsd -0x2d0(%rbp,%rax,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x78a14
jp 0x78a14
jmp 0x78a51
cvtsi2sdl -0x8f0(%rbp), %xmm0
movsd 0x48004(%rip), %xmm1    # 0xc0a28
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd -0x2d0(%rbp,%rax,8), %xmm1
movsd 0x47fa0(%rip), %xmm2    # 0xc09e0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x2d0(%rbp,%rax,8)
jmp 0x78a53
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x789b2
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x78b05
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0x14, %edx
callq 0x8c050
movl %eax, -0x8f4(%rbp)
movl -0x8d4(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x8d4(%rbp)
cmpl $0xfff80000, -0x8f4(%rbp) # imm = 0xFFF80000
je 0x78aef
cvtsi2sdl -0x8f4(%rbp), %xmm0
movsd 0x463a1(%rip), %xmm1    # 0xbee70
mulsd %xmm1, %xmm0
movsd 0x47f05(%rip), %xmm1    # 0xc09e0
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x4d0(%rbp,%rax,8)
jmp 0x78af1
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x78a71
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x78ba3
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0x18, %edx
callq 0x8c050
movl %eax, -0x8f8(%rbp)
movl -0x8d4(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x8d4(%rbp)
cmpl $0xff800000, -0x8f8(%rbp) # imm = 0xFF800000
je 0x78b8d
cvtsi2sdl -0x8f8(%rbp), %xmm0
movsd 0x4446b(%rip), %xmm1    # 0xbcfd8
mulsd %xmm1, %xmm0
movsd 0x47e67(%rip), %xmm1    # 0xc09e0
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x6d0(%rbp,%rax,8)
jmp 0x78b8f
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x78b0f
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x78c06
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0xa, %edx
callq 0x8bfc0
movl %eax, %ecx
movslq -0x8d8(%rbp), %rax
movl %ecx, -0xa00(%rbp,%rax,4)
movl -0x8d4(%rbp), %eax
addl $0xa, %eax
movl %eax, -0x8d4(%rbp)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x78bad
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x78c69
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, %ecx
movslq -0x8d8(%rbp), %rax
movl %ecx, -0xb00(%rbp,%rax,4)
movl -0x8d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d4(%rbp)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x78c10
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x78cdf
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0xa, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x47d8d(%rip), %xmm1    # 0xc0a38
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x8d0(%rbp,%rax,8)
movl -0x8d4(%rbp), %eax
addl $0xa, %eax
movl %eax, -0x8d4(%rbp)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x78c73
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x2d0(%rbp), %rcx
leaq -0x4d0(%rbp), %r8
leaq -0x6d0(%rbp), %r9
leaq -0x8d0(%rbp), %r11
leaq -0xa00(%rbp), %r10
leaq -0xb00(%rbp), %rax
leaq -0xc4(%rbp), %rdx
xorl %ebx, %ebx
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x7b9f0
cmpl $0x0, -0x8e0(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x9bdd0(%rax)
movl -0x8e0(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0xb28, %rsp            # imm = 0xB28
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)