// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3.cpp
// Function: bamboo::decode_type1004(bamboo::rtcm_t*)
static int decode_type1004(rtcm_t *rtcm)
{
    const int L2codes[]={CODE_L2X,CODE_L2P,CODE_L2D,CODE_L2W};
    double pr1,cnr1,cnr2,tt,cp1,cp2;
    int i=24+64,j,index,nsat,sync,prn,sat,code1,code2,pr21,ppr1,ppr2;
    int lock1,lock2,amb,sys;
    
    if ((nsat=decode_head1001(rtcm,&sync))<0) return -1;
    
    for (j=0;j<nsat&&rtcm->obs.n<MAXOBS&&i+125<=rtcm->len*8;j++) {
        prn  =getbitu(rtcm->buff,i, 6); i+= 6;
        code1=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;
        code2=getbitu(rtcm->buff,i, 2); i+= 2;
        pr21 =getbits(rtcm->buff,i,14); i+=14;
        ppr2 =getbits(rtcm->buff,i,20); i+=20;
        lock2=getbitu(rtcm->buff,i, 7); i+= 7;
        cnr2 =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 1004 satellite number error: sys=%d prn=%d\n",sys,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]=code1?CODE_L1P:CODE_L1C;
        
        if (pr21!=(int)0xFFFFE000) {
            rtcm->obs.data[index].P[1]=pr1+pr21*0.02;
        }
        if (ppr2!=(int)0xFFF80000) {
            cp2=adjcp(rtcm,sat,1,ppr2*0.0005/lam_carr[1]);
            rtcm->obs.data[index].L[1]=pr1/lam_carr[1]+cp2;
        }
        rtcm->obs.data[index].LLI[1]=lossoflock(rtcm,sat,1,lock2);
        rtcm->obs.data[index].SNR[1]=snratio(cnr2*0.25);
        rtcm->obs.data[index].code[1]=L2codes[code2];
    }
    rtcm->obsflag=!sync;
    return sync?0:1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq 0x5175a(%rip), %rax     # 0xc0a80
movq %rax, -0x20(%rbp)
movq 0x51757(%rip), %rax     # 0xc0a88
movq %rax, -0x18(%rbp)
movl $0x58, -0x54(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x79d10
movl %eax, -0x60(%rbp)
cmpl $0x0, %eax
jge 0x6f35d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6f969
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %ecx
xorl %eax, %eax
cmpl -0x60(%rbp), %ecx
movb %al, -0xc1(%rbp)
jge 0x6f3a4
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x40, 0x30(%rcx)
movb %al, -0xc1(%rbp)
jge 0x6f3a4
movl -0x54(%rbp), %eax
addl $0x7d, %eax
movq -0x10(%rbp), %rcx
movl 0x9f0c0(%rcx), %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
setle %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x6f3b3
jmp 0x6f93e
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0x6, %edx
callq 0x8bfc0
movl %eax, -0x68(%rbp)
movl -0x54(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0x1, %edx
callq 0x8bfc0
movl %eax, -0x70(%rbp)
movl -0x54(%rbp), %eax
incl %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0x18, %edx
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x54(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0x14, %edx
movl %edx, -0xd0(%rbp)
callq 0x8c050
movl %eax, -0x7c(%rbp)
movl -0x54(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0x7, %edx
movl %edx, -0xcc(%rbp)
callq 0x8bfc0
movl %eax, -0x84(%rbp)
movl -0x54(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0x8, %edx
movl %edx, -0xc8(%rbp)
callq 0x8bfc0
movl -0xc8(%rbp), %edx
movl %eax, -0x8c(%rbp)
movl -0x54(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x54(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0x2, %edx
callq 0x8bfc0
movl %eax, -0x74(%rbp)
movl -0x54(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
movl $0xe, %edx
callq 0x8c050
movl -0xd0(%rbp), %edx
movl %eax, -0x78(%rbp)
movl -0x54(%rbp), %eax
addl $0xe, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
callq 0x8c050
movl -0xcc(%rbp), %edx
movl %eax, -0x80(%rbp)
movl -0x54(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
callq 0x8bfc0
movl -0xc8(%rbp), %edx
movl %eax, -0x88(%rbp)
movl -0x54(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x54(%rbp), %esi
callq 0x8bfc0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x54(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x54(%rbp)
cmpl $0x28, -0x68(%rbp)
jge 0x6f5ae
movl $0x1, -0x90(%rbp)
jmp 0x6f5c1
movl $0x2, -0x90(%rbp)
movl -0x68(%rbp), %eax
addl $0x50, %eax
movl %eax, -0x68(%rbp)
movl -0x90(%rbp), %edi
movl -0x68(%rbp), %esi
callq 0x8b1b0
movl %eax, -0x6c(%rbp)
cmpl $0x0, %eax
jne 0x6f5f8
movl -0x90(%rbp), %edx
movl -0x68(%rbp), %ecx
movl $0x2, %edi
leaq 0x51c42(%rip), %rsi     # 0xc122e
movb $0x0, %al
callq 0x8b980
jmp 0x6f930
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rcx
movq %rcx, -0xa0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0xb0(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
movsd -0x98(%rbp), %xmm0
movq -0xb0(%rbp), %rsi
movsd -0xa8(%rbp), %xmm1
callq 0x8e8e0
movsd %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x9bdd0(%rax)
jne 0x6f682
movsd -0x40(%rbp), %xmm0
movaps 0x4dbb0(%rip), %xmm1    # 0xbd220
pand %xmm1, %xmm0
movsd 0x4e724(%rip), %xmm1    # 0xbdda0
ucomisd %xmm1, %xmm0
jbe 0x6f69b
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, -0xc0(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0xb8(%rbp)
movl -0x6c(%rbp), %edx
movq -0xc0(%rbp), %rsi
movsd -0xb8(%rbp), %xmm0
callq 0x7a130
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
jge 0x6f6e1
jmp 0x6f930
movsd -0x28(%rbp), %xmm0
cvtsi2sdl -0x8c(%rbp), %xmm1
movsd 0x512ea(%rip), %xmm2    # 0xc09e0
mulsd %xmm2, %xmm1
movsd 0x4e686(%rip), %xmm2    # 0xbdd88
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
cmpl $0xfff80000, -0x7c(%rbp) # imm = 0xFFF80000
je 0x6f791
movsd -0x28(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %esi
cvtsi2sdl -0x7c(%rbp), %xmm0
movsd 0x5129f(%rip), %xmm1    # 0xc09e8
mulsd %xmm1, %xmm0
leaq 0x5383c(%rip), %rax     # 0xc2f90
divsd (%rax), %xmm0
xorl %edx, %edx
callq 0x7a2d0
movsd %xmm0, -0x48(%rbp)
movsd -0x28(%rbp), %xmm0
leaq 0x53820(%rip), %rax     # 0xc2f90
divsd (%rax), %xmm0
addsd -0x48(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %esi
movl -0x84(%rbp), %ecx
xorl %edx, %edx
callq 0x7a3f0
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x15(%rax)
movsd 0x4d783(%rip), %xmm0    # 0xbcf48
mulsd -0x30(%rbp), %xmm0
callq 0x7a4a0
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x12(%rax)
movl -0x70(%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 -0x5c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x18(%rax)
cmpl $0xffffe000, -0x78(%rbp) # imm = 0xFFFFE000
je 0x6f84d
movsd -0x28(%rbp), %xmm1
cvtsi2sdl -0x78(%rbp), %xmm0
movsd 0x4e55b(%rip), %xmm2    # 0xbdd88
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x40(%rax)
cmpl $0xfff80000, -0x80(%rbp) # imm = 0xFFF80000
je 0x6f8b7
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %esi
cvtsi2sdl -0x80(%rbp), %xmm0
movsd 0x5117e(%rip), %xmm1    # 0xc09e8
mulsd %xmm1, %xmm0
leaq 0x5371b(%rip), %rax     # 0xc2f90
divsd 0x8(%rax), %xmm0
movl $0x1, %edx
callq 0x7a2d0
movsd %xmm0, -0x50(%rbp)
movsd -0x28(%rbp), %xmm0
leaq 0x536fb(%rip), %rax     # 0xc2f90
divsd 0x8(%rax), %xmm0
addsd -0x50(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x28(%rax)
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %esi
movl -0x88(%rbp), %ecx
movl $0x1, %edx
callq 0x7a3f0
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x16(%rax)
movsd 0x4d65a(%rip), %xmm0    # 0xbcf48
mulsd -0x38(%rbp), %xmm0
callq 0x7a4a0
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x13(%rax)
movslq -0x74(%rbp), %rax
movl -0x20(%rbp,%rax,4), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x5c(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x19(%rax)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x6f364
cmpl $0x0, -0x64(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x9bdd0(%rax)
movl -0x64(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)