// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3.cpp
// Function: bamboo::decode_type1002(bamboo::rtcm_t*)
static int decode_type1002(rtcm_t *rtcm)
{
    double pr1,cnr1,tt,cp1;
    int i=24+64,j,index,nsat,sync,prn,code,sat,ppr1,lock1,amb,sys;
    
    if ((nsat=decode_head1001(rtcm,&sync))<0) return -1;
    
    for (j=0;j<nsat&&rtcm->obs.n<MAXOBS&&i+74<=rtcm->len*8;j++) {
        prn  =getbitu(rtcm->buff,i, 6); i+= 6;
        code =getbitu(rtcm->buff,i, 1); i+= 1;
        pr1  =getbitu(rtcm->buff,i,24); i+=24;
        ppr1 =getbits(rtcm->buff,i,20); i+=20;
        lock1=getbitu(rtcm->buff,i, 7); i+= 7;
        amb  =getbitu(rtcm->buff,i, 8); i+= 8;
        cnr1 =getbitu(rtcm->buff,i, 8); i+= 8;
        if (prn<40) {
            sys=SYS_GPS;
        }
        else {
            sys=SYS_SBS; prn+=80;
        }
        if (!(sat=satno(sys,prn))) {
            trace(2,"rtcm3 1002 satellite number error: prn=%d\n",prn);
            continue;
        }
        tt=timediff(rtcm->obs.data[0].time,rtcm->time);
        if (rtcm->obsflag||fabs(tt)>1E-9) {
            rtcm->obs.n=rtcm->obsflag=0;
        }
        if ((index=obsindex(&rtcm->obs,rtcm->time,sat))<0) continue;
        pr1=pr1*0.02+amb*PRUNIT_GPS;
        if (ppr1!=(int)0xFFF80000) {
            rtcm->obs.data[index].P[0]=pr1;
            cp1=adjcp(rtcm,sat,0,ppr1*0.0005/lam_carr[0]);
            rtcm->obs.data[index].L[0]=pr1/lam_carr[0]+cp1;
        }
        rtcm->obs.data[index].LLI[0]=lossoflock(rtcm,sat,0,lock1);
        rtcm->obs.data[index].SNR[0]=snratio(cnr1*0.25);
        rtcm->obs.data[index].code[0]=code?CODE_L1P:CODE_L1C;
    }
    return sync?0:1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movl $0x58, -0x34(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x79d10
movl %eax, -0x40(%rbp)
cmpl $0x0, %eax
jge 0x6eec7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6f29b
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x40(%rbp), %ecx
movb %al, -0x91(%rbp)
jge 0x6ef0e
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x40, 0x30(%rcx)
movb %al, -0x91(%rbp)
jge 0x6ef0e
movl -0x34(%rbp), %eax
addl $0x4a, %eax
movq -0x10(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
setle %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x6ef1d
jmp 0x6f288
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x6, %edx
callq 0x8bfc0
movl %eax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x4c(%rbp)
movl -0x34(%rbp), %eax
incl %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x18, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x34(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x14, %edx
callq 0x8c050
movl %eax, -0x54(%rbp)
movl -0x34(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x7, %edx
callq 0x8bfc0
movl %eax, -0x58(%rbp)
movl -0x34(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x8, %edx
movl %edx, -0x98(%rbp)
callq 0x8bfc0
movl -0x98(%rbp), %edx
movl %eax, -0x5c(%rbp)
movl -0x34(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x20(%rbp)
movl -0x34(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x34(%rbp)
cmpl $0x28, -0x48(%rbp)
jge 0x6f040
movl $0x1, -0x60(%rbp)
jmp 0x6f050
movl $0x2, -0x60(%rbp)
movl -0x48(%rbp), %eax
addl $0x50, %eax
movl %eax, -0x48(%rbp)
movl -0x60(%rbp), %edi
movl -0x48(%rbp), %esi
callq 0x8b1b0
movl %eax, -0x50(%rbp)
cmpl $0x0, %eax
jne 0x6f07e
movl -0x48(%rbp), %edx
movl $0x2, %edi
leaq 0x52191(%rip), %rsi     # 0xc1203
movb $0x0, %al
callq 0x8b980
jmp 0x6f27a
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x80(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movq -0x80(%rbp), %rsi
movsd -0x78(%rbp), %xmm1
callq 0x8e8e0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x9bdd0(%rax)
jne 0x6f0f0
movsd -0x28(%rbp), %xmm0
movaps 0x4e142(%rip), %xmm1    # 0xbd220
pand %xmm1, %xmm0
movsd 0x4ecb6(%rip), %xmm1    # 0xbdda0
ucomisd %xmm1, %xmm0
jbe 0x6f109
movq -0x10(%rbp), %rax
movl $0x0, 0x9bdd0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x90(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x50(%rbp), %edx
movq -0x90(%rbp), %rsi
movsd -0x88(%rbp), %xmm0
callq 0x7a130
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jge 0x6f14f
jmp 0x6f27a
movsd -0x18(%rbp), %xmm0
cvtsi2sdl -0x5c(%rbp), %xmm1
movsd 0x5187f(%rip), %xmm2    # 0xc09e0
mulsd %xmm2, %xmm1
movsd 0x4ec1b(%rip), %xmm2    # 0xbdd88
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
cmpl $0xfff80000, -0x54(%rbp) # imm = 0xFFF80000
je 0x6f1fc
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
cvtsi2sdl -0x54(%rbp), %xmm0
movsd 0x51834(%rip), %xmm1    # 0xc09e8
mulsd %xmm1, %xmm0
leaq 0x53dd1(%rip), %rax     # 0xc2f90
divsd (%rax), %xmm0
xorl %edx, %edx
callq 0x7a2d0
movsd %xmm0, -0x30(%rbp)
movsd -0x18(%rbp), %xmm0
leaq 0x53db5(%rip), %rax     # 0xc2f90
divsd (%rax), %xmm0
addsd -0x30(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
movl -0x58(%rbp), %ecx
xorl %edx, %edx
callq 0x7a3f0
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x15(%rax)
movsd 0x4dd1b(%rip), %xmm0    # 0xbcf48
mulsd -0x20(%rbp), %xmm0
callq 0x7a4a0
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x12(%rax)
movl -0x4c(%rbp), %edx
movl $0x1, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x18(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6eece
movl -0x44(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)