// File: /workspace/github_cpp_makefile_star2_O2/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, %r14d
movq %rdi, %rbx
leaq 0x2507d(%rip), %rsi     # 0x66553
xorl %r15d, %r15d
pushq $0x3
popq %rdi
movl %r14d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x455bc
pushq $0x6
popq %rdx
leal -0x1(%r14), %eax
cmpl $0x7, %eax
movq %r14, -0x70(%rbp)
ja 0x4152b
leaq 0x24acc(%rip), %rcx     # 0x65fcc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r12d, -0x58(%rbp)
jmpq *%rax
movq %rdx, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
pushq $0x11
popq %rax
movq %rax, -0x60(%rbp)
leaq 0x24c0a(%rip), %rax     # 0x66130
jmp 0x415cc
cmpl $0x10, %r14d
je 0x415ac
cmpl $0x20, %r14d
jne 0x417f4
movl %r12d, -0x58(%rbp)
movq %rdx, -0x48(%rbp)
pushq $0x9
popq %rax
movq %rax, -0x60(%rbp)
pushq $-0x1
popq %rax
movl %eax, -0x2c(%rbp)
leaq 0x24cb9(%rip), %rax     # 0x66210
jmp 0x415cc
movq %rdx, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
pushq $0x13
popq %rax
movq %rax, -0x60(%rbp)
leaq 0x24c0e(%rip), %rax     # 0x66180
jmp 0x415cc
movq %rdx, -0x48(%rbp)
pushq $0x4
popq %rax
movq %rax, -0x60(%rbp)
pushq $-0x78
popq %rax
movl %eax, -0x2c(%rbp)
leaq 0x23224(%rip), %rax     # 0x647b0
jmp 0x415cc
movl $0x0, -0x2c(%rbp)
pushq $0x4
popq %rax
movq %rax, -0x60(%rbp)
pushq $0x5
popq %rax
movq %rax, -0x48(%rbp)
leaq 0x231f6(%rip), %rax     # 0x647a0
jmp 0x415cc
movl %r12d, -0x58(%rbp)
pushq $0xd
popq %rax
movq %rax, -0x60(%rbp)
movl $0xffffff40, -0x2c(%rbp) # imm = 0xFFFFFF40
pushq $0x4
popq %rax
movq %rax, -0x48(%rbp)
leaq 0x24c04(%rip), %rax     # 0x661d0
movq %rax, -0x50(%rbp)
movq %rbx, -0x78(%rbp)
leaq 0x6f1c8(%rbx), %r15
xorl %r13d, %r13d
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x64(%rbp), %r12
movl $0x0, -0x38(%rbp)
xorl %ebx, %ebx
imulq $0x498, %r13, %r14      # imm = 0x498
incq %r13
addq %r15, %r14
cmpq $0x9c, %r13
je 0x41644
movl %r13d, %edi
movq %r12, %rsi
callq 0x45362
cmpl -0x70(%rbp), %eax
jne 0x41623
cmpb $0x0, 0x410(%r14)
jne 0x4162f
incq %r13
addq $0x498, %r14            # imm = 0x498
jmp 0x41600
incl %ebx
movsd (%r14), %xmm0
movsd %xmm0, -0x40(%rbp)
movl 0x20(%r14), %eax
movl %eax, -0x38(%rbp)
jmp 0x415f3
andl $0x0, (%rsp)
pushq $0x3
popq %rdi
movq -0x78(%rbp), %r14
movq %r14, %rsi
movq -0x70(%rbp), %rdx
movl %ebx, %ecx
movl -0x58(%rbp), %r8d
movl -0x38(%rbp), %r9d
movq %rdx, %r15
movsd -0x40(%rbp), %xmm0
callq 0x437dc
movq %rax, -0x40(%rbp)
leaq 0x9f0c4(%r14), %rax
movq %rax, -0x58(%rbp)
leaq 0x6f24c(%r14), %r13
xorl %ebx, %ebx
movq %r13, -0x80(%rbp)
imulq $0x498, %rbx, %r12      # imm = 0x498
incq %rbx
addq %r13, %r12
cmpq $0x9c, %rbx
je 0x417e5
movl %ebx, %edi
leaq -0x64(%rbp), %rsi
callq 0x45362
cmpl %r15d, %eax
jne 0x416be
cmpb $0x0, 0x38c(%r12)
jne 0x416ca
incq %rbx
addq $0x498, %r12            # imm = 0x498
jmp 0x41696
xorl %r14d, %r14d
movq $0x0, -0x38(%rbp)
cmpq %r14, -0x60(%rbp)
je 0x41736
movq -0x50(%rbp), %rax
movslq (%rax,%r14,4), %rax
movss (%r12,%rax,4), %xmm0
ucomiss 0x24b7c(%rip), %xmm0    # 0x6626c
jne 0x416f4
jnp 0x41731
movslq -0x38(%rbp), %r15
movl %r14d, -0x240(%rbp,%r15,4)
cvtss2sd %xmm0, %xmm0
divsd 0x200ac(%rip), %xmm0    # 0x617b8
addsd 0x20564(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
leal 0x1(%r15), %ecx
movq %rcx, -0x38(%rbp)
movl %eax, -0x160(%rbp,%r15,4)
movq -0x70(%rbp), %r15
incq %r14
jmp 0x416d5
movl -0x64(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq -0x58(%rbp), %r12
movq %r12, %rdi
movq -0x40(%rbp), %r14
movl %r14d, %esi
movq -0x48(%rbp), %r13
movl %r13d, %edx
callq 0x45a69
leal (%r14,%r13), %esi
movq %r12, %rdi
pushq $0x5
popq %rdx
movq -0x38(%rbp), %r12
movl %r12d, %ecx
callq 0x45a69
addl %r13d, %r14d
addl $0x5, %r14d
movq %r14, -0x40(%rbp)
testl %r12d, %r12d
movl $0x0, %eax
cmovlel %eax, %r12d
movq %r12, -0x38(%rbp)
xorl %r14d, %r14d
cmpq %r14, -0x38(%rbp)
je 0x417d8
movl -0x240(%rbp,%r14,4), %ecx
movq -0x58(%rbp), %r12
movq %r12, %rdi
movq %r15, %r13
movq -0x40(%rbp), %r15
movl %r15d, %esi
pushq $0x5
popq %rdx
callq 0x45a69
leal 0x5(%r15), %esi
movl -0x160(%rbp,%r14,4), %ecx
movq %r12, %rdi
pushq $0xe
popq %rdx
callq 0x45ae0
addl $0x13, %r15d
movq %r15, -0x40(%rbp)
movq %r13, %r15
incq %r14
jmp 0x4178a
movq -0x78(%rbp), %r14
movq -0x80(%rbp), %r13
jmp 0x41689
movq -0x40(%rbp), %rax
movl %eax, 0x9f0bc(%r14)
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq