// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, -0x58(%rbp)
movq %r8, %r15
movq %rcx, -0x50(%rbp)
movq %rdx, -0x38(%rbp)
movl %esi, %r14d
movq %rdi, %r13
leaq 0x9f0c4(%rdi), %rbx
movq %rbx, %rdi
movl $0x18, %esi
movl $0xc, %edx
callq 0x4e341
movl %eax, %r12d
movl $0xa8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x8390
movq %r13, -0x48(%rbp)
movl 0x9f0c0(%r13), %ecx
cmpl $0x19, %ecx
jl 0x438dd
movl %r12d, -0x3c(%rbp)
movq %rbx, %rdi
movl $0x24, %esi
movl $0xc, %edx
callq 0x4e341
cmpl $0x20, %r14d
movl %eax, -0x2c(%rbp)
movl %r14d, -0x40(%rbp)
je 0x438fe
cmpl $0x4, %r14d
movq -0x48(%rbp), %r12
movq %rbx, %rdi
movl $0x30, %esi
jne 0x4392d
movl $0x3, %edx
callq 0x4e341
movq %rbx, %rdi
movl $0x33, %esi
movl $0x1b, %edx
callq 0x4e341
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x284a5(%rip), %xmm0    # 0x6bd78
movq %r12, %rdi
callq 0x432c4
jmp 0x4394e
leaq 0x2b663(%rip), %rsi     # 0x6ef47
movl $0x2, %edi
movl %r12d, %edx
xorl %eax, %eax
callq 0x4ded0
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x43c0a
movq %rbx, %rdi
movl $0x30, %esi
movl $0x1e, %edx
callq 0x4e341
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x28459(%rip), %xmm0    # 0x6bd78
addsd 0x27081(%rip), %xmm0    # 0x6a9a8
movq -0x48(%rbp), %r12
jmp 0x43946
movl $0x1e, %edx
callq 0x4e341
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x28432(%rip), %xmm0    # 0x6bd78
movq %r12, %rdi
callq 0x4302b
movq -0x38(%rbp), %r14
movq %rbx, %rdi
movl $0x4e, %esi
movl $0x1, %edx
callq 0x4e341
movl %eax, (%r14)
movq %rbx, %rdi
movl $0x4f, %esi
movl $0x3, %edx
callq 0x4e341
movq -0x50(%rbp), %rcx
movl %eax, (%rcx)
movq %rbx, %rdi
movl $0x52, %esi
movl $0x7, %edx
callq 0x4e341
movb %al, 0x1(%r15)
movq %rbx, %rdi
movl $0x59, %esi
movl $0x2, %edx
callq 0x4e341
movb %al, 0x2(%r15)
movq %rbx, %rdi
movl $0x5b, %esi
movl $0x2, %edx
callq 0x4e341
movb %al, 0x3(%r15)
movq %rbx, %rdi
movl $0x5d, %esi
movl $0x1, %edx
callq 0x4e341
movb %al, 0x4(%r15)
movq %rbx, %rdi
movl $0x5e, %esi
movl $0x3, %edx
callq 0x4e341
movb %al, 0x5(%r15)
movl $0x61, %r13d
movq %rbx, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x4e341
testl %eax, %eax
je 0x43a1c
movzbl 0x6(%r15), %eax
leal 0x1(%rax), %ecx
movb %cl, 0x6(%r15)
leal -0x60(%r13), %ecx
movb %cl, 0x8(%r15,%rax)
incl %r13d
cmpl $0xa1, %r13d
jne 0x439f3
movl $0xa1, %r13d
movq %rbx, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x4e341
testl %eax, %eax
je 0x43a57
movzbl 0x7(%r15), %eax
leal 0x1(%rax), %ecx
movb %cl, 0x7(%r15)
leal 0x60(%r13), %ecx
movb %cl, 0x48(%r15,%rax)
incl %r13d
cmpl $0xc1, %r13d
jne 0x43a2e
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x42f7e
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x43c0a
movzbl 0x6(%r15), %r8d
movzbl 0x7(%r15), %r9d
movl %r9d, %eax
imull %r8d, %eax
cmpl $0x41, %eax
jb 0x43ab3
leaq 0x2beb6(%rip), %rsi     # 0x6f94f
movl $0x2, %edi
movl -0x3c(%rbp), %edx
movl %r8d, %ecx
movl %r9d, %r8d
xorl %eax, %eax
callq 0x4ded0
jmp 0x43c0a
addl $0xc1, %eax
movl 0x9f0c0(%r12), %ecx
leal (,%rcx,8), %edx
cmpl %edx, %eax
movl -0x3c(%rbp), %edx
jle 0x43ae6
leaq 0x2beb3(%rip), %rsi     # 0x6f988
movl $0x2, %edi
xorl %eax, %eax
callq 0x4ded0
jmp 0x43c0a
cmpb $0x0, 0x6(%r15)
sete %al
cmpb $0x0, 0x7(%r15)
sete %cl
orb %al, %cl
jne 0x43b3e
xorl %r14d, %r14d
xorl %r13d, %r13d
leal 0xc1(%r14), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x4e341
movb %al, 0x68(%r15,%r14)
cmpb $0x1, %al
sbbl $-0x1, %r13d
incq %r14
movzbl 0x6(%r15), %eax
movzbl 0x7(%r15), %ecx
imulq %rax, %rcx
cmpq %rcx, %r14
jb 0x43b00
addl $0xc1, %r14d
jmp 0x43b47
xorl %r13d, %r13d
movl $0xc1, %r14d
movq -0x58(%rbp), %rax
movl %r14d, (%rax)
movq 0x10(%r12), %rdi
movsd 0x18(%r12), %xmm0
leaq -0xa0(%rbp), %rsi
movl $0x2, %edx
callq 0x50696
movzbl 0x6(%r15), %r9d
movzbl 0x7(%r15), %r10d
movq -0x38(%rbp), %rax
movl (%rax), %r11d
movq -0x50(%rbp), %rbx
movl (%rbx), %r14d
leaq 0x2be2d(%rip), %rsi     # 0x6f9b7
movl $0x4, %edi
leaq -0xa0(%rbp), %rdx
movl -0x40(%rbp), %ecx
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
pushq %r13
pushq %r14
pushq %r11
pushq %r10
callq 0x4ded0
addq $0x20, %rsp
cmpl $0x0, 0xc(%r12)
je 0x43c0a
leaq 0x9b9d0(%r12), %rdi
callq 0x8290
leaq (%r12,%rax), %rdi
addq $0x9b9d0, %rdi          # imm = 0x9B9D0
movzbl 0x6(%r15), %r8d
movzbl 0x7(%r15), %r9d
movl (%rbx), %r10d
movq -0x38(%rbp), %rax
movl (%rax), %r11d
subq $0x8, %rsp
leaq 0x2be1a(%rip), %rsi     # 0x6fa09
leaq -0xa0(%rbp), %rcx
movl -0x2c(%rbp), %edx
xorl %eax, %eax
pushq %r11
pushq %r13
pushq %r10
callq 0x8120
addq $0x20, %rsp
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq