// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr2(bamboo::rtcm_t*, int, int)
static int encode_ssr2(rtcm_t *rtcm, int sys, int sync)
{
    double udint=0.0;
    int i,j,iod=0,nsat,prn,np,offp,iode,dclk[3];
    
    trace(3,"encode_ssr2: sys=%d sync=%d\n",sys,sync);
    
    switch (sys) {
        case SYS_GPS: np=6; offp=  0; break;
        case SYS_GLO: np=5; offp=  0; break;
        case SYS_GAL: np=6; offp=  0; break;
        case SYS_QZS: np=4; offp=192; break;
        case SYS_CMP: np=6; offp=  1; break;
        case SYS_SBS: np=6; 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[1];
        iod  =rtcm->ssr[j].iod[1];
    }
    /* encode ssr header */
    i=encode_ssr_head(2,rtcm,sys,nsat,sync,iod,udint,0,0,0);
    
    for (j=0;j<MAXRTKSAT;j++) {
        if (satsys(j+1,&prn)!=sys||!rtcm->ssr[j].update) continue;
        
        iode=rtcm->ssr[j].iode;
        
        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 */
        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 $0x58, %rsp
movl %edx, %r12d
movl %esi, %ebx
movq %rdi, %r14
leaq 0x27625(%rip), %rsi     # 0x70556
xorl %r15d, %r15d
movl $0x3, %edi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x4d55d
movl $0x6, %eax
movq %rax, -0x50(%rbp)
leal -0x1(%rbx), %eax
cmpl $0x7, %eax
movq %rbx, -0x58(%rbp)
ja 0x48f77
leaq 0x26f0b(%rip), %rcx     # 0x6fe6c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r12d, -0x38(%rbp)
jmpq *%rax
movl $0x0, -0x2c(%rbp)
jmp 0x48fbd
cmpl $0x10, %ebx
je 0x48fa9
cmpl $0x20, %ebx
jne 0x491b3
movl %r12d, -0x38(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x48fbd
movl $0x0, -0x2c(%rbp)
movl $0x5, %eax
jmp 0x48fb9
movl $0xffffff88, -0x2c(%rbp) # imm = 0xFFFFFF88
jmp 0x48fbd
movl %r12d, -0x38(%rbp)
movl $0xffffff40, -0x2c(%rbp) # imm = 0xFFFFFF40
movl $0x4, %eax
movq %rax, -0x50(%rbp)
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x6f1b0, %ebx          # imm = 0x6F1B0
movl $0x1, %r12d
leaq -0x3c(%rbp), %r13
movl $0x0, -0x30(%rbp)
movl %r12d, %edi
movq %r13, %rsi
callq 0x4d2f2
cmpl -0x58(%rbp), %eax
jne 0x4900f
cmpb $0x0, 0x428(%r14,%rbx)
je 0x4900f
incl %r15d
movsd (%r14,%rbx), %xmm0
movsd %xmm0, -0x48(%rbp)
movl 0x2c(%r14,%rbx), %eax
movl %eax, -0x30(%rbp)
addq $0x498, %rbx            # imm = 0x498
incl %r12d
cmpq $0x9b9b8, %rbx          # imm = 0x9B9B8
jne 0x48fde
movl $0x0, (%rsp)
movl $0x2, %edi
movq %r14, %rsi
movq -0x58(%rbp), %rdx
movl %r15d, %ecx
movq %rdx, %r13
movl -0x38(%rbp), %r8d
movl -0x30(%rbp), %r9d
movsd -0x48(%rbp), %xmm0
callq 0x4b64c
movq %rax, -0x48(%rbp)
movq %r14, -0x68(%rbp)
leaq 0x9f0c4(%r14), %rax
movq %rax, -0x70(%rbp)
movl $0x1, %r12d
xorl %r14d, %r14d
leaq -0x3c(%rbp), %r15
movl %r12d, %edi
movq %r15, %rsi
callq 0x4d2f2
cmpl %r13d, %eax
jne 0x49188
movq -0x68(%rbp), %rbx
cmpb $0x0, 0x6f5d8(%rbx,%r14)
je 0x49188
movsd 0x6f230(%rbx,%r14), %xmm0
movsd 0x6f238(%rbx,%r14), %xmm1
movsd %xmm1, -0x38(%rbp)
divsd 0x2186b(%rip), %xmm0    # 0x6a920
movsd 0x22bbb(%rip), %xmm1    # 0x6bc78
addsd %xmm1, %xmm0
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
divsd 0x23b66(%rip), %xmm0    # 0x6cc40
addsd 0x22b96(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
movsd 0x6f240(%rbx,%r14), %xmm0
divsd 0x27060(%rip), %xmm0    # 0x70160
addsd 0x22b70(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x5c(%rbp)
movl -0x3c(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq -0x70(%rbp), %r13
movq %r13, %rdi
movq -0x48(%rbp), %r15
movl %r15d, %esi
movq -0x50(%rbp), %rbx
movl %ebx, %edx
callq 0x4da98
leal (%r15,%rbx), %esi
movq %r13, %rdi
movl $0x16, %edx
movl -0x30(%rbp), %ecx
callq 0x4db0c
leal (%r15,%rbx), %esi
addl $0x16, %esi
movq %r13, %rdi
movl $0x15, %edx
movl -0x38(%rbp), %ecx
callq 0x4db0c
leal (%r15,%rbx), %esi
addl $0x2b, %esi
movq %r13, %rdi
movq -0x58(%rbp), %r13
movl $0x1b, %edx
movl -0x5c(%rbp), %ecx
callq 0x4db0c
addl %ebx, %r15d
addl $0x46, %r15d
movq %r15, -0x48(%rbp)
leaq -0x3c(%rbp), %r15
addq $0x498, %r14            # imm = 0x498
incl %r12d
cmpq $0x2c808, %r14          # imm = 0x2C808
jne 0x4906d
movq -0x68(%rbp), %rax
movq -0x48(%rbp), %rcx
movl %ecx, 0x9f0bc(%rax)
movl $0x1, %r15d
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq