// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr7(bamboo::rtcm_t*, int, int)
static int encode_ssr7(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],pbias[MAXCODE],stdpb[MAXCODE],yaw_ang,yaw_rate;
    
    trace(3,"encode_ssr7: 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;
        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[5];
        iod  =rtcm->ssr[j].iod[5];
    }
    /* encode ssr header */
    i=encode_ssr_head(7,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].pbias[codes[k]-1]==0.0) continue;
            code[nbias]=k;
            pbias[nbias  ]=ROUND(rtcm->ssr[j].pbias[codes[k]-1]/0.0001);
            stdpb[nbias++]=ROUND(rtcm->ssr[j].stdpb[codes[k]-1]/0.0001);
        }
        yaw_ang =ROUND(rtcm->ssr[j].yaw_ang /180.0* 256.0);
        yaw_rate=ROUND(rtcm->ssr[j].yaw_rate/180.0*8192.0);
        setbitu(rtcm->buff,i,np,prn-offp); i+=np; /* satellite id */
        setbitu(rtcm->buff,i, 5,nbias);    i+= 5; /* number of code biases */
        setbitu(rtcm->buff,i, 9,yaw_ang);  i+= 9; /* yaw angle */
        setbits(rtcm->buff,i, 8,yaw_rate); i+= 8; /* yaw rate */
        
        for (k=0;k<nbias;k++) {
            setbitu(rtcm->buff,i, 5,code[k] ); i+= 5; /* signal indicator */
            setbitu(rtcm->buff,i, 1,0       ); i+= 1; /* integer-indicator */
            setbitu(rtcm->buff,i, 2,0       ); i+= 2; /* WL integer-indicator */
            setbitu(rtcm->buff,i, 4,0       ); i+= 4; /* discont counter */
            setbits(rtcm->buff,i,20,pbias[k]); i+=20; /* phase bias */
            setbits(rtcm->buff,i,17,stdpb[k]); i+=17; /* std-dev phase bias */
        }
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movl %edx, %r12d
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x25fef(%rip), %rsi     # 0x707f9
xorl %r15d, %r15d
movl $0x3, %edi
movl %r14d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x4d55d
movl $0x6, %eax
movq %rax, -0x60(%rbp)
cmpl $0x7, %r14d
movl %r14d, -0x54(%rbp)
jle 0x4a868
cmpl $0x8, %r14d
je 0x4a89a
cmpl $0x10, %r14d
je 0x4a8b7
cmpl $0x20, %r14d
jne 0x4ac2d
movl %r12d, -0x38(%rbp)
leaq 0x2587d(%rip), %rax     # 0x700d0
movq %rax, -0x50(%rbp)
movl $0x9, %ecx
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a8f8
cmpl $0x1, %r14d
je 0x4a8dd
cmpl $0x4, %r14d
jne 0x4ac2d
movl %r12d, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
leaq 0x24556(%rip), %rax     # 0x6ede0
movq %rax, -0x50(%rbp)
movl $0x4, %ecx
movl $0x5, %eax
jmp 0x4a8d7
movl %r12d, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
leaq 0x25794(%rip), %rax     # 0x70040
movq %rax, -0x50(%rbp)
movl $0x13, %ecx
jmp 0x4a8f8
movl %r12d, -0x38(%rbp)
leaq 0x257ce(%rip), %rax     # 0x70090
movq %rax, -0x50(%rbp)
movl $0xd, %ecx
movl $0xffffff40, -0x2c(%rbp) # imm = 0xFFFFFF40
movl $0x4, %eax
movq %rax, -0x60(%rbp)
jmp 0x4a8f8
movl %r12d, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
leaq 0x25701(%rip), %rax     # 0x6fff0
movq %rax, -0x50(%rbp)
movl $0x11, %ecx
movq %rcx, -0x80(%rbp)
movq %rbx, -0x70(%rbp)
leaq 0x6f148(%rbx), %rax
movq %rax, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorl %r15d, %r15d
movl $0x6f1d0, %r14d         # imm = 0x6F1D0
movl $0x1, %r12d
leaq -0x58(%rbp), %r13
movl $0x0, -0x3c(%rbp)
movl -0x54(%rbp), %ebx
movl %r12d, %edi
movq %r13, %rsi
callq 0x4d2f2
cmpl %ebx, %eax
jne 0x4a964
movq -0x70(%rbp), %rax
cmpb $0x0, 0x408(%rax,%r14)
je 0x4a964
incl %r15d
movsd (%rax,%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
movl 0x1c(%rax,%r14), %eax
movl %eax, -0x3c(%rbp)
addq $0x498, %r14            # imm = 0x498
incl %r12d
cmpq $0x9b9d8, %r14          # imm = 0x9B9D8
jne 0x4a930
movl $0x0, (%rsp)
movl $0x7, %edi
movl %ebx, %edx
movq -0x70(%rbp), %rbx
movq %rbx, %rsi
movl %r15d, %ecx
movl -0x38(%rbp), %r8d
movl -0x3c(%rbp), %r9d
movsd -0x48(%rbp), %xmm0
callq 0x4b64c
movl %eax, %r13d
addq $0x9f0c4, %rbx          # imm = 0x9F0C4
xorl %r14d, %r14d
movq -0x50(%rbp), %r15
movq -0x68(%rbp), %r12
movq %rbx, -0x78(%rbp)
movq %r14, %rbx
incq %r14
movl %r14d, %edi
leaq -0x58(%rbp), %rsi
callq 0x4d2f2
cmpl -0x54(%rbp), %eax
jne 0x4ac0f
movq %r14, -0x48(%rbp)
imulq $0x498, %rbx, %r14      # imm = 0x498
cmpb $0x0, 0x490(%r12,%r14)
je 0x4ac0b
addq %r12, %r14
xorl %ebx, %ebx
xorl %edx, %edx
movq -0x80(%rbp), %rcx
movslq (%r15,%rbx,4), %r12
movsd 0x1e0(%r14,%r12,8), %xmm0
ucomisd 0x1fef8(%rip), %xmm0    # 0x6a908
jne 0x4aa14
jnp 0x4aa82
movslq %edx, %r15
movl %ebx, -0x320(%rbp,%r15,4)
movsd 0x1fef9(%rip), %xmm1    # 0x6a920
divsd %xmm1, %xmm0
movsd 0x21245(%rip), %xmm1    # 0x6bc78
addsd %xmm1, %xmm0
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x240(%rbp,%r15,4)
xorps %xmm0, %xmm0
cvtss2sd 0x39c(%r14,%r12,4), %xmm0
divsd 0x1fec3(%rip), %xmm0    # 0x6a920
addsd 0x21213(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
movq -0x80(%rbp), %rcx
cvttsd2si %xmm0, %eax
leal 0x1(%r15), %edx
movl %eax, -0x160(%rbp,%r15,4)
movq -0x50(%rbp), %r15
incq %rbx
cmpq %rbx, %rcx
jne 0x4a9fa
movsd 0x480(%r14), %xmm0
movsd 0x488(%r14), %xmm1
movsd %xmm1, -0x38(%rbp)
movsd 0x243d3(%rip), %xmm1    # 0x6ee80
divsd %xmm1, %xmm0
mulsd 0x256af(%rip), %xmm0    # 0x70168
movsd 0x211b7(%rip), %xmm1    # 0x6bc78
addsd %xmm1, %xmm0
movl %edx, %r12d
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movsd -0x38(%rbp), %xmm0
divsd 0x2439f(%rip), %xmm0    # 0x6ee80
mulsd 0x25687(%rip), %xmm0    # 0x70170
addsd 0x21187(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
movl -0x58(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq -0x78(%rbp), %r14
movq %r14, %rdi
movl %r13d, %esi
movq -0x60(%rbp), %rbx
movl %ebx, %edx
callq 0x4da98
leal (%rbx,%r13), %esi
movq %r14, %rdi
movl $0x5, %edx
movl %r12d, %ecx
callq 0x4da98
leal (%rbx,%r13), %esi
addl $0x5, %esi
movq %r14, %rdi
movl $0x9, %edx
movl -0x3c(%rbp), %ecx
callq 0x4da98
leal (%rbx,%r13), %esi
addl $0xe, %esi
movq %r14, %rdi
movl $0x8, %edx
movl -0x38(%rbp), %ecx
callq 0x4db0c
addl %ebx, %r13d
addl $0x16, %r13d
testl %r12d, %r12d
jle 0x4ac07
movl %r12d, %r12d
xorl %r14d, %r14d
movq -0x78(%rbp), %rbx
movl -0x320(%rbp,%r14,4), %ecx
movq %rbx, %rdi
movl %r13d, %esi
movl $0x5, %edx
callq 0x4da98
leal 0x5(%r13), %esi
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4da98
leal 0x6(%r13), %esi
movq %rbx, %rdi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x4da98
leal 0x8(%r13), %esi
movq %rbx, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x4da98
movl -0x240(%rbp,%r14,4), %ecx
leal 0xc(%r13), %esi
movq %rbx, %rdi
movl $0x14, %edx
callq 0x4db0c
movl -0x160(%rbp,%r14,4), %ecx
leal 0x20(%r13), %esi
movq %rbx, %rdi
movl $0x11, %edx
callq 0x4db0c
addl $0x31, %r13d
incq %r14
cmpq %r14, %r12
jne 0x4ab74
movq -0x68(%rbp), %r12
movq -0x48(%rbp), %r14
cmpq $0x9b, %r14
jne 0x4a9ba
movq -0x70(%rbp), %rax
movl %r13d, 0x9f0bc(%rax)
movl $0x1, %r15d
movl %r15d, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq