// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3.cpp
// Function: bamboo::decode_msm4(bamboo::rtcm_t*, int)
static int decode_msm4(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*48>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,15); i+=15;
        if (prv!=-16384) pr[j]=prv*P2_24*RANGE_MS;
    }
    for (j=0;j<ncell;j++) { /* phaserange */
        cpv=getbits(rtcm->buff,i,22); i+=22;
        if (cpv!=-2097152) cp[j]=cpv*P2_29*RANGE_MS;
    }
    for (j=0;j<ncell;j++) { /* lock time */
        lock[j]=getbitu(rtcm->buff,i,4); i+=4;
    }
    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,6)*1.0; i+=6;
    }
    /* 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 0x77a45
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x77fa8
movl -0x8d4(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
imull $0x12, %ecx, %ecx
addl %ecx, %eax
imull $0x30, -0x8e8(%rbp), %ecx
addl %ecx, %eax
movq -0x18(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
jle 0x77aaf
movl -0x8dc(%rbp), %edx
movzbl -0xbe(%rbp), %ecx
movl -0x8e8(%rbp), %r8d
movq -0x18(%rbp), %rax
movl 0x9f0c0(%rax), %r9d
movl $0x2, %edi
leaq 0x4a1cc(%rip), %rsi     # 0xc1c68
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x77fa8
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x77aee
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 0x77ab9
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x77b47
movslq -0x8d8(%rbp), %rax
movsd 0x48f1b(%rip), %xmm0    # 0xc0a30
movsd %xmm0, -0x6d0(%rbp,%rax,8)
movslq -0x8d8(%rbp), %rax
movsd 0x48f03(%rip), %xmm0    # 0xc0a30
movsd %xmm0, -0x4d0(%rbp,%rax,8)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x77af8
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x77bd8
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 0x77bc2
cvtsi2sdl -0x8ec(%rbp), %xmm0
movsd 0x48e32(%rip), %xmm1    # 0xc09e0
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x2d0(%rbp,%rax,8)
jmp 0x77bc4
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x77b51
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
movzbl -0xbe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x77c97
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 0x77c44
jp 0x77c44
jmp 0x77c81
cvtsi2sdl -0x8f0(%rbp), %xmm0
movsd 0x48dd4(%rip), %xmm1    # 0xc0a28
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd -0x2d0(%rbp,%rax,8), %xmm1
movsd 0x48d70(%rip), %xmm2    # 0xc09e0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x2d0(%rbp,%rax,8)
jmp 0x77c83
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x77be2
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x77d35
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0xf, %edx
callq 0x8c050
movl %eax, -0x8f4(%rbp)
movl -0x8d4(%rbp), %eax
addl $0xf, %eax
movl %eax, -0x8d4(%rbp)
cmpl $0xffffc000, -0x8f4(%rbp) # imm = 0xFFFFC000
je 0x77d1f
cvtsi2sdl -0x8f4(%rbp), %xmm0
movsd 0x471c9(%rip), %xmm1    # 0xbeec8
mulsd %xmm1, %xmm0
movsd 0x48cd5(%rip), %xmm1    # 0xc09e0
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x4d0(%rbp,%rax,8)
jmp 0x77d21
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x77ca1
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x77dd3
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0x16, %edx
callq 0x8c050
movl %eax, -0x8f8(%rbp)
movl -0x8d4(%rbp), %eax
addl $0x16, %eax
movl %eax, -0x8d4(%rbp)
cmpl $0xffe00000, -0x8f8(%rbp) # imm = 0xFFE00000
je 0x77dbd
cvtsi2sdl -0x8f8(%rbp), %xmm0
movsd 0x470d3(%rip), %xmm1    # 0xbee70
mulsd %xmm1, %xmm0
movsd 0x48c37(%rip), %xmm1    # 0xc09e0
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x6d0(%rbp,%rax,8)
jmp 0x77dbf
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x77d3f
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x77e36
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0x4, %edx
callq 0x8bfc0
movl %eax, %ecx
movslq -0x8d8(%rbp), %rax
movl %ecx, -0xa00(%rbp,%rax,4)
movl -0x8d4(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x8d4(%rbp)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x77ddd
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x77e99
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 0x77e40
movl $0x0, -0x8d8(%rbp)
movl -0x8d8(%rbp), %eax
cmpl -0x8e8(%rbp), %eax
jge 0x77f0f
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8d4(%rbp), %esi
movl $0x6, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x43f85(%rip), %xmm1    # 0xbbe60
mulsd %xmm1, %xmm0
movslq -0x8d8(%rbp), %rax
movsd %xmm0, -0x8d0(%rbp,%rax,8)
movl -0x8d4(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x8d4(%rbp)
movl -0x8d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d8(%rbp)
jmp 0x77ea3
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)