// File: DoubleString[P]RtConverter/src/Rtklib/rtcm2.cpp
// Function: bamboo::decode_rtcm2(bamboo::rtcm_t*)
extern int decode_rtcm2(rtcm_t *rtcm)
{
    double zcnt;
    int staid,seqno,stah,ret=0,type=getbitu(rtcm->buff,8,6);
    
    trace(3,"decode_rtcm2: type=%2d len=%3d\n",type,rtcm->len);
    
    if ((zcnt=getbitu(rtcm->buff,24,13)*0.6)>=3600.0) {
        trace(2,"rtcm2 modified z-count error: zcnt=%.1f\n",zcnt);
        return -1;
    }
    adjhour(rtcm,zcnt);
    staid=getbitu(rtcm->buff,14,10);
    seqno=getbitu(rtcm->buff,37, 3);
    stah =getbitu(rtcm->buff,45, 3);
    if (seqno-rtcm->seqno!=1&&seqno-rtcm->seqno!=-7) {
        trace(2,"rtcm2 message outage: seqno=%d->%d\n",rtcm->seqno,seqno);
    }
    rtcm->seqno=seqno;
    rtcm->stah =stah;
    
    if (rtcm->outtype) {
        sprintf(rtcm->msgtype,"RTCM %2d (%4d) zcnt=%7.1f staid=%3d seqno=%d",
                type,rtcm->len,zcnt,staid,seqno);
    }
    if (type==3||type==22||type==23||type==24) {
        if (rtcm->staid!=0&&staid!=rtcm->staid) {
           trace(2,"rtcm2 station id changed: %d->%d\n",rtcm->staid,staid);
        }
        rtcm->staid=staid;
    }
    if (rtcm->staid!=0&&staid!=rtcm->staid) {
        trace(2,"rtcm2 station id invalid: %d %d\n",staid,rtcm->staid);
        return -1;
    }
    switch (type) {
        case  1: ret=decode_type1 (rtcm); break;
        case  3: ret=decode_type3 (rtcm); break;
        case  9: ret=decode_type1 (rtcm); break;
        case 14: ret=decode_type14(rtcm); break;
        case 16: ret=decode_type16(rtcm); break;
        case 17: ret=decode_type17(rtcm); break;
        case 18: ret=decode_type18(rtcm); break;
        case 19: ret=decode_type19(rtcm); break;
        case 22: ret=decode_type22(rtcm); break;
        case 23: ret=decode_type23(rtcm); break; /* not supported */
        case 24: ret=decode_type24(rtcm); break; /* not supported */
        case 31: ret=decode_type31(rtcm); break; /* not supported */
        case 32: ret=decode_type32(rtcm); break; /* not supported */
        case 34: ret=decode_type34(rtcm); break; /* not supported */
        case 36: ret=decode_type36(rtcm); break; /* not supported */
        case 37: ret=decode_type37(rtcm); break; /* not supported */
        case 59: ret=decode_type59(rtcm); break; /* not supported */
    }
    if (ret>=0) {
        if (1<=type&&type<=99) rtcm->nmsg2[type]++; else rtcm->nmsg2[0]++;
    }
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl $0x8, %esi
movl $0x6, %edx
callq 0x8bfc0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %ecx
leaq 0x54e68(%rip), %rsi     # 0xc068c
xorl %eax, %eax
movl $0x3, %edi
callq 0x8b980
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl $0x18, %esi
movl $0xd, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x54cff(%rip), %xmm1    # 0xc0558
mulsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd 0x515a6(%rip), %xmm1    # 0xbce10
ucomisd %xmm1, %xmm0
jb 0x6b894
movsd -0x18(%rbp), %xmm0
movl $0x2, %edi
leaq 0x54e2b(%rip), %rsi     # 0xc06ac
movb $0x1, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6bb87
movq -0x10(%rbp), %rdi
movsd -0x18(%rbp), %xmm0
callq 0x6bb90
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl $0xe, %esi
movl $0xa, %edx
callq 0x8bfc0
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl $0x25, %esi
movl $0x3, %edx
callq 0x8bfc0
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl $0x2d, %esi
movl $0x3, %edx
callq 0x8bfc0
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
cmpl $0x1, %eax
je 0x6b934
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
cmpl $-0x7, %eax
je 0x6b934
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movl -0x20(%rbp), %ecx
movl $0x2, %edi
leaq 0x54da8(%rip), %rsi     # 0xc06d5
movb $0x0, %al
callq 0x8b980
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x6b985
movq -0x10(%rbp), %rdi
addq $0x9b9d0, %rdi          # imm = 0x9B9D0
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %ecx
movsd -0x18(%rbp), %xmm0
movl -0x1c(%rbp), %r8d
movl -0x20(%rbp), %r9d
leaq 0x54d7b(%rip), %rsi     # 0xc06f9
movb $0x1, %al
callq 0x9150
cmpl $0x3, -0x2c(%rbp)
je 0x6b99d
cmpl $0x16, -0x2c(%rbp)
je 0x6b99d
cmpl $0x17, -0x2c(%rbp)
je 0x6b99d
cmpl $0x18, -0x2c(%rbp)
jne 0x6b9d6
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6b9cd
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x6b9cd
movq -0x10(%rbp), %rax
movl (%rax), %edx
movl -0x1c(%rbp), %ecx
movl $0x2, %edi
leaq 0x54d60(%rip), %rsi     # 0xc0726
movb $0x0, %al
callq 0x8b980
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6ba12
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x6ba12
movl -0x1c(%rbp), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movl $0x2, %edi
leaq 0x54d49(%rip), %rsi     # 0xc0748
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6bb87
movl -0x2c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x3a, %eax
ja 0x6bb3b
movq -0x38(%rbp), %rax
leaq 0x54b6f(%rip), %rcx     # 0xc05a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
callq 0x6bd10
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6c010
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6bd10
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6c150
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6c2c0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6c3a0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6ccb0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d1f0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d680
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d970
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d980
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d990
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d9a0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d9b0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d9c0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d9d0
movl %eax, -0x28(%rbp)
jmp 0x6bb3b
movq -0x10(%rbp), %rdi
callq 0x6d9e0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jl 0x6bb81
movl $0x1, %eax
cmpl -0x2c(%rbp), %eax
jg 0x6bb6c
cmpl $0x63, -0x2c(%rbp)
jg 0x6bb6c
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl 0x9f578(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x9f578(%rax,%rcx,4)
jmp 0x6bb7f
movq -0x10(%rbp), %rax
movl 0x9f578(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x9f578(%rax)
jmp 0x6bb81
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq