// File: /workspace/github_cpp_makefile_star2_O2/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, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movl %esi, %r12d
movq %rdi, %r13
leaq 0x9f0c4(%rdi), %rbx
pushq $0x18
popq %rsi
pushq $0xc
popq %rdx
movq %rbx, %rdi
callq 0x459f7
movl %eax, %r14d
movl $0xa8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x8390
movl 0x9f0c0(%r13), %ecx
cmpl $0x19, %ecx
jl 0x3bc38
movl %r14d, -0x3c(%rbp)
pushq $0x24
popq %rsi
pushq $0xc
popq %rdx
movq %rbx, %rdi
callq 0x459f7
movl %eax, -0x40(%rbp)
cmpl $0x20, %r12d
movq %r13, -0x48(%rbp)
movl %r12d, -0x4c(%rbp)
pushq $0x30
popq %rsi
je 0x3bc55
cmpl $0x4, %r12d
jne 0x3bc79
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0x459f7
pushq $0x33
popq %rsi
pushq $0x1b
popq %rdx
movq %rbx, %rdi
callq 0x459f7
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x2614a(%rip), %xmm0    # 0x61d78
movq %r13, %rdi
callq 0x3b61c
jmp 0x3bc9b
leaq 0x29304(%rip), %rsi     # 0x64f43
pushq $0x2
popq %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x455bc
pushq $-0x1
popq %r13
jmp 0x3bf46
pushq $0x1e
popq %rdx
movq %rbx, %rdi
callq 0x459f7
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x26109(%rip), %xmm0    # 0x61d78
addsd 0x24d21(%rip), %xmm0    # 0x60998
jmp 0x3bc93
pushq $0x1e
popq %rdx
movq %rbx, %rdi
callq 0x459f7
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x260e5(%rip), %xmm0    # 0x61d78
movq %r13, %rdi
callq 0x3b289
movq -0x30(%rbp), %r14
movq -0x38(%rbp), %r12
pushq $0x4e
popq %rsi
pushq $0x1
popq %r13
movq %rbx, %rdi
movl %r13d, %edx
callq 0x459f7
movl %eax, (%r12)
pushq $0x4f
popq %rsi
pushq $0x3
popq %r12
movq %rbx, %rdi
movl %r12d, %edx
callq 0x459f7
movl %eax, (%r14)
pushq $0x52
popq %rsi
pushq $0x7
popq %rdx
movq %rbx, %rdi
callq 0x459f7
movb %al, 0x1(%r15)
pushq $0x59
popq %rsi
pushq $0x2
popq %r14
movq %rbx, %rdi
movl %r14d, %edx
callq 0x459f7
movb %al, 0x2(%r15)
pushq $0x5b
popq %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x459f7
movb %al, 0x3(%r15)
pushq $0x5d
popq %rsi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x459f7
movb %al, 0x4(%r15)
pushq $0x5e
popq %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x459f7
movb %al, 0x5(%r15)
pushq $0x61
popq %r14
pushq $-0x40
popq %r12
testl %r12d, %r12d
je 0x3bd69
movq %rbx, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x459f7
testl %eax, %eax
je 0x3bd61
movzbl 0x6(%r15), %eax
leal 0x1(%rax), %ecx
movb %cl, 0x6(%r15)
leal 0x41(%r12), %ecx
movb %cl, 0x8(%r15,%rax)
incl %r12d
incl %r14d
jmp 0x3bd34
movl $0xa1, %r14d
pushq $-0x20
popq %r12
pushq $0x1
popq %r13
testl %r12d, %r12d
je 0x3bdac
movq %rbx, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x459f7
testl %eax, %eax
je 0x3bda4
movzbl 0x7(%r15), %eax
leal 0x1(%rax), %ecx
movb %cl, 0x7(%r15)
leal 0x21(%r12), %ecx
movb %cl, 0x48(%r15,%rax)
incl %r12d
incl %r14d
jmp 0x3bd77
movq -0x48(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x3b1e4
pushq $-0x1
popq %r13
testl %eax, %eax
je 0x3bf46
movb 0x6(%r15), %r10b
movb 0x7(%r15), %al
movzbl %r10b, %r8d
movzbl %al, %r9d
movl %r9d, %esi
imull %r8d, %esi
cmpl $0x41, %esi
jb 0x3bdff
leaq 0x29b64(%rip), %rsi     # 0x6594b
pushq $0x2
popq %rdi
movl -0x3c(%rbp), %edx
movl %r8d, %ecx
movl %r9d, %r8d
xorl %eax, %eax
callq 0x455bc
jmp 0x3bf46
addl $0xc1, %esi
movq -0x48(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
leal (,%rcx,8), %edi
cmpl %edi, %esi
movl -0x3c(%rbp), %edx
jle 0x3be33
leaq 0x29b60(%rip), %rsi     # 0x65984
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x455bc
jmp 0x3bf46
xorl %r12d, %r12d
pushq $0x1
popq %r14
xorl %r13d, %r13d
movzbl %r10b, %ecx
movzbl %al, %eax
imulq %rcx, %rax
cmpq %rax, %r12
jae 0x3be78
leaq 0xc1(%r12), %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x459f7
cmpb $0x1, %al
sbbl $-0x1, %r13d
movb %al, 0x68(%r15,%r12)
incq %r12
movb 0x6(%r15), %r10b
movb 0x7(%r15), %al
jmp 0x3be3d
addl $0xc1, %r12d
movq -0x58(%rbp), %rax
movl %r12d, (%rax)
movq -0x48(%rbp), %r12
movq 0x10(%r12), %rdi
movsd 0x18(%r12), %xmm0
leaq -0xa0(%rbp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rsi
callq 0x47a48
movzbl 0x6(%r15), %r9d
movzbl 0x7(%r15), %r10d
movq -0x38(%rbp), %rax
movl (%rax), %r11d
movq -0x30(%rbp), %rax
movl (%rax), %r14d
leaq 0x29aec(%rip), %rsi     # 0x659b3
pushq $0x4
popq %rdi
movq %rbx, %rdx
movl -0x4c(%rbp), %ecx
movl -0x40(%rbp), %ebx
movl %ebx, %r8d
xorl %eax, %eax
pushq %r13
pushq %r14
pushq %r11
pushq %r10
callq 0x455bc
addq $0x20, %rsp
cmpl $0x0, 0xc(%r12)
je 0x3bf46
leaq 0x9b9d0(%r12), %rdi
callq 0x8290
leaq (%r12,%rax), %rdi
addq $0x9b9d0, %rdi          # imm = 0x9B9D0
movzbl 0x6(%r15), %r8d
movzbl 0x7(%r15), %r9d
movq -0x30(%rbp), %rax
movl (%rax), %r10d
movq -0x38(%rbp), %rax
movl (%rax), %r11d
subq $0x8, %rsp
leaq 0x29ad9(%rip), %rsi     # 0x65a05
leaq -0xa0(%rbp), %rcx
movl %ebx, %edx
xorl %eax, %eax
pushq %r11
pushq %r13
pushq %r10
callq 0x8110
addq $0x20, %rsp
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq