// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr6(bamboo::rtcm_t*, int, int)
static int encode_ssr6(rtcm_t *rtcm, int sys, int sync)
{
    double udint=0.0;
    int i,j,nsat,iod=0,prn,hrclk,np,offp;
    
    trace(3,"encode_ssr6: 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[2];
        iod  =rtcm->ssr[j].iod[2];
    }
    /* encode ssr header */
    i=encode_ssr_head(6,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;
        
        hrclk=ROUND(rtcm->ssr[j].hrclk/1E-4);
        
        setbitu(rtcm->buff,i,np,prn-offp); i+=np; /* satellite id */
        setbits(rtcm->buff,i,22,hrclk   ); i+=22; /* high rate clock corr */
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r15d
movl %esi, %r14d
movq %rdi, -0x58(%rbp)
leaq 0x26a0c(%rip), %rsi     # 0x705ca
xorl %ebx, %ebx
movl $0x3, %edi
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4d55d
movl $0x6, %eax
movq %rax, -0x50(%rbp)
leal -0x1(%r14), %eax
cmpl $0x7, %eax
ja 0x49c01
leaq 0x26301(%rip), %rcx     # 0x6feec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r15d, -0x48(%rbp)
jmpq *%rax
movl $0x0, -0x2c(%rbp)
jmp 0x49c49
cmpl $0x10, %r14d
je 0x49c35
cmpl $0x20, %r14d
jne 0x49dac
movl %r15d, -0x48(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x49c49
movl $0x0, -0x2c(%rbp)
movl $0x5, %eax
jmp 0x49c45
movl $0xffffff88, -0x2c(%rbp) # imm = 0xFFFFFF88
jmp 0x49c49
movl %r15d, -0x48(%rbp)
movl $0xffffff40, -0x2c(%rbp) # imm = 0xFFFFFF40
movl $0x4, %eax
movq %rax, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x6f1b8, %ebx          # imm = 0x6F1B8
movl $0x1, %r13d
leaq -0x34(%rbp), %r15
xorl %r12d, %r12d
movl %r13d, %edi
movq %r15, %rsi
callq 0x4d2f2
cmpl %r14d, %eax
jne 0x49c9c
movq -0x58(%rbp), %rax
cmpb $0x0, 0x420(%rax,%rbx)
je 0x49c9c
incl %r12d
movsd (%rax,%rbx), %xmm0
movsd %xmm0, -0x40(%rbp)
movl 0x28(%rax,%rbx), %eax
movl %eax, -0x30(%rbp)
addq $0x498, %rbx            # imm = 0x498
incl %r13d
cmpq $0x9b9c0, %rbx          # imm = 0x9B9C0
jne 0x49c6a
movl $0x0, (%rsp)
movl $0x6, %edi
movq -0x58(%rbp), %r13
movq %r13, %rsi
movl %r14d, %edx
movl %r12d, %ecx
movl -0x48(%rbp), %r8d
movl -0x30(%rbp), %r9d
movsd -0x40(%rbp), %xmm0
callq 0x4b64c
movq %rax, -0x40(%rbp)
leaq 0x9f0c4(%r13), %rax
movq %rax, -0x48(%rbp)
movl $0x1, %r12d
xorl %ebx, %ebx
leaq -0x34(%rbp), %r15
movq %r14, -0x60(%rbp)
movl %r12d, %edi
movq %r15, %rsi
callq 0x4d2f2
cmpl %r14d, %eax
jne 0x49d85
cmpb $0x0, 0x6f5d8(%r13,%rbx)
je 0x49d85
movsd 0x6f248(%r13,%rbx), %xmm0
divsd 0x20bfa(%rip), %xmm0    # 0x6a920
addsd 0x21f4a(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq -0x48(%rbp), %r13
movq %r13, %rdi
movq -0x40(%rbp), %r15
movl %r15d, %esi
movq -0x50(%rbp), %r14
movl %r14d, %edx
callq 0x4da98
leal (%r15,%r14), %esi
movq %r13, %rdi
movl $0x16, %edx
movl -0x30(%rbp), %ecx
movq -0x58(%rbp), %r13
callq 0x4db0c
addl %r14d, %r15d
addl $0x16, %r15d
movq %r15, -0x40(%rbp)
leaq -0x34(%rbp), %r15
movq -0x60(%rbp), %r14
addq $0x498, %rbx            # imm = 0x498
incl %r12d
cmpq $0x2c808, %rbx          # imm = 0x2C808
jne 0x49cf9
movq -0x40(%rbp), %rax
movl %eax, 0x9f0bc(%r13)
movl $0x1, %ebx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq