// File: /workspace/github_cpp_makefile_star2_O2/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, %r14d
movq %rdi, %rbx
leaq 0x23e38(%rip), %rsi     # 0x667d9
movq $0x0, -0x68(%rbp)
pushq $0x3
popq %rdi
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x455bc
pushq $0x6
popq %rax
cmpl $0x1, %r14d
movl %r14d, -0x38(%rbp)
je 0x42a64
cmpl $0x20, %r14d
je 0x42a05
cmpl $0x8, %r14d
je 0x42a4d
cmpl $0x10, %r14d
je 0x42a27
cmpl $0x4, %r14d
jne 0x42dec
movl %r15d, -0x30(%rbp)
leaq 0x21daf(%rip), %rax     # 0x647a0
movq %rax, -0x40(%rbp)
pushq $0x4
popq %rax
movq %rax, -0x58(%rbp)
pushq $0x5
popq %rax
movq %rax, -0x50(%rbp)
jmp 0x42a7e
movl %r15d, -0x30(%rbp)
movq %rax, -0x50(%rbp)
leaq 0x237fc(%rip), %rax     # 0x66210
movq %rax, -0x40(%rbp)
pushq $0x9
popq %rax
movq %rax, -0x58(%rbp)
pushq $-0x1
popq %rax
movl %eax, -0x34(%rbp)
jmp 0x42a85
movl %r15d, -0x30(%rbp)
leaq 0x2379e(%rip), %rax     # 0x661d0
movq %rax, -0x40(%rbp)
pushq $0xd
popq %rax
movq %rax, -0x58(%rbp)
movl $0xffffff40, -0x34(%rbp) # imm = 0xFFFFFF40
pushq $0x4
popq %rax
movq %rax, -0x50(%rbp)
jmp 0x42a85
movl %r15d, -0x30(%rbp)
movq %rax, -0x50(%rbp)
leaq 0x23724(%rip), %rax     # 0x66180
movq %rax, -0x40(%rbp)
pushq $0x13
jmp 0x42a79
movl %r15d, -0x30(%rbp)
movq %rax, -0x50(%rbp)
leaq 0x236bd(%rip), %rax     # 0x66130
movq %rax, -0x40(%rbp)
pushq $0x11
popq %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
movq %rbx, -0x88(%rbp)
leaq 0x6f1d0(%rbx), %r14
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq -0x5c(%rbp), %r12
xorl %r13d, %r13d
xorl %r15d, %r15d
imulq $0x498, %r13, %rbx      # imm = 0x498
incq %r13
addq %r14, %rbx
cmpq $0x9c, %r13
je 0x42af5
movl %r13d, %edi
movq %r12, %rsi
callq 0x45362
cmpl -0x38(%rbp), %eax
jne 0x42ad4
cmpb $0x0, 0x408(%rbx)
jne 0x42ae0
incq %r13
addq $0x498, %rbx            # imm = 0x498
jmp 0x42ab2
incl %r15d
movsd (%rbx), %xmm0
movsd %xmm0, -0x48(%rbp)
movl 0x1c(%rbx), %eax
movq %rax, -0x68(%rbp)
jmp 0x42aa5
andl $0x0, (%rsp)
pushq $0x7
popq %rdi
movq -0x88(%rbp), %r14
movq %r14, %rsi
movl -0x38(%rbp), %r13d
movl %r13d, %edx
movl %r15d, %ecx
movl -0x30(%rbp), %r8d
movq -0x68(%rbp), %r9
movsd -0x48(%rbp), %xmm0
callq 0x437dc
movq %rax, -0x30(%rbp)
leaq 0x9f0c4(%r14), %rax
movq %rax, -0x48(%rbp)
leaq 0x6f328(%r14), %r12
pushq $0x1
popq %rax
movq %rax, -0x68(%rbp)
xorl %ebx, %ebx
imulq $0x498, %rbx, %r15      # imm = 0x498
incq %rbx
addq %r12, %r15
cmpq $0x9c, %rbx
je 0x42de1
movl %ebx, %edi
leaq -0x5c(%rbp), %rsi
callq 0x45362
cmpl %r13d, %eax
jne 0x42b75
cmpb $0x0, 0x2b0(%r15)
jne 0x42b81
incq %rbx
addq $0x498, %r15            # imm = 0x498
jmp 0x42b4e
xorl %r14d, %r14d
xorl %ecx, %ecx
movq -0x40(%rbp), %rax
movq %r12, -0x90(%rbp)
cmpq %r14, -0x58(%rbp)
je 0x42c24
movslq (%rax,%r14,4), %r12
movsd (%r15,%r12,8), %xmm0
ucomisd 0x1dd4b(%rip), %xmm0    # 0x608f8
jne 0x42bb1
jnp 0x42c1c
movslq %ecx, %r13
movl %r14d, -0x330(%rbp,%r13,4)
movsd 0x1dd4c(%rip), %xmm1    # 0x60910
divsd %xmm1, %xmm0
movsd 0x1f0a8(%rip), %xmm1    # 0x61c78
addsd %xmm1, %xmm0
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x250(%rbp,%r13,4)
cvtss2sd 0x1bc(%r15,%r12,4), %xmm0
divsd 0x1dd19(%rip), %xmm0    # 0x60910
addsd 0x1f079(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
leal 0x1(%r13), %ecx
movl %eax, -0x170(%rbp,%r13,4)
movq -0x40(%rbp), %rax
movl -0x38(%rbp), %r13d
incq %r14
jmp 0x42b91
movsd 0x2a0(%r15), %xmm0
movsd 0x2a8(%r15), %xmm1
movsd %xmm1, -0x70(%rbp)
movsd 0x21af5(%rip), %xmm1    # 0x64738
divsd %xmm1, %xmm0
mulsd 0x22fc1(%rip), %xmm0    # 0x65c10
movsd 0x1f021(%rip), %xmm1    # 0x61c78
addsd %xmm1, %xmm0
movq %rcx, -0x80(%rbp)
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x74(%rbp)
movsd -0x70(%rbp), %xmm0
divsd 0x21ac0(%rip), %xmm0    # 0x64738
mulsd 0x22f98(%rip), %xmm0    # 0x65c18
addsd 0x1eff0(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %eax
movl %eax, -0x70(%rbp)
movl -0x5c(%rbp), %ecx
addl -0x34(%rbp), %ecx
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %r12
movl %r12d, %esi
movq -0x50(%rbp), %r14
movl %r14d, %edx
callq 0x45a69
leal (%r12,%r14), %r15d
movq -0x48(%rbp), %r12
movq %r12, %rdi
movl %r15d, %esi
pushq $0x5
popq %rdx
movq -0x80(%rbp), %rcx
callq 0x45a69
movq -0x30(%rbp), %rax
leal (%rax,%r14), %esi
addl $0x5, %esi
movq %r12, %rdi
pushq $0x9
popq %rdx
movl -0x74(%rbp), %ecx
callq 0x45a69
movq -0x30(%rbp), %rax
leal (%rax,%r14), %esi
addl $0xe, %esi
movq %r12, %rdi
pushq $0x8
popq %rdx
movl -0x70(%rbp), %ecx
callq 0x45ae0
movq -0x80(%rbp), %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
imulq $0x31, %rcx, %rax
movq %rax, -0x30(%rbp)
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq %r12, -0x30(%rbp)
je 0x42dc3
leaq (%r15,%r12), %rsi
addq $0x16, %rsi
movl -0x330(%rbp,%r14), %ecx
movq -0x48(%rbp), %r13
movq %r13, %rdi
pushq $0x5
popq %rdx
callq 0x45a69
leal (%r15,%r12), %esi
addl $0x1b, %esi
movq %r13, %rdi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x45a69
leal (%r15,%r12), %esi
addl $0x1c, %esi
movq %r13, %rdi
pushq $0x2
popq %rdx
xorl %ecx, %ecx
callq 0x45a69
leal (%r15,%r12), %esi
addl $0x1e, %esi
movq %r13, %rdi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
callq 0x45a69
leal (%r15,%r12), %esi
addl $0x22, %esi
movl -0x250(%rbp,%r14), %ecx
movq %r13, %rdi
pushq $0x14
popq %rdx
callq 0x45ae0
leal (%r15,%r12), %esi
addl $0x36, %esi
movl -0x170(%rbp,%r14), %ecx
movq %r13, %rdi
movl -0x38(%rbp), %r13d
pushq $0x11
popq %rdx
callq 0x45ae0
addq $0x31, %r12
addq $0x4, %r14
jmp 0x42d19
leal (%r12,%r15), %eax
addl $0x16, %eax
movq %rax, -0x30(%rbp)
movq -0x88(%rbp), %r14
movq -0x90(%rbp), %r12
jmp 0x42b41
movq -0x30(%rbp), %rax
movl %eax, 0x9f0bc(%r14)
movq -0x68(%rbp), %rax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq