// File: 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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
leaq 0x3c93c(%rip), %rsi     # 0xc28ba
xorl %eax, %eax
movl $0x3, %edi
callq 0x8b980
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x1f, %eax
ja 0x8600e
movq -0x48(%rbp), %rax
leaq 0x3c18b(%rip), %rcx     # 0xc2130
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x8601a
movl $0x5, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x8601a
movl $0x6, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x8601a
movl $0x4, -0x3c(%rbp)
movl $0xc0, -0x40(%rbp)
jmp 0x8601a
movl $0x6, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x8601a
movl $0x6, -0x3c(%rbp)
movl $0x78, -0x40(%rbp)
jmp 0x8601a
movl $0x0, -0x4(%rbp)
jmp 0x86200
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x9b, -0x28(%rbp)
jge 0x860c6
movl -0x28(%rbp), %edi
addl $0x1, %edi
leaq -0x34(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x8606a
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
cmpb $0x0, 0x490(%rax)
jne 0x8606c
jmp 0x860b8
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0x70(%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movl 0x98(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x86028
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x30(%rbp), %r9d
movsd -0x20(%rbp), %xmm0
movl $0x6, %edi
xorl %eax, %eax
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x885f0
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x9b, -0x28(%rbp)
jge 0x861ec
movl -0x28(%rbp), %edi
addl $0x1, %edi
leaq -0x34(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x8614c
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
cmpb $0x0, 0x490(%rax)
jne 0x86151
jmp 0x861de
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movsd 0x100(%rax), %xmm0
movsd 0x36cef(%rip), %xmm1    # 0xbce68
divsd %xmm1, %xmm0
movsd 0x36cfb(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x34(%rbp), %ecx
subl -0x40(%rbp), %ecx
callq 0x8c0d0
movl -0x3c(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x24(%rbp), %esi
movl -0x38(%rbp), %ecx
movl $0x16, %edx
callq 0x8c1d0
movl -0x24(%rbp), %eax
addl $0x16, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x8610a
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)