// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr7(bamboo::rtcm_t*, int, int)
static int encode_ssr7(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],pbias[MAXCODE],stdpb[MAXCODE],yaw_ang,yaw_rate;
    
    trace(3,"encode_ssr7: 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;
        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[5];
        iod  =rtcm->ssr[j].iod[5];
    }
    /* encode ssr header */
    i=encode_ssr_head(7,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].pbias[codes[k]-1]==0.0) continue;
            code[nbias]=k;
            pbias[nbias  ]=ROUND(rtcm->ssr[j].pbias[codes[k]-1]/0.0001);
            stdpb[nbias++]=ROUND(rtcm->ssr[j].stdpb[codes[k]-1]/0.0001);
        }
        yaw_ang =ROUND(rtcm->ssr[j].yaw_ang /180.0* 256.0);
        yaw_rate=ROUND(rtcm->ssr[j].yaw_rate/180.0*8192.0);
        setbitu(rtcm->buff,i,np,prn-offp); i+=np; /* satellite id */
        setbitu(rtcm->buff,i, 5,nbias);    i+= 5; /* number of code biases */
        setbitu(rtcm->buff,i, 9,yaw_ang);  i+= 9; /* yaw angle */
        setbits(rtcm->buff,i, 8,yaw_rate); i+= 8; /* yaw rate */
        
        for (k=0;k<nbias;k++) {
            setbitu(rtcm->buff,i, 5,code[k] ); i+= 5; /* signal indicator */
            setbitu(rtcm->buff,i, 1,0       ); i+= 1; /* integer-indicator */
            setbitu(rtcm->buff,i, 2,0       ); i+= 2; /* WL integer-indicator */
            setbitu(rtcm->buff,i, 4,0       ); i+= 4; /* discont counter */
            setbits(rtcm->buff,i,20,pbias[k]); i+=20; /* phase bias */
            setbits(rtcm->buff,i,17,stdpb[k]); i+=17; /* std-dev phase bias */
        }
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
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 0x3bb68(%rip), %rsi     # 0xc2ae9
xorl %eax, %eax
movl $0x3, %edi
callq 0x8b980
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x300(%rbp)
subl $0x1f, %eax
ja 0x87068
movq -0x300(%rbp), %rax
leaq 0x3b1fe(%rip), %rcx     # 0xc21b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq 0x3b490(%rip), %rax     # 0xc2460
movq %rax, -0x20(%rbp)
movl $0x11, -0x50(%rbp)
jmp 0x87074
movl $0x5, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq 0x3b4bb(%rip), %rax     # 0xc24b0
movq %rax, -0x20(%rbp)
movl $0x4, -0x50(%rbp)
jmp 0x87074
movl $0x6, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq 0x3b4a9(%rip), %rax     # 0xc24c0
movq %rax, -0x20(%rbp)
movl $0x13, -0x50(%rbp)
jmp 0x87074
movl $0x4, -0x48(%rbp)
movl $0xc0, -0x4c(%rbp)
leaq 0x3b4d7(%rip), %rax     # 0xc2510
movq %rax, -0x20(%rbp)
movl $0xd, -0x50(%rbp)
jmp 0x87074
movl $0x6, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
leaq 0x3b4f5(%rip), %rax     # 0xc2550
movq %rax, -0x20(%rbp)
movl $0x9, -0x50(%rbp)
jmp 0x87074
movl $0x0, -0x4(%rbp)
jmp 0x87565
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x9b, -0x30(%rbp)
jge 0x87123
movl -0x30(%rbp), %edi
addl $0x1, %edi
leaq -0x40(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x870c4
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 0x870c6
jmp 0x87115
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 0x88(%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 0xa4(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x87082
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 $0x7, %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 0x87551
movl -0x30(%rbp), %edi
addl $0x1, %edi
leaq -0x40(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x871b0
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 0x871b5
jmp 0x87543
movl $0x0, -0x44(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x872f6
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
movsd 0x1e8(%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x87211
jp 0x87211
jmp 0x872e8
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
movsd 0x1e8(%rax,%rcx,8), %xmm0
movsd 0x35c0f(%rip), %xmm1    # 0xbce68
divsd %xmm1, %xmm0
movsd 0x35c1b(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %ecx
movslq -0x44(%rbp), %rax
movl %ecx, -0x210(%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 0x3a0(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x35bad(%rip), %xmm1    # 0xbce68
divsd %xmm1, %xmm0
movsd 0x35bb9(%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, -0x2f0(%rbp,%rax,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x871c3
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0x480(%rax), %xmm0
movsd 0x39722(%rip), %xmm1    # 0xc0a40
divsd %xmm1, %xmm0
movsd 0x36a9e(%rip), %xmm1    # 0xbddc8
mulsd %xmm1, %xmm0
movsd 0x35b4a(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x2f4(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x30(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0x488(%rax), %xmm0
movsd 0x396cf(%rip), %xmm1    # 0xc0a40
divsd %xmm1, %xmm0
movsd 0x396cb(%rip), %xmm1    # 0xc0a48
mulsd %xmm1, %xmm0
movsd 0x35af7(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x2f8(%rbp)
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)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x2f4(%rbp), %ecx
movl $0x9, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x2f8(%rbp), %ecx
movl $0x8, %edx
callq 0x8c1d0
movl -0x2c(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x87541
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
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x4, %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 $0x14, %edx
callq 0x8c1d0
movl -0x2c(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movslq -0x34(%rbp), %rax
movl -0x2f0(%rbp,%rax,4), %ecx
movl $0x11, %edx
callq 0x8c1d0
movl -0x2c(%rbp), %eax
addl $0x11, %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x8743a
jmp 0x87543
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x8716e
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
nopw %cs:(%rax,%rax)