// File: /workspace/github_cpp_makefile_star2_O1/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 0x26076(%rip), %rsi     # 0x705ca
xorl %ebx, %ebx
movl $0x3, %edi
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4ded0
movl $0x6, %eax
movq %rax, -0x50(%rbp)
leal -0x1(%r14), %eax
cmpl $0x7, %eax
ja 0x4a597
leaq 0x2596b(%rip), %rcx     # 0x6feec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r15d, -0x48(%rbp)
jmpq *%rax
movl $0x0, -0x2c(%rbp)
jmp 0x4a5df
cmpl $0x10, %r14d
je 0x4a5cb
cmpl $0x20, %r14d
jne 0x4a742
movl %r15d, -0x48(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a5df
movl $0x0, -0x2c(%rbp)
movl $0x5, %eax
jmp 0x4a5db
movl $0xffffff88, -0x2c(%rbp) # imm = 0xFFFFFF88
jmp 0x4a5df
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 0x4dc2a
cmpl %r14d, %eax
jne 0x4a632
movq -0x58(%rbp), %rax
cmpb $0x0, 0x420(%rax,%rbx)
je 0x4a632
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 0x4a600
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 0x4bffb
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 0x4dc2a
cmpl %r14d, %eax
jne 0x4a71b
cmpb $0x0, 0x6f5d8(%r13,%rbx)
je 0x4a71b
movsd 0x6f248(%r13,%rbx), %xmm0
divsd 0x20264(%rip), %xmm0    # 0x6a920
addsd 0x215b4(%rip), %xmm0    # 0x6bc78
callq 0x8ad0
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 0x4e403
leal (%r15,%r14), %esi
movq %r13, %rdi
movl $0x16, %edx
movl -0x30(%rbp), %ecx
movq -0x58(%rbp), %r13
callq 0x4e47b
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 0x4a68f
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