// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr5(bamboo::rtcm_t*, int, int)
static int encode_ssr5(rtcm_t *rtcm, int sys, int sync)
{
    double udint=0.0;
    int i,j,nsat,iod=0,prn,ura,np,offp;
    
    trace(3,"encode_ssr5: 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[3];
        iod  =rtcm->ssr[j].iod[3];
    }
    /* encode ssr header */
    i=encode_ssr_head(5,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;
        
        ura=rtcm->ssr[j].ura;
        setbitu(rtcm->buff,i,np,prn-offp); i+=np; /* satellite id */
        setbitu(rtcm->buff,i, 6,ura     ); i+= 6; /* ssr ura */
    }
    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 0x3cbbf(%rip), %rsi     # 0xc289d
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 0x85d6e
movq -0x48(%rbp), %rax
leaq 0x3c3ab(%rip), %rcx     # 0xc20b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x85d7a
movl $0x5, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x85d7a
movl $0x6, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x85d7a
movl $0x4, -0x3c(%rbp)
movl $0xc0, -0x40(%rbp)
jmp 0x85d7a
movl $0x6, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x85d7a
movl $0x6, -0x3c(%rbp)
movl $0x78, -0x40(%rbp)
jmp 0x85d7a
movl $0x0, -0x4(%rbp)
jmp 0x85f3a
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x9b, -0x28(%rbp)
jge 0x85e26
movl -0x28(%rbp), %edi
addl $0x1, %edi
leaq -0x34(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x85dca
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 0x85dcc
jmp 0x85e18
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 0x78(%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 0x9c(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x85d88
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 $0x5, %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 0x85f26
movl -0x28(%rbp), %edi
addl $0x1, %edi
leaq -0x34(%rbp), %rsi
callq 0x8b3b0
cmpl -0x14(%rbp), %eax
jne 0x85eac
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 0x85eae
jmp 0x85f18
movq -0x10(%rbp), %rax
addq $0x6f148, %rax          # imm = 0x6F148
movslq -0x28(%rbp), %rcx
imulq $0x498, %rcx, %rcx      # imm = 0x498
addq %rcx, %rax
movl 0xb0(%rax), %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 $0x6, %edx
callq 0x8c0d0
movl -0x24(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x85e6a
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
nopw %cs:(%rax,%rax)