// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr3(bamboo::rtcm_t*, int, int)
static int encode_ssr3(rtcm_t *rtcm, int sys, int sync)
{
    const int *codes;
    double udint=0.0;
    int i,j,k,iod=0,nsat,prn,nbias,np,offp,ncode;
    int code[MAXCODE],bias[MAXCODE];
    
    trace(3,"encode_ssr3: sys=%d sync=%d\n",sys,sync);
    
    switch (sys) {
        case SYS_GPS: np=6; offp=  0; codes=codes_gps; ncode=17; break;
        case SYS_GLO: np=5; offp=  0; codes=codes_glo; ncode= 4; break;
        case SYS_GAL: np=6; offp=  0; codes=codes_gal; ncode=19; break;
        case SYS_QZS: np=4; offp=192; codes=codes_qzs; ncode=13; break;
        case SYS_CMP: np=6; offp=  1; codes=codes_bds; ncode= 9; break;
        case SYS_SBS: np=6; offp=120; codes=codes_sbs; ncode= 4; 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[4];
        iod  =rtcm->ssr[j].iod[4];
    }
    /* encode ssr header */
    i=encode_ssr_head(3,rtcm,sys,nsat,sync,iod,udint,0,0,0);
    
    for (j=nsat=0;j<MAXRTKSAT;j++) {
        if (satsys(j+1,&prn)!=sys||!rtcm->ssr[j].update) continue;
        
        for (k=nbias=0;k<ncode;k++) {
            if (rtcm->ssr[j].cbias[codes[k]-1]==0.0) continue;
            code[nbias]=k;
            bias[nbias++]=ROUND(rtcm->ssr[j].cbias[codes[k]-1]/0.01);
        }
        setbitu(rtcm->buff,i,np,prn-offp); i+=np; /* satellite id */
        setbitu(rtcm->buff,i, 5,nbias);    i+= 5; /* number of code biases */
        
        for (k=0;k<nbias;k++) {
            setbitu(rtcm->buff,i, 5,code[k]); i+= 5; /* signal indicator */
            setbits(rtcm->buff,i,14,bias[k]); i+=14; /* code bias */
        }
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movl %edx, %r12d
movl %esi, %ebx
movq %rdi, %r14
leaq 0x269fc(%rip), %rsi     # 0x70573
xorl %r15d, %r15d
movl $0x3, %edi
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x4ded0
movl $0x6, %eax
movq %rax, -0x60(%rbp)
leal -0x1(%rbx), %eax
cmpl $0x7, %eax
movq %rbx, -0x68(%rbp)
ja 0x49bd0
leaq 0x262e5(%rip), %rcx     # 0x6fe8c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r12d, -0x48(%rbp)
jmpq *%rax
movl $0x0, -0x2c(%rbp)
movl $0x11, %eax
movq %rax, -0x38(%rbp)
leaq 0x26425(%rip), %rax     # 0x6fff0
jmp 0x49c73
cmpl $0x10, %ebx
je 0x49c4f
cmpl $0x20, %ebx
jne 0x49e6e
movl %r12d, -0x48(%rbp)
movl $0x9, %eax
movq %rax, -0x38(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
leaq 0x264d7(%rip), %rax     # 0x700d0
jmp 0x49c73
movl $0x0, -0x2c(%rbp)
movl $0x13, %eax
movq %rax, -0x38(%rbp)
leaq 0x2642e(%rip), %rax     # 0x70040
jmp 0x49c73
movl $0x4, %eax
movq %rax, -0x38(%rbp)
movl $0xffffff88, -0x2c(%rbp) # imm = 0xFFFFFF88
leaq 0x251c5(%rip), %rax     # 0x6edf0
jmp 0x49c73
movl $0x0, -0x2c(%rbp)
movl $0x4, %eax
movq %rax, -0x38(%rbp)
movl $0x5, %eax
movq %rax, -0x60(%rbp)
leaq 0x25193(%rip), %rax     # 0x6ede0
jmp 0x49c73
movl %r12d, -0x48(%rbp)
movl $0xd, %eax
movq %rax, -0x38(%rbp)
movl $0xffffff40, -0x2c(%rbp) # imm = 0xFFFFFF40
movl $0x4, %eax
movq %rax, -0x60(%rbp)
leaq 0x2641d(%rip), %rax     # 0x70090
movq %rax, -0x78(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorl %r15d, %r15d
movl $0x6f1c8, %r13d         # imm = 0x6F1C8
movl $0x1, %r12d
leaq -0x4c(%rbp), %rbx
movl $0x0, -0x58(%rbp)
movl %r12d, %edi
movq %rbx, %rsi
callq 0x4dc2a
cmpl -0x68(%rbp), %eax
jne 0x49cca
cmpb $0x0, 0x410(%r14,%r13)
je 0x49cca
incl %r15d
movsd (%r14,%r13), %xmm0
movsd %xmm0, -0x40(%rbp)
movl 0x20(%r14,%r13), %eax
movl %eax, -0x58(%rbp)
addq $0x498, %r13            # imm = 0x498
incl %r12d
cmpq $0x9b9d0, %r13          # imm = 0x9B9D0
jne 0x49c99
movl $0x0, (%rsp)
movl $0x3, %edi
movq %r14, %rsi
movq -0x68(%rbp), %rdx
movl %r15d, %ecx
movl -0x48(%rbp), %r8d
movl -0x58(%rbp), %r9d
movsd -0x40(%rbp), %xmm0
callq 0x4bffb
movl %eax, %r13d
leaq 0x6f148(%r14), %rax
leaq 0x9f0c4(%r14), %r12
xorl %ebx, %ebx
movq -0x38(%rbp), %r15
movq %r14, -0x70(%rbp)
movq %rax, -0x48(%rbp)
movq %r12, -0x40(%rbp)
leaq 0x1(%rbx), %rdi
movq %rdi, -0x58(%rbp)
leaq -0x4c(%rbp), %rsi
callq 0x4dc2a
cmpl -0x68(%rbp), %eax
jne 0x49e50
imulq $0x498, %rbx, %r12      # imm = 0x498
movq -0x48(%rbp), %rax
cmpb $0x0, 0x490(%rax,%r12)
je 0x49e50
addq %rax, %r12
xorl %r14d, %r14d
xorl %ebx, %ebx
movq -0x78(%rbp), %rcx
movq -0x40(%rbp), %rdx
movslq (%rcx,%r14,4), %rax
movss 0x104(%r12,%rax,4), %xmm0
ucomiss 0x26507(%rip), %xmm0    # 0x70288
jne 0x49d85
jnp 0x49dc5
movslq %ebx, %r15
movl %r14d, -0x240(%rbp,%r15,4)
cvtss2sd %xmm0, %xmm0
divsd 0x21a24(%rip), %xmm0    # 0x6b7c0
addsd 0x21ed4(%rip), %xmm0    # 0x6bc78
callq 0x8ad0
movq -0x40(%rbp), %rdx
movq -0x78(%rbp), %rcx
cvttsd2si %xmm0, %eax
leal 0x1(%r15), %ebx
movl %eax, -0x160(%rbp,%r15,4)
movq -0x38(%rbp), %r15
incq %r14
cmpq %r14, %r15
jne 0x49d6c
movl -0x4c(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq %rdx, %r12
movq %rdx, %rdi
movl %r13d, %esi
movq -0x60(%rbp), %r14
movl %r14d, %edx
callq 0x4e403
leal (%r14,%r13), %esi
movq %r12, %rdi
movl $0x5, %edx
movl %ebx, %ecx
callq 0x4e403
addl %r14d, %r13d
addl $0x5, %r13d
testl %ebx, %ebx
jle 0x49e4c
movl %ebx, %ebx
xorl %r14d, %r14d
movq -0x40(%rbp), %r12
movl -0x240(%rbp,%r14,4), %ecx
movq %r12, %rdi
movl %r13d, %esi
movl $0x5, %edx
callq 0x4e403
movl -0x160(%rbp,%r14,4), %ecx
leal 0x5(%r13), %esi
movq %r12, %rdi
movl $0xe, %edx
callq 0x4e47b
addl $0x13, %r13d
incq %r14
cmpq %r14, %rbx
jne 0x49e0f
movq -0x70(%rbp), %r14
movq -0x58(%rbp), %rbx
cmpq $0x9b, %rbx
jne 0x49d28
movl %r13d, 0x9f0bc(%r14)
movl $0x1, %r15d
movl %r15d, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq