// File: 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
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl $0x30, -0x3c(%rbp)
movl $0x1, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %edx
movl $0x4, %edi
leaq 0x53b9e(%rip), %rsi     # 0xc0881
movb $0x0, %al
callq 0x8b980
movl -0x3c(%rbp), %eax
addl $0x18, %eax
movq -0x10(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
jg 0x6cd54
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x2, %edx
callq 0x8bfc0
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x14, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x3c(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6cd7d
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %edx
movl $0x2, %edi
leaq 0x53b2e(%rip), %rsi     # 0xc0898
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d1da
movl -0x44(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6cdaa
movl -0x44(%rbp), %edx
movl $0x2, %edi
leaq 0x53b20(%rip), %rsi     # 0xc08b7
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d1da
movl -0x44(%rbp), %eax
sarl %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x30, %ecx
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %edx
shll $0x3, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0xd1(%rbp)
jg 0x6cde2
movq -0x10(%rbp), %rax
cmpl $0x40, 0x30(%rax)
setl %al
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x6cdf1
jmp 0x6d1af
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x5, %edx
callq 0x8bfc0
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x5, %edx
callq 0x8bfc0
movl %eax, -0x5c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x3c(%rbp), %esi
movl $0x20, %edx
callq 0x8c050
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x3c(%rbp), %eax
addl $0x20, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0x6cedc
movl $0x20, -0x54(%rbp)
movl -0x50(%rbp), %ecx
movl $0x1, %edi
movl $0x4, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edi
movl -0x54(%rbp), %esi
callq 0x8b1b0
movl %eax, -0x58(%rbp)
cmpl $0x0, %eax
jne 0x6cf1d
movl -0x50(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x2, %edi
leaq 0x539d1(%rip), %rsi     # 0xc08e2
movb $0x0, %al
callq 0x8b980
jmp 0x6cdb2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x80(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
movsd 0x51e97(%rip), %xmm1    # 0xbedd0
mulsd -0x28(%rbp), %xmm1
movq -0x80(%rbp), %rdi
movsd -0x78(%rbp), %xmm0
callq 0x8e860
movq %rax, -0x70(%rbp)
movsd %xmm0, -0x68(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x6cfba
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rdi
movsd -0x98(%rbp), %xmm0
callq 0x8f0a0
movq %rax, -0x90(%rbp)
movsd %xmm0, -0x88(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rcx
movq %rcx, -0xb0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
movq -0xc0(%rbp), %rsi
movsd -0xb8(%rbp), %xmm1
callq 0x8e8e0
movsd %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x9bdd0(%rax)
jne 0x6d040
movsd -0x38(%rbp), %xmm0
movaps 0x501f2(%rip), %xmm1    # 0xbd220
pand %xmm1, %xmm0
movsd 0x50d66(%rip), %xmm1    # 0xbdda0
ucomisd %xmm1, %xmm0
jbe 0x6d059
movq -0x10(%rbp), %rax
movl $0x0, 0x9bdd0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl -0x58(%rbp), %edx
movq -0xd0(%rbp), %rsi
movsd -0xc8(%rbp), %xmm0
callq 0x6d9f0
movl %eax, -0x40(%rbp)
cmpl $0x0, %eax
jl 0x6d1aa
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x50d0a(%rip), %xmm1    # 0xbddc8
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movslq -0x44(%rbp), %rcx
movsd %xmm0, 0x20(%rax,%rcx,8)
movq -0x10(%rbp), %rax
addq $0x9d002, %rax          # imm = 0x9D002
movl -0x58(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movslq -0x44(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
cmpl -0x5c(%rbp), %eax
setne %dl
andb $0x1, %dl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movslq -0x44(%rbp), %rcx
movb %dl, 0x15(%rax,%rcx)
cmpl $0x0, -0x44(%rbp)
jne 0x6d146
movl -0x4c(%rbp), %edx
movl $0x1, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0xd8(%rbp)
jmp 0x6d15f
movl -0x4c(%rbp), %edx
movl $0xe, %eax
movl $0x13, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movslq -0x44(%rbp), %rcx
movb %dl, 0x18(%rax,%rcx)
movl -0x5c(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
addq $0x9d002, %rax          # imm = 0x9D002
movl -0x58(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movslq -0x44(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
jmp 0x6cdb2
cmpl $0x0, -0x48(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x9bdd0(%rax)
movl -0x48(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)