// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rtklib/rtcm2.cpp
// Function: bamboo::decode_type18(bamboo::rtcm_t*)
static int decode_type18(rtcm_t *rtcm)
{
    gtime_t time;
    double usec,cp,tt;
    int i=48,index,freq,sync=1,code,sys,prn,sat,loss;
    
    trace(4,"decode_type18: len=%d\n",rtcm->len);
    
    if (i+24<=rtcm->len*8) {
        freq=getbitu(rtcm->buff,i, 2); i+= 2+2;
        usec=getbitu(rtcm->buff,i,20); i+=20;
    }
    else {
        trace(2,"rtcm2 18 length error: len=%d\n",rtcm->len);
        return -1;
    }
    if (freq&0x1) {
        trace(2,"rtcm2 18 not supported frequency: freq=%d\n",freq);
        return -1;
    }
    freq>>=1;
    
    while (i+48<=rtcm->len*8&&rtcm->obs.n<MAXOBS) {
        sync=getbitu(rtcm->buff,i, 1); i+= 1;
        code=getbitu(rtcm->buff,i, 1); i+= 1;
        sys =getbitu(rtcm->buff,i, 1); i+= 1;
        prn =getbitu(rtcm->buff,i, 5); i+= 5+3;
        loss=getbitu(rtcm->buff,i, 5); i+= 5;
        cp  =getbits(rtcm->buff,i,32); i+=32;
        if (prn==0) prn=32;
        if (!(sat=satno(sys?SYS_GLO:SYS_GPS,prn))) {
            trace(2,"rtcm2 18 satellite number error: sys=%d prn=%d\n",sys,prn);
            continue;
        }
        time=timeadd(rtcm->time,usec*1E-6);
        if (sys) time=utc2gpst(time); /* convert glonass time to gpst */
        
        tt=timediff(rtcm->obs.data[0].time,time);
        if (rtcm->obsflag||fabs(tt)>1E-9) {
            rtcm->obs.n=rtcm->obsflag=0;
        }
        if ((index=obsindex(&rtcm->obs,time,sat))>=0) {
            rtcm->obs.data[index].L[freq]=-cp/256.0;
            rtcm->obs.data[index].LLI[freq]=rtcm->loss[sat-1][freq]!=loss;
            rtcm->obs.data[index].code[freq]=
                !freq?(code?CODE_L1P:CODE_L1C):(code?CODE_L2P:CODE_L2C);
            rtcm->loss[sat-1][freq]=loss;
        }
    }
    rtcm->obsflag=!sync;
    return sync?0:1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movl 0x9f0c0(%rdi), %edx
leaq 0x33f3d(%rip), %rsi     # 0x6e570
movl $0x4, %edi
xorl %eax, %eax
callq 0x4ded0
movl 0x9f0c0(%rbx), %edx
cmpl $0x9, %edx
jl 0x3a8e3
leaq 0x9f0c4(%rbx), %r15
movq %r15, %rdi
movl $0x30, %esi
movl $0x2, %edx
callq 0x4e341
movl %eax, %r14d
movq %r15, -0x70(%rbp)
movq %r15, %rdi
movl $0x34, %esi
movl $0x14, %edx
callq 0x4e341
testb $0x1, %r14b
jne 0x3a8f1
movl %eax, %ecx
xorl %eax, %eax
cmpl $0xf, 0x9f0c0(%rbx)
jl 0x3a8db
cmpl $0x3f, 0x30(%rbx)
jg 0x3a8db
movl %ecx, %eax
cvtsi2sd %rax, %xmm0
leaq 0x30(%rbx), %rax
movq %rax, -0x48(%rbp)
movl %r14d, -0x2c(%rbp)
sarl %r14d
mulsd 0x3257d(%rip), %xmm0    # 0x6cc40
movsd %xmm0, -0x60(%rbp)
movslq %r14d, %rax
movq %rax, -0x58(%rbp)
leaq 0x9d002(%rbx), %rax
movq %rax, -0x50(%rbp)
movl $0x48, %r13d
movq -0x70(%rbp), %r12
movq %r12, %rdi
movl %r13d, %esi
movl $0x1, %edx
callq 0x4e341
movl %eax, -0x30(%rbp)
leal 0x1(%r13), %esi
movq %r12, %rdi
movl $0x1, %edx
callq 0x4e341
movl %eax, -0x3c(%rbp)
leal 0x2(%r13), %esi
movq %r12, %rdi
movl $0x1, %edx
callq 0x4e341
movl %eax, %r14d
leal 0x3(%r13), %esi
movq %r12, %rdi
movl $0x5, %edx
callq 0x4e341
movl %eax, %r15d
leal 0xb(%r13), %esi
movq %r12, %rdi
movl $0x5, %edx
callq 0x4e341
movl %eax, -0x38(%rbp)
addl $0x10, %r13d
movq %r12, %rdi
movl %r13d, %esi
movl $0x20, %edx
callq 0x4e390
movl %eax, -0x34(%rbp)
testl %r15d, %r15d
movl $0x20, %eax
cmovel %eax, %r15d
xorl %eax, %eax
testl %r14d, %r14d
setne %al
leal (%rax,%rax,2), %edi
incl %edi
movl %r15d, %esi
callq 0x4dbc5
testl %eax, %eax
je 0x3a896
movl %eax, %r12d
movq 0x10(%rbx), %rdi
movsd 0x18(%rbx), %xmm0
movsd -0x60(%rbp), %xmm1
callq 0x4fe63
movq %rax, %r15
movaps %xmm0, %xmm1
testl %r14d, %r14d
je 0x3a7b9
movq %r15, %rdi
movaps %xmm1, %xmm0
callq 0x5040e
movq %rax, %r15
movaps %xmm0, %xmm1
movq 0x38(%rbx), %rax
movq (%rax), %rdi
movsd 0x8(%rax), %xmm0
movq %r15, %rsi
movsd %xmm1, -0x68(%rbp)
callq 0x4fe97
cmpl $0x0, 0x9bdd0(%rbx)
jne 0x3a7ed
andpd 0x2f14d(%rip), %xmm0    # 0x69930
ucomisd 0x3251d(%rip), %xmm0    # 0x6cd08
jbe 0x3a7f8
xorl %eax, %eax
movl %eax, 0x9bdd0(%rbx)
movl %eax, 0x30(%rbx)
movq -0x48(%rbp), %rdi
movq %r15, %rsi
movsd -0x68(%rbp), %xmm0
movl %r12d, %edx
callq 0x3adaa
testl %eax, %eax
js 0x3a8af
xorps %xmm0, %xmm0
cvtsi2sdl -0x34(%rbp), %xmm0
mulsd 0x33b04(%rip), %xmm0    # 0x6e328
movl %eax, %eax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rax
movq 0x38(%rbx), %rcx
addq %rax, %rcx
movq -0x58(%rbp), %r8
movsd %xmm0, 0x20(%rcx,%r8,8)
decl %r12d
movslq %r12d, %rdx
leaq (%rdx,%rdx,2), %rdx
movq -0x50(%rbp), %rsi
leaq (%rsi,%rdx,2), %rdx
movzwl (%rdx,%r8,2), %esi
movl -0x38(%rbp), %r9d
cmpl %esi, %r9d
setne 0x15(%r8,%rcx)
xorl %ecx, %ecx
cmpl $0x0, -0x3c(%rbp)
sete %sil
setne %cl
movb $0x2, %dil
subb %sil, %dil
cmpl $0x0, -0x2c(%rbp)
leal 0xe(%rcx,%rcx,4), %ecx
movzbl %dil, %esi
cmovnel %ecx, %esi
addq 0x38(%rbx), %rax
movb %sil, 0x18(%r8,%rax)
movw %r9w, (%rdx,%r8,2)
jmp 0x3a8af
movl $0x2, %edi
leaq 0x33d2f(%rip), %rsi     # 0x6e5d1
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4ded0
movl 0x9f0c0(%rbx), %eax
shll $0x3, %eax
addl $0x50, %r13d
cmpl %eax, %r13d
jg 0x3a8d2
addl $-0x30, %r13d
movq -0x48(%rbp), %rax
cmpl $0x3f, (%rax)
jle 0x3a6e0
xorl %eax, %eax
cmpl $0x0, -0x30(%rbp)
sete %al
movl %eax, 0x9bdd0(%rbx)
jmp 0x3a90c
leaq 0x33c9d(%rip), %rsi     # 0x6e587
movl $0x2, %edi
jmp 0x3a900
leaq 0x33cae(%rip), %rsi     # 0x6e5a6
movl $0x2, %edi
movl %r14d, %edx
xorl %eax, %eax
callq 0x4ded0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq