// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/rtcm.cpp
// Function: bamboo::input_rtcm2(bamboo::rtcm_t*, unsigned char)
extern int input_rtcm2(rtcm_t *rtcm, unsigned char data)
{
    unsigned char preamb;
    int i;
    
    trace(5,"input_rtcm2: data=%02x\n",data);
    
    if ((data&0xC0)!=0x40) return 0; /* ignore if upper 2bit != 01 */
    
    for (i=0;i<6;i++,data>>=1) { /* decode 6-of-8 form */
        rtcm->word=(rtcm->word<<1)+(data&1);
        
        /* synchronize frame */
        if (rtcm->nbyte==0) {
            preamb=(unsigned char)(rtcm->word>>22);
            if (rtcm->word&0x40000000) preamb^=0xFF; /* decode preamble */
            if (preamb!=RTCM2PREAMB) continue;
            
            /* check parity */
            if (!decode_word(rtcm->word,rtcm->buff)) continue;
            rtcm->nbyte=3; rtcm->nbit=0;
            continue;
        }
        if (++rtcm->nbit<30) continue; else rtcm->nbit=0;
        
        /* check parity */
        if (!decode_word(rtcm->word,rtcm->buff+rtcm->nbyte)) {
            trace(2,"rtcm2 partity error: i=%d word=%08x\n",i,rtcm->word);
            rtcm->nbyte=0; rtcm->word&=0x3;
            continue;
        }
        rtcm->nbyte+=3;
        if (rtcm->nbyte==6) rtcm->len=(rtcm->buff[5]>>3)*3+6;
        if (rtcm->nbyte<rtcm->len) continue;
        rtcm->nbyte=0; rtcm->word&=0x3;
        
        /* decode rtcm2 message */
        return decode_rtcm2(rtcm);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x31651(%rip), %rsi     # 0x641f9
pushq $0x5
popq %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x455bc
movl %r14d, %eax
andl $-0x40, %eax
cmpl $0x40, %eax
jne 0x32cc1
leaq 0x9f0c4(%rbx), %r15
pushq $0x2
popq %r13
xorl %r12d, %r12d
cmpl $0x6, %r12d
je 0x32cc1
movl 0x9f574(%rbx), %eax
movl %r14d, %ecx
andb $0x1, %cl
movzbl %cl, %ecx
leal (%rcx,%rax,2), %edi
movl %edi, 0x9f574(%rbx)
movslq 0x9f0b8(%rbx), %rsi
testq %rsi, %rsi
je 0x32c57
movl 0x9f0bc(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x9f0bc(%rbx)
cmpl $0x1d, %eax
jl 0x32cb6
andl $0x0, 0x9f0bc(%rbx)
addq %r15, %rsi
callq 0x45bbf
testl %eax, %eax
je 0x32c82
movl 0x9f0b8(%rbx), %eax
addl $0x3, %eax
movl %eax, 0x9f0b8(%rbx)
cmpl $0x6, %eax
jne 0x32cac
movzbl 0x9f0c9(%rbx), %ecx
shrl $0x3, %ecx
leal (%rcx,%rcx,2), %ecx
addl $0x6, %ecx
movl %ecx, 0x9f0c0(%rbx)
jmp 0x32cb2
leal (%rax,%rax), %ecx
shrl $0x16, %ecx
shll $0x2, %eax
sarl $0x1f, %eax
xorl %ecx, %eax
cmpb $0x66, %al
jne 0x32cb6
movq %r15, %rsi
callq 0x45bbf
testl %eax, %eax
je 0x32cb6
movq $0x3, 0x9f0b8(%rbx)
jmp 0x32cb6
movl 0x9f574(%rbx), %ecx
movl %r13d, %edi
leaq 0x3157f(%rip), %rsi     # 0x64211
movl %r12d, %edx
xorl %eax, %eax
callq 0x455bc
andl $0x0, 0x9f0b8(%rbx)
andl $0x3, 0x9f574(%rbx)
jmp 0x32cb6
movl 0x9f0c0(%rbx), %ecx
cmpl %ecx, %eax
jge 0x32cd2
incl %r12d
shrb %r14b
jmp 0x32bd2
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andl $0x0, 0x9f0b8(%rbx)
andl $0x3, 0x9f574(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33040