// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr1(bamboo::rtcm_t*, int, int)
static int encode_ssr1(rtcm_t *rtcm, int sys, int sync)
{
    double udint=0.0;
    int i,j,iod=0,nsat,prn,iode,iodcrc,refd=0,np,ni,nj,offp,deph[3],ddeph[3];
    
    trace(3,"encode_ssr1: sys=%d sync=%d\n",sys,sync);
    
    switch (sys) {
        case SYS_GPS: np=6; ni= 8; nj= 0; offp=  0; break;
        case SYS_GLO: np=5; ni= 8; nj= 0; offp=  0; break;
        case SYS_GAL: np=6; ni=10; nj= 0; offp=  0; break;
        case SYS_QZS: np=4; ni= 8; nj= 0; offp=192; break;
        case SYS_CMP: np=6; ni=10; nj=24; offp=  1; break;
        case SYS_SBS: np=6; ni= 9; nj=24; offp=120; break;
        default: return 0;
    }
    /* number of satellites */
    for (j=nsat=0;j<MAXRTKSAT;j++) {
        if (satsys(j+1,&prn)!=sys||!rtcm->ssr[j].update) continue;
        nsat++;
        udint=rtcm->ssr[j].udi[0];
        iod  =rtcm->ssr[j].iod[0];
        refd =rtcm->ssr[j].refd;
    }
    /* encode ssr header */
    i=encode_ssr_head(1,rtcm,sys,nsat,sync,iod,udint,refd,0,0);
    
    for (j=0;j<MAXRTKSAT;j++) {
        if (satsys(j+1,&prn)!=sys||!rtcm->ssr[j].update) continue;
        
        iode=rtcm->ssr[j].iode;      /* sbas/bds: toe/t0 modulo */
        iodcrc=rtcm->ssr[j].iodcrc;  /* sbas/bds: iod crc */
        
        deph [0]=ROUND(rtcm->ssr[j].deph [0]/1E-4);
        deph [1]=ROUND(rtcm->ssr[j].deph [1]/4E-4);
        deph [2]=ROUND(rtcm->ssr[j].deph [2]/4E-4);
        ddeph[0]=ROUND(rtcm->ssr[j].ddeph[0]/1E-6);
        ddeph[1]=ROUND(rtcm->ssr[j].ddeph[1]/4E-6);
        ddeph[2]=ROUND(rtcm->ssr[j].ddeph[2]/4E-6);
        
        setbitu(rtcm->buff,i,np,prn-offp); i+=np; /* satellite id */
        setbitu(rtcm->buff,i,ni,iode    ); i+=ni; /* iode */
        setbitu(rtcm->buff,i,nj,iodcrc  ); i+=nj; /* iodcrc */
        setbits(rtcm->buff,i,22,deph [0]); i+=22; /* delta radial */
        setbits(rtcm->buff,i,20,deph [1]); i+=20; /* delta along-track */
        setbits(rtcm->buff,i,20,deph [2]); i+=20; /* delta cross-track */
        setbits(rtcm->buff,i,21,ddeph[0]); i+=21; /* dot delta radial */
        setbits(rtcm->buff,i,19,ddeph[1]); i+=19; /* dot delta along-track */
        setbits(rtcm->buff,i,19,ddeph[2]); i+=19; /* dot delta cross-track */
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
leaq 0x3dffe(%rip), %rsi     # 0xc27e6
xorl %eax, %eax
movl $0x3, %edi
callq 0x8b980
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x70(%rbp)
subl $0x1f, %eax
ja 0x848d6
movq -0x70(%rbp), %rax
leaq 0x3d69d(%rip), %rcx     # 0xc1eb0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, -0x44(%rbp)
movl $0x8, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
jmp 0x848e2
movl $0x5, -0x44(%rbp)
movl $0x8, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
jmp 0x848e2
movl $0x6, -0x44(%rbp)
movl $0xa, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
jmp 0x848e2
movl $0x4, -0x44(%rbp)
movl $0x8, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0xc0, -0x50(%rbp)
jmp 0x848e2
movl $0x6, -0x44(%rbp)
movl $0xa, -0x48(%rbp)
movl $0x18, -0x4c(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x848e2
movl $0x6, -0x44(%rbp)
movl $0x9, -0x48(%rbp)
movl $0x18, -0x4c(%rbp)
movl $0x78, -0x50(%rbp)
jmp 0x848e2
movl $0x0, -0x4(%rbp)
jmp 0x84d77
movl $0x0, -0x30(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x9b, -0x28(%rbp)
jge 0x849af
movl -0x28(%rbp), %edi
addl $0x1, %edi
leaq -0x34(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x84932
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
cmpb $0x0, 0x490(%rax)
jne 0x84934
jmp 0x849a1
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movl 0x90(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movl 0xb4(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x848f0
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x2c(%rbp), %r9d
movsd -0x20(%rbp), %xmm0
movl -0x40(%rbp), %eax
movl $0x1, %edi
xorl %r10d, %r10d
movl %eax, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x885f0
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x9b, -0x28(%rbp)
jge 0x84d63
movl -0x28(%rbp), %edi
addl $0x1, %edi
leaq -0x34(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x84a35
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
cmpb $0x0, 0x490(%rax)
jne 0x84a3a
jmp 0x84d55
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movl 0xa8(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movl 0xac(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0xb8(%rax), %xmm0
movsd 0x383c4(%rip), %xmm1    # 0xbce68
divsd %xmm1, %xmm0
movsd 0x383d0(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0xc0(%rax), %xmm0
movsd 0x3bf30(%rip), %xmm1    # 0xc0a18
divsd %xmm1, %xmm0
movsd 0x3838c(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0xc8(%rax), %xmm0
movsd 0x3beec(%rip), %xmm1    # 0xc0a18
divsd %xmm1, %xmm0
movsd 0x38348(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0xd0(%rax), %xmm0
movsd 0x3a260(%rip), %xmm1    # 0xbedd0
divsd %xmm1, %xmm0
movsd 0x38304(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0xd8(%rax), %xmm0
movsd 0x3be5c(%rip), %xmm1    # 0xc0a10
divsd %xmm1, %xmm0
movsd 0x382c0(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0xe0(%rax), %xmm0
movsd 0x3be18(%rip), %xmm1    # 0xc0a10
divsd %xmm1, %xmm0
movsd 0x3827c(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x44(%rbp), %edx
movl -0x34(%rbp), %ecx
subl -0x50(%rbp), %ecx
callq 0x8c0d0
movl -0x44(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x48(%rbp), %edx
movl -0x38(%rbp), %ecx
callq 0x8c0d0
movl -0x48(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x4c(%rbp), %edx
movl -0x3c(%rbp), %ecx
callq 0x8c0d0
movl -0x4c(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x5c(%rbp), %ecx
movl $0x16, %edx
callq 0x8c1d0
movl -0x24(%rbp), %eax
addl $0x16, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x58(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x24(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x54(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x24(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x68(%rbp), %ecx
movl $0x15, %edx
callq 0x8c1d0
movl -0x24(%rbp), %eax
addl $0x15, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x64(%rbp), %ecx
movl $0x13, %edx
callq 0x8c1d0
movl -0x24(%rbp), %eax
addl $0x13, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x60(%rbp), %ecx
movl $0x13, %edx
callq 0x8c1d0
movl -0x24(%rbp), %eax
addl $0x13, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x849f3
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)