// File: /workspace/github_cpp_makefile_star2_O1/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 $0x318, %rsp            # imm = 0x318
movl %edx, %r15d
movl %esi, %ebx
movq %rdi, -0x68(%rbp)
leaq 0x25659(%rip), %rsi     # 0x707f9
xorl %r14d, %r14d
movl $0x3, %edi
movl %ebx, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4ded0
movl $0x6, %eax
movq %rax, -0x60(%rbp)
cmpl $0x7, %ebx
jle 0x4b1f5
cmpl $0x8, %ebx
je 0x4b225
cmpl $0x10, %ebx
je 0x4b242
cmpl $0x20, %ebx
jne 0x4b5b9
movl %r15d, -0x38(%rbp)
leaq 0x24ef0(%rip), %rax     # 0x700d0
movq %rax, -0x50(%rbp)
movl $0x9, %ecx
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x4b283
cmpl $0x1, %ebx
je 0x4b268
cmpl $0x4, %ebx
jne 0x4b5b9
movl %r15d, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
leaq 0x23bcb(%rip), %rax     # 0x6ede0
movq %rax, -0x50(%rbp)
movl $0x4, %ecx
movl $0x5, %eax
jmp 0x4b262
movl %r15d, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
leaq 0x24e09(%rip), %rax     # 0x70040
movq %rax, -0x50(%rbp)
movl $0x13, %ecx
jmp 0x4b283
movl %r15d, -0x38(%rbp)
leaq 0x24e43(%rip), %rax     # 0x70090
movq %rax, -0x50(%rbp)
movl $0xd, %ecx
movl $0xffffff40, -0x2c(%rbp) # imm = 0xFFFFFF40
movl $0x4, %eax
movq %rax, -0x60(%rbp)
jmp 0x4b283
movl %r15d, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
leaq 0x24d76(%rip), %rax     # 0x6fff0
movq %rax, -0x50(%rbp)
movl $0x11, %ecx
movq %rcx, -0x88(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorl %r15d, %r15d
movl $0x6f1d0, %r14d         # imm = 0x6F1D0
movl $0x1, %r12d
leaq -0x54(%rbp), %r13
movl $0x0, -0x3c(%rbp)
movl %r12d, %edi
movq %r13, %rsi
callq 0x4dc2a
cmpl %ebx, %eax
jne 0x4b2e0
movq -0x68(%rbp), %rax
cmpb $0x0, 0x408(%rax,%r14)
je 0x4b2e0
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 0x4b2ac
movl $0x0, (%rsp)
movl $0x7, %edi
movl %ebx, %edx
movq -0x68(%rbp), %rbx
movq %rbx, %rsi
movl %edx, -0x6c(%rbp)
movl %r15d, %ecx
movl -0x38(%rbp), %r8d
movl -0x3c(%rbp), %r9d
movsd -0x48(%rbp), %xmm0
callq 0x4bffb
movl %eax, %r13d
leaq 0x6f148(%rbx), %r12
addq $0x9f0c4, %rbx          # imm = 0x9F0C4
xorl %r14d, %r14d
movq -0x50(%rbp), %r15
movq %r12, -0x78(%rbp)
movq %rbx, -0x80(%rbp)
movq %r14, %rbx
incq %r14
movl %r14d, %edi
leaq -0x54(%rbp), %rsi
callq 0x4dc2a
cmpl -0x6c(%rbp), %eax
jne 0x4b59b
movq %r14, -0x48(%rbp)
imulq $0x498, %rbx, %r14      # imm = 0x498
cmpb $0x0, 0x490(%r12,%r14)
je 0x4b597
addq %r12, %r14
xorl %ebx, %ebx
xorl %edx, %edx
movq -0x88(%rbp), %rcx
movslq (%r15,%rbx,4), %r12
movsd 0x1e0(%r14,%r12,8), %xmm0
ucomisd 0x1f56f(%rip), %xmm0    # 0x6a908
jne 0x4b39d
jnp 0x4b40e
movslq %edx, %r15
movl %ebx, -0x330(%rbp,%r15,4)
movsd 0x1f570(%rip), %xmm1    # 0x6a920
divsd %xmm1, %xmm0
movsd 0x208bc(%rip), %xmm1    # 0x6bc78
addsd %xmm1, %xmm0
callq 0x8ad0
cvttsd2si %xmm0, %eax
movl %eax, -0x250(%rbp,%r15,4)
xorps %xmm0, %xmm0
cvtss2sd 0x39c(%r14,%r12,4), %xmm0
divsd 0x1f53a(%rip), %xmm0    # 0x6a920
addsd 0x2088a(%rip), %xmm0    # 0x6bc78
callq 0x8ad0
movq -0x88(%rbp), %rcx
cvttsd2si %xmm0, %eax
leal 0x1(%r15), %edx
movl %eax, -0x170(%rbp,%r15,4)
movq -0x50(%rbp), %r15
incq %rbx
cmpq %rbx, %rcx
jne 0x4b383
movsd 0x480(%r14), %xmm0
movsd 0x488(%r14), %xmm1
movsd %xmm1, -0x38(%rbp)
movsd 0x23a47(%rip), %xmm1    # 0x6ee80
divsd %xmm1, %xmm0
mulsd 0x24d23(%rip), %xmm0    # 0x70168
movsd 0x2082b(%rip), %xmm1    # 0x6bc78
addsd %xmm1, %xmm0
movl %edx, %r12d
callq 0x8ad0
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movsd -0x38(%rbp), %xmm0
divsd 0x23a13(%rip), %xmm0    # 0x6ee80
mulsd 0x24cfb(%rip), %xmm0    # 0x70170
addsd 0x207fb(%rip), %xmm0    # 0x6bc78
callq 0x8ad0
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
movl -0x54(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq -0x80(%rbp), %r14
movq %r14, %rdi
movl %r13d, %esi
movq -0x60(%rbp), %rbx
movl %ebx, %edx
callq 0x4e403
leal (%rbx,%r13), %esi
movq %r14, %rdi
movl $0x5, %edx
movl %r12d, %ecx
callq 0x4e403
leal (%rbx,%r13), %esi
addl $0x5, %esi
movq %r14, %rdi
movl $0x9, %edx
movl -0x3c(%rbp), %ecx
callq 0x4e403
leal (%rbx,%r13), %esi
addl $0xe, %esi
movq %r14, %rdi
movl $0x8, %edx
movl -0x38(%rbp), %ecx
callq 0x4e47b
addl %ebx, %r13d
addl $0x16, %r13d
testl %r12d, %r12d
jle 0x4b593
movl %r12d, %r12d
xorl %r14d, %r14d
movq -0x80(%rbp), %rbx
movl -0x330(%rbp,%r14,4), %ecx
movq %rbx, %rdi
movl %r13d, %esi
movl $0x5, %edx
callq 0x4e403
leal 0x5(%r13), %esi
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4e403
leal 0x6(%r13), %esi
movq %rbx, %rdi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x4e403
leal 0x8(%r13), %esi
movq %rbx, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x4e403
movl -0x250(%rbp,%r14,4), %ecx
leal 0xc(%r13), %esi
movq %rbx, %rdi
movl $0x14, %edx
callq 0x4e47b
movl -0x170(%rbp,%r14,4), %ecx
leal 0x20(%r13), %esi
movq %rbx, %rdi
movl $0x11, %edx
callq 0x4e47b
addl $0x31, %r13d
incq %r14
cmpq %r14, %r12
jne 0x4b500
movq -0x78(%rbp), %r12
movq -0x48(%rbp), %r14
cmpq $0x9b, %r14
jne 0x4b340
movq -0x68(%rbp), %rax
movl %r13d, 0x9f0bc(%rax)
movl $0x1, %r14d
movl %r14d, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq