// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr4(bamboo::rtcm_t*, int, int)
static int encode_ssr4(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;
    int deph[3],ddeph[3],dclk[3];
    
    trace(3,"encode_ssr4: 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(4,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;
        iodcrc=rtcm->ssr[j].iodcrc;
        
        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);
        dclk [0]=ROUND(rtcm->ssr[j].dclk [0]/1E-4);
        dclk [1]=ROUND(rtcm->ssr[j].dclk [1]/1E-6);
        dclk [2]=ROUND(rtcm->ssr[j].dclk [2]/1E-8);
        
        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 raidal */
        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 */
        setbits(rtcm->buff,i,22,dclk [0]); i+=22; /* delta clock c0 */
        setbits(rtcm->buff,i,21,dclk [1]); i+=21; /* delta clock c1 */
        setbits(rtcm->buff,i,27,dclk [2]); i+=27; /* delta clock c2 */
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %r12d
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x24d46(%rip), %rsi     # 0x66570
xorl %r15d, %r15d
pushq $0x3
popq %rdi
movl %r14d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x455bc
pushq $0x6
popq %rdx
pushq $0x8
popq %rsi
leal -0x1(%r14), %eax
cmpl $0x7, %eax
ja 0x41870
leaq 0x24799(%rip), %rcx     # 0x65fec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r12d, -0x44(%rbp)
jmpq *%rax
movl %esi, -0x2c(%rbp)
movl %edx, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
jmp 0x418cd
cmpl $0x10, %r14d
je 0x418d6
cmpl $0x20, %r14d
jne 0x41c82
movl %r12d, -0x44(%rbp)
movl %edx, -0x40(%rbp)
pushq $0xa
popq %rax
movl %eax, -0x2c(%rbp)
pushq $-0x1
jmp 0x418af
movl %edx, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
pushq $0xa
popq %rax
movl %eax, -0x2c(%rbp)
jmp 0x418cd
movl %edx, -0x40(%rbp)
pushq $0x9
popq %rax
movl %eax, -0x2c(%rbp)
pushq $-0x78
popq %rax
movl %eax, -0x3c(%rbp)
pushq $0x18
popq %rax
movq %rax, -0x58(%rbp)
jmp 0x418f2
movl %esi, -0x2c(%rbp)
movq $0x0, -0x58(%rbp)
pushq $0x5
popq %rax
movl %eax, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
jmp 0x418f2
movl %r12d, -0x44(%rbp)
movl %esi, -0x2c(%rbp)
movq $0x0, -0x58(%rbp)
pushq $0x4
popq %rax
movl %eax, -0x40(%rbp)
movl $0xffffff40, -0x3c(%rbp) # imm = 0xFFFFFF40
movq %rbx, -0x80(%rbp)
leaq 0x6f1a8(%rbx), %r15
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorl %r13d, %r13d
leaq -0x5c(%rbp), %rbx
movl $0x0, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
imulq $0x498, %r13, %r12      # imm = 0x498
incq %r13
addq %r15, %r12
cmpq $0x9c, %r13
je 0x4197e
movl %r13d, %edi
movq %rbx, %rsi
callq 0x45362
cmpl %r14d, %eax
jne 0x41952
cmpb $0x0, 0x430(%r12)
jne 0x4195e
incq %r13
addq $0x498, %r12            # imm = 0x498
jmp 0x4192e
incl -0x50(%rbp)
movsd (%r12), %xmm0
movsd %xmm0, -0x38(%rbp)
movl 0x30(%r12), %eax
movl %eax, -0x4c(%rbp)
movl 0x54(%r12), %eax
movl %eax, -0x48(%rbp)
jmp 0x41921
movl -0x48(%rbp), %eax
movl %eax, (%rsp)
pushq $0x4
popq %rdi
movq -0x80(%rbp), %rbx
movq %rbx, %rsi
movl %r14d, %edx
movl -0x50(%rbp), %ecx
movl -0x44(%rbp), %r8d
movl -0x4c(%rbp), %r9d
movsd -0x38(%rbp), %xmm0
callq 0x437dc
movl %eax, %r12d
leaq 0x9f0c4(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x6f1f0(%rbx), %r15
xorl %ebx, %ebx
imulq $0x498, %rbx, %r13      # imm = 0x498
incq %rbx
addq %r15, %r13
cmpq $0x9c, %rbx
je 0x41c73
movl %ebx, %edi
leaq -0x5c(%rbp), %rsi
callq 0x45362
cmpl %r14d, %eax
jne 0x419f1
cmpb $0x0, 0x3e8(%r13)
jne 0x419fd
incq %rbx
addq $0x498, %r13            # imm = 0x498
jmp 0x419ca
movl (%r13), %eax
movl %eax, -0x78(%rbp)
movl 0x4(%r13), %eax
movl %eax, -0x50(%rbp)
movsd 0x10(%r13), %xmm0
movsd 0x1eef7(%rip), %xmm1    # 0x60910
divsd %xmm1, %xmm0
movsd 0x20253(%rip), %xmm1    # 0x61c78
addsd %xmm1, %xmm0
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x4c(%rbp)
movsd 0x18(%r13), %xmm0
movsd 0x22ccd(%rip), %xmm1    # 0x64710
divsd %xmm1, %xmm0
addsd 0x20229(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x48(%rbp)
movsd 0x20(%r13), %xmm0
divsd 0x22ca7(%rip), %xmm0    # 0x64710
addsd 0x20207(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x44(%rbp)
movsd 0x28(%r13), %xmm0
movsd 0x211b5(%rip), %xmm1    # 0x62c40
divsd %xmm1, %xmm0
addsd 0x201e1(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x74(%rbp)
movsd 0x30(%r13), %xmm0
movsd 0x22c67(%rip), %xmm1    # 0x64718
divsd %xmm1, %xmm0
addsd 0x201bb(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x70(%rbp)
movsd 0x38(%r13), %xmm0
divsd 0x22c41(%rip), %xmm0    # 0x64718
addsd 0x20199(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x6c(%rbp)
movsd 0x40(%r13), %xmm0
divsd 0x1ee17(%rip), %xmm0    # 0x60910
addsd 0x20177(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x68(%rbp)
movsd 0x48(%r13), %xmm0
divsd 0x21125(%rip), %xmm0    # 0x62c40
addsd 0x20155(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x64(%rbp)
movsd 0x50(%r13), %xmm0
divsd 0x240cb(%rip), %xmm0    # 0x65c08
addsd 0x20133(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %ecx
addl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rdi
movl %r12d, %esi
movl -0x40(%rbp), %r13d
movl %r13d, %edx
callq 0x45a69
addl %r13d, %r12d
movq -0x38(%rbp), %r13
movq %r13, %rdi
movl %r12d, %esi
movl -0x2c(%rbp), %edx
movl -0x78(%rbp), %ecx
callq 0x45a69
addl -0x2c(%rbp), %r12d
movq %r13, %rdi
movl %r12d, %esi
movq -0x58(%rbp), %r13
movl %r13d, %edx
movl -0x50(%rbp), %ecx
callq 0x45a69
leal (%r12,%r13), %esi
movq -0x38(%rbp), %rdi
pushq $0x16
popq %rdx
movl -0x4c(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0x16, %esi
movq -0x38(%rbp), %rdi
pushq $0x14
popq %rdx
movl -0x48(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0x2a, %esi
movq -0x38(%rbp), %rdi
pushq $0x14
popq %rdx
movl -0x44(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0x3e, %esi
movq -0x38(%rbp), %rdi
pushq $0x15
popq %rdx
movl -0x74(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0x53, %esi
movq -0x38(%rbp), %rdi
pushq $0x13
popq %rdx
movl -0x70(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0x66, %esi
movq -0x38(%rbp), %rdi
pushq $0x13
popq %rdx
movl -0x6c(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0x79, %esi
movq -0x38(%rbp), %rdi
pushq $0x16
popq %rdx
movl -0x68(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0x8f, %esi
movq -0x38(%rbp), %rdi
pushq $0x15
popq %rdx
movl -0x64(%rbp), %ecx
callq 0x45ae0
leal (%r12,%r13), %esi
addl $0xa4, %esi
movq -0x38(%rbp), %rdi
pushq $0x1b
popq %rdx
movl -0x60(%rbp), %ecx
callq 0x45ae0
addl %r13d, %r12d
addl $0xbf, %r12d
jmp 0x419bd
movq -0x80(%rbp), %rax
movl %r12d, 0x9f0bc(%rax)
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq