// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr3(bamboo::rtcm_t*, int, int)
static int encode_ssr3(rtcm_t *rtcm, int sys, int sync)
{
    const int *codes;
    double udint=0.0;
    int i,j,k,iod=0,nsat,prn,nbias,np,offp,ncode;
    int code[MAXCODE],bias[MAXCODE];
    
    trace(3,"encode_ssr3: sys=%d sync=%d\n",sys,sync);
    
    switch (sys) {
        case SYS_GPS: np=6; offp=  0; codes=codes_gps; ncode=17; break;
        case SYS_GLO: np=5; offp=  0; codes=codes_glo; ncode= 4; break;
        case SYS_GAL: np=6; offp=  0; codes=codes_gal; ncode=19; break;
        case SYS_QZS: np=4; offp=192; codes=codes_qzs; ncode=13; break;
        case SYS_CMP: np=6; offp=  1; codes=codes_bds; ncode= 9; break;
        case SYS_SBS: np=6; offp=120; codes=codes_sbs; ncode= 4; 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[4];
        iod  =rtcm->ssr[j].iod[4];
    }
    /* encode ssr header */
    i=encode_ssr_head(3,rtcm,sys,nsat,sync,iod,udint,0,0,0);
    
    for (j=nsat=0;j<MAXRTKSAT;j++) {
        if (satsys(j+1,&prn)!=sys||!rtcm->ssr[j].update) continue;
        
        for (k=nbias=0;k<ncode;k++) {
            if (rtcm->ssr[j].cbias[codes[k]-1]==0.0) continue;
            code[nbias]=k;
            bias[nbias++]=ROUND(rtcm->ssr[j].cbias[codes[k]-1]/0.01);
        }
        setbitu(rtcm->buff,i,np,prn-offp); i+=np; /* satellite id */
        setbitu(rtcm->buff,i, 5,nbias);    i+= 5; /* number of code biases */
        
        for (k=0;k<nbias;k++) {
            setbitu(rtcm->buff,i, 5,code[k]); i+= 5; /* signal indicator */
            setbits(rtcm->buff,i,14,bias[k]); i+=14; /* code bias */
        }
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
leaq 0x3d6f2(%rip), %rsi     # 0xc2863
xorl %eax, %eax
movl $0x3, %edi
callq 0x8b980
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x218(%rbp)
subl $0x1f, %eax
ja 0x8527d
movq -0x218(%rbp), %rax
leaq 0x3ce0e(%rip), %rcx     # 0xc1fb0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq 0x3d2a0(%rip), %rax     # 0xc2460
movq %rax, -0x20(%rbp)
movl $0x11, -0x50(%rbp)
jmp 0x85289
movl $0x5, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq 0x3d2cb(%rip), %rax     # 0xc24b0
movq %rax, -0x20(%rbp)
movl $0x4, -0x50(%rbp)
jmp 0x85289
movl $0x6, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq 0x3d2b6(%rip), %rax     # 0xc24c0
movq %rax, -0x20(%rbp)
movl $0x13, -0x50(%rbp)
jmp 0x85289
movl $0x4, -0x48(%rbp)
movl $0xc0, -0x4c(%rbp)
leaq 0x3d2e4(%rip), %rax     # 0xc2510
movq %rax, -0x20(%rbp)
movl $0xd, -0x50(%rbp)
jmp 0x85289
movl $0x6, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
leaq 0x3d302(%rip), %rax     # 0xc2550
movq %rax, -0x20(%rbp)
movl $0x9, -0x50(%rbp)
jmp 0x85289
movl $0x6, -0x48(%rbp)
movl $0x78, -0x4c(%rbp)
leaq 0x3d310(%rip), %rax     # 0xc2580
movq %rax, -0x20(%rbp)
movl $0x4, -0x50(%rbp)
jmp 0x85289
movl $0x0, -0x4(%rbp)
jmp 0x8558d
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x9b, -0x30(%rbp)
jge 0x85338
movl -0x30(%rbp), %edi
addl $0x1, %edi
leaq -0x40(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x852d9
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
cmpb $0x0, 0x490(%rax)
jne 0x852db
jmp 0x8532a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0x80(%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movl 0xa0(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x85297
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x38(%rbp), %r9d
movsd -0x28(%rbp), %xmm0
movl $0x3, %edi
xorl %eax, %eax
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x885f0
movl %eax, -0x2c(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x9b, -0x30(%rbp)
jge 0x85579
movl -0x30(%rbp), %edi
addl $0x1, %edi
leaq -0x40(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x853c5
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
cmpb $0x0, 0x490(%rax)
jne 0x853ca
jmp 0x8556b
movl $0x0, -0x44(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x854ae
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss 0x108(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x85427
jp 0x85427
jmp 0x854a0
movl -0x34(%rbp), %ecx
movslq -0x44(%rbp), %rax
movl %ecx, -0x130(%rbp,%rax,4)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss 0x108(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x38315(%rip), %xmm1    # 0xbd788
divsd %xmm1, %xmm0
movsd 0x37a01(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %ecx
movl -0x44(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x44(%rbp)
cltq
movl %ecx, -0x210(%rbp,%rax,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x853d8
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x48(%rbp), %edx
movl -0x40(%rbp), %ecx
subl -0x4c(%rbp), %ecx
callq 0x8c0d0
movl -0x48(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x44(%rbp), %ecx
movl $0x5, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x85569
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movslq -0x34(%rbp), %rax
movl -0x130(%rbp,%rax,4), %ecx
movl $0x5, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movslq -0x34(%rbp), %rax
movl -0x210(%rbp,%rax,4), %ecx
movl $0xe, %edx
callq 0x8c1d0
movl -0x2c(%rbp), %eax
addl $0xe, %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x854fe
jmp 0x8556b
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x85383
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
nopl (%rax)