// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3.cpp
// Function: bamboo::decode_msm_head(bamboo::rtcm_t*, int, int*, int*, bamboo::msm_h_t*, int*)
static int decode_msm_head(rtcm_t *rtcm, int sys, int *sync, int *iod,
                           msm_h_t *h, int *hsize)
{
    msm_h_t h0={0};
    double tow,tod;
    char *msg,tstr[64];
    int i=24,j,dow,mask,staid,type,ncell=0;
    
    type=getbitu(rtcm->buff,i,12); i+=12;
    
    *h=h0;
    if (i+157<=rtcm->len*8) {
        staid     =getbitu(rtcm->buff,i,12);       i+=12;
        
        if (sys==SYS_GLO) {
            dow   =getbitu(rtcm->buff,i, 3);       i+= 3;
            tod   =getbitu(rtcm->buff,i,27)*0.001; i+=27;
            adjday_glot(rtcm,tod);
        }
        else if (sys==SYS_CMP) {
            tow   =getbitu(rtcm->buff,i,30)*0.001; i+=30;
            tow+=14.0; /* BDT -> GPST */
            adjweek(rtcm,tow);
        }
        else {
            tow   =getbitu(rtcm->buff,i,30)*0.001; i+=30;
            adjweek(rtcm,tow);
        }
        *sync     =getbitu(rtcm->buff,i, 1);       i+= 1;
        *iod      =getbitu(rtcm->buff,i, 3);       i+= 3;
        h->time_s =getbitu(rtcm->buff,i, 7);       i+= 7;
        h->clk_str=getbitu(rtcm->buff,i, 2);       i+= 2;
        h->clk_ext=getbitu(rtcm->buff,i, 2);       i+= 2;
        h->smooth =getbitu(rtcm->buff,i, 1);       i+= 1;
        h->tint_s =getbitu(rtcm->buff,i, 3);       i+= 3;
        for (j=1;j<=64;j++) {
            mask=getbitu(rtcm->buff,i,1); i+=1;
            if (mask) h->sats[h->nsat++]=j;
        }
        for (j=1;j<=32;j++) {
            mask=getbitu(rtcm->buff,i,1); i+=1;
            if (mask) h->sigs[h->nsig++]=j;
        }
    }
    else {
        trace(2,"rtcm3 %d length error: len=%d\n",type,rtcm->len);
        return -1;
    }
    /* test station id */
    if (!test_staid(rtcm,staid)) return -1;
    
    if (h->nsat*h->nsig>64) {
        trace(2,"rtcm3 %d number of sats and sigs error: nsat=%d nsig=%d\n",
              type,h->nsat,h->nsig);
        return -1;
    }
    if (i+h->nsat*h->nsig>rtcm->len*8) {
        trace(2,"rtcm3 %d length error: len=%d nsat=%d nsig=%d\n",type,
              rtcm->len,h->nsat,h->nsig);
        return -1;
    }
    for (j=0;j<h->nsat*h->nsig;j++) {
        h->cellmask[j]=getbitu(rtcm->buff,i,1); i+=1;
        if (h->cellmask[j]) ncell++;
    }
    *hsize=i;
    
    time2str(rtcm->time,tstr,2);
    trace(4,"decode_head_msm: time=%s sys=%d staid=%d nsat=%d nsig=%d sync=%d iod=%d ncell=%d\n",
          tstr,sys,staid,h->nsat,h->nsig,*sync,*iod,ncell);
    
    if (rtcm->outtype) {
        msg=rtcm->msgtype+strlen(rtcm->msgtype);
        sprintf(msg," staid=%4d %s nsat=%2d nsig=%2d iod=%2d ncell=%2d sync=%d",
                staid,tstr,h->nsat,h->nsig,*iod,ncell,*sync);
    }
    return ncell;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
leaq -0xe8(%rbp), %rdi
xorl %esi, %esi
movl $0xa8, %edx
callq 0x93d0
movl $0x18, -0x144(%rbp)
movl $0x0, -0x15c(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0xc, %edx
callq 0x8bfc0
movl %eax, -0x158(%rbp)
movl -0x144(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x144(%rbp)
movq -0x38(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
movl $0xa8, %edx
callq 0x9610
movl -0x144(%rbp), %eax
addl $0x9d, %eax
movq -0x18(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
jg 0x7b6ff
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0xc, %edx
callq 0x8bfc0
movl %eax, -0x154(%rbp)
movl -0x144(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x144(%rbp)
cmpl $0x4, -0x1c(%rbp)
jne 0x7b3c4
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x3, %edx
callq 0x8bfc0
movl %eax, -0x14c(%rbp)
movl -0x144(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1b, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x429b5(%rip), %xmm1    # 0xbdd48
mulsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movl -0x144(%rbp), %eax
addl $0x1b, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
movsd -0xf8(%rbp), %xmm0
callq 0x7a780
jmp 0x7b492
cmpl $0x20, -0x1c(%rbp)
jne 0x7b43a
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1e, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x42954(%rip), %xmm1    # 0xbdd48
mulsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movl -0x144(%rbp), %eax
addl $0x1e, %eax
movl %eax, -0x144(%rbp)
movsd 0x41ad1(%rip), %xmm0    # 0xbcee8
addsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movq -0x18(%rbp), %rdi
movsd -0xf0(%rbp), %xmm0
callq 0x7a020
jmp 0x7b490
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1e, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x428e4(%rip), %xmm1    # 0xbdd48
mulsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movl -0x144(%rbp), %eax
addl $0x1e, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
movsd -0xf0(%rbp), %xmm0
callq 0x7a020
jmp 0x7b492
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x3, %edx
callq 0x8bfc0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl -0x144(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x7, %edx
callq 0x8bfc0
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x144(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x2, %edx
callq 0x8bfc0
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x144(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x2, %edx
callq 0x8bfc0
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x3(%rax)
movl -0x144(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x4(%rax)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x3, %edx
callq 0x8bfc0
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x5(%rax)
movl -0x144(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x144(%rbp)
movl $0x1, -0x148(%rbp)
cmpl $0x40, -0x148(%rbp)
jg 0x7b679
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x150(%rbp)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
cmpl $0x0, -0x150(%rbp)
je 0x7b666
movl -0x148(%rbp), %eax
movb %al, %dl
movq -0x38(%rbp), %rax
movq -0x38(%rbp), %rsi
movb 0x6(%rsi), %cl
movb %cl, %dil
addb $0x1, %dil
movb %dil, 0x6(%rsi)
movzbl %cl, %ecx
movb %dl, 0x8(%rax,%rcx)
jmp 0x7b668
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x148(%rbp)
jmp 0x7b5ff
movl $0x1, -0x148(%rbp)
cmpl $0x20, -0x148(%rbp)
jg 0x7b6fd
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x150(%rbp)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
cmpl $0x0, -0x150(%rbp)
je 0x7b6ea
movl -0x148(%rbp), %eax
movb %al, %dl
movq -0x38(%rbp), %rax
movq -0x38(%rbp), %rsi
movb 0x7(%rsi), %cl
movb %cl, %dil
addb $0x1, %dil
movb %dil, 0x7(%rsi)
movzbl %cl, %ecx
movb %dl, 0x48(%rax,%rcx)
jmp 0x7b6ec
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x148(%rbp)
jmp 0x7b683
jmp 0x7b72e
movl -0x158(%rbp), %edx
movq -0x18(%rbp), %rax
movl 0x9f0c0(%rax), %ecx
movl $0x2, %edi
leaq 0x45a51(%rip), %rsi     # 0xc116c
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7b9e3
movq -0x18(%rbp), %rdi
movl -0x154(%rbp), %esi
callq 0x79f30
cmpl $0x0, %eax
jne 0x7b74e
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7b9e3
movq -0x38(%rbp), %rax
movzbl 0x6(%rax), %eax
movq -0x38(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
imull %ecx, %eax
cmpl $0x40, %eax
jle 0x7b79c
movl -0x158(%rbp), %edx
movq -0x38(%rbp), %rax
movzbl 0x6(%rax), %ecx
movq -0x38(%rbp), %rax
movzbl 0x7(%rax), %r8d
movl $0x2, %edi
leaq 0x463eb(%rip), %rsi     # 0xc1b74
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7b9e3
movl -0x144(%rbp), %eax
movq -0x38(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
movq -0x38(%rbp), %rdx
movzbl 0x7(%rdx), %edx
imull %edx, %ecx
addl %ecx, %eax
movq -0x18(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
jle 0x7b809
movl -0x158(%rbp), %edx
movq -0x18(%rbp), %rax
movl 0x9f0c0(%rax), %ecx
movq -0x38(%rbp), %rax
movzbl 0x6(%rax), %r8d
movq -0x38(%rbp), %rax
movzbl 0x7(%rax), %r9d
movl $0x2, %edi
leaq 0x463b7(%rip), %rsi     # 0xc1bad
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7b9e3
movl $0x0, -0x148(%rbp)
movl -0x148(%rbp), %eax
movq -0x38(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
movq -0x38(%rbp), %rdx
movzbl 0x7(%rdx), %edx
imull %edx, %ecx
cmpl %ecx, %eax
jge 0x7b8a2
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x144(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movb %al, %dl
movq -0x38(%rbp), %rax
movslq -0x148(%rbp), %rcx
movb %dl, 0x68(%rax,%rcx)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
movq -0x38(%rbp), %rax
movslq -0x148(%rbp), %rcx
cmpb $0x0, 0x68(%rax,%rcx)
je 0x7b88c
movl -0x15c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x15c(%rbp)
jmp 0x7b88e
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x148(%rbp)
jmp 0x7b813
movl -0x144(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x170(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x168(%rbp)
leaq -0x140(%rbp), %rsi
movq -0x170(%rbp), %rdi
movsd -0x168(%rbp), %xmm0
movl $0x2, %edx
callq 0x8f550
leaq -0x140(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x154(%rbp), %r8d
movq -0x38(%rbp), %rax
movzbl 0x6(%rax), %r9d
movq -0x38(%rbp), %rax
movzbl 0x7(%rax), %ebx
movq -0x28(%rbp), %rax
movl (%rax), %r11d
movq -0x30(%rbp), %rax
movl (%rax), %r10d
movl -0x15c(%rbp), %eax
movl $0x4, %edi
leaq 0x462b2(%rip), %rsi     # 0xc1bdc
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x8b980
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x7b9da
movq -0x18(%rbp), %rax
addq $0x9b9d0, %rax          # imm = 0x9B9D0
movq %rax, -0x178(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9b9d0, %rdi          # imm = 0x9B9D0
callq 0x92e0
movq %rax, %rcx
movq -0x178(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
movl -0x154(%rbp), %edx
leaq -0x140(%rbp), %rcx
movq -0x38(%rbp), %rax
movzbl 0x6(%rax), %r8d
movq -0x38(%rbp), %rax
movzbl 0x7(%rax), %r9d
movq -0x30(%rbp), %rax
movl (%rax), %r11d
movl -0x15c(%rbp), %r10d
movq -0x28(%rbp), %rax
movl (%rax), %eax
leaq 0x46268(%rip), %rsi     # 0xc1c2e
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x9150
movl -0x15c(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %rbp
retq