// File: /workspace/github_cpp_makefile_star2_O3/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 0x34590(%rip), %rsi     # 0x6e570
movl $0x4, %edi
xorl %eax, %eax
callq 0x4d55d
movl 0x9f0c0(%rbx), %edx
cmpl $0x9, %edx
jl 0x3a290
leaq 0x9f0c4(%rbx), %r15
movq %r15, %rdi
movl $0x30, %esi
movl $0x2, %edx
callq 0x4d9d6
movl %eax, %r14d
movq %r15, -0x70(%rbp)
movq %r15, %rdi
movl $0x34, %esi
movl $0x14, %edx
callq 0x4d9d6
testb $0x1, %r14b
jne 0x3a29e
movl %eax, %ecx
xorl %eax, %eax
cmpl $0xf, 0x9f0c0(%rbx)
jl 0x3a288
cmpl $0x3f, 0x30(%rbx)
jg 0x3a288
movl %ecx, %eax
cvtsi2sd %rax, %xmm0
leaq 0x30(%rbx), %rax
movq %rax, -0x48(%rbp)
movl %r14d, -0x2c(%rbp)
sarl %r14d
mulsd 0x32bd0(%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 0x4d9d6
movl %eax, -0x30(%rbp)
leal 0x1(%r13), %esi
movq %r12, %rdi
movl $0x1, %edx
callq 0x4d9d6
movl %eax, -0x3c(%rbp)
leal 0x2(%r13), %esi
movq %r12, %rdi
movl $0x1, %edx
callq 0x4d9d6
movl %eax, %r14d
leal 0x3(%r13), %esi
movq %r12, %rdi
movl $0x5, %edx
callq 0x4d9d6
movl %eax, %r15d
leal 0xb(%r13), %esi
movq %r12, %rdi
movl $0x5, %edx
callq 0x4d9d6
movl %eax, -0x38(%rbp)
addl $0x10, %r13d
movq %r12, %rdi
movl %r13d, %esi
movl $0x20, %edx
callq 0x4da25
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 0x4d28d
testl %eax, %eax
je 0x3a243
movl %eax, %r12d
movq 0x10(%rbx), %rdi
movsd 0x18(%rbx), %xmm0
movsd -0x60(%rbp), %xmm1
callq 0x4f4e7
movq %rax, %r15
movaps %xmm0, %xmm1
testl %r14d, %r14d
je 0x3a166
movq %r15, %rdi
movaps %xmm1, %xmm0
callq 0x4fa70
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 0x4f51b
cmpl $0x0, 0x9bdd0(%rbx)
jne 0x3a19a
andpd 0x2f7a0(%rip), %xmm0    # 0x69930
ucomisd 0x32b70(%rip), %xmm0    # 0x6cd08
jbe 0x3a1a5
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 0x3a757
testl %eax, %eax
js 0x3a25c
xorps %xmm0, %xmm0
cvtsi2sdl -0x34(%rbp), %xmm0
mulsd 0x34157(%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 0x3a25c
movl $0x2, %edi
leaq 0x34382(%rip), %rsi     # 0x6e5d1
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4d55d
movl 0x9f0c0(%rbx), %eax
shll $0x3, %eax
addl $0x50, %r13d
cmpl %eax, %r13d
jg 0x3a27f
addl $-0x30, %r13d
movq -0x48(%rbp), %rax
cmpl $0x3f, (%rax)
jle 0x3a08d
xorl %eax, %eax
cmpl $0x0, -0x30(%rbp)
sete %al
movl %eax, 0x9bdd0(%rbx)
jmp 0x3a2b9
leaq 0x342f0(%rip), %rsi     # 0x6e587
movl $0x2, %edi
jmp 0x3a2ad
leaq 0x34301(%rip), %rsi     # 0x6e5a6
movl $0x2, %edi
movl %r14d, %edx
xorl %eax, %eax
callq 0x4d55d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq