// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_ssr_head(int, bamboo::rtcm_t*, int, int, int, int, double, int, int, int)
static int encode_ssr_head(int type, rtcm_t *rtcm, int sys, int nsat, int sync,
                           int iod, double udint, int refd, int provid,
                           int solid)
{
    double tow;
    int i=24,msgno,epoch,week,udi,ns;
    
    trace(4,"encode_ssr_head: type=%d sys=%d nsat=%d sync=%d iod=%d udint=%.0f\n",
          type,sys,nsat,sync,iod,udint);
    
    ns=sys==SYS_QZS?4:6;
    
    switch (sys) {
        case SYS_GPS: msgno=(type==7)?11:1056+type; break;
        case SYS_GLO: msgno=(type==7)? 0:1062+type; break;
        case SYS_GAL: msgno=(type==7)?12:1239+type; break;
        case SYS_QZS: msgno=(type==7)?13:1245+type; break;
        case SYS_CMP: msgno=(type==7)?14:1257+type; break;
        case SYS_SBS: msgno=(type==7)? 0:1251+type; break;
        default: return 0;
    }
    if (msgno==0) {
        return 0;
    }
    setbitu(rtcm->buff,i,12,msgno    ); i+=12; /* message number */
    
    if (sys==SYS_GLO) {
        tow=time2gpst(timeadd(gpst2utc(rtcm->time),10800.0),&week);
        epoch=ROUND(fmod(tow,86400.0));
        setbitu(rtcm->buff,i,17,epoch); i+=17; /* glonass epoch time */
    }
    else {
        tow=time2gpst(rtcm->time,&week);
        epoch=ROUND(tow);
        setbitu(rtcm->buff,i,20,epoch); i+=20; /* gps epoch time */
    }
    for (udi=0;udi<15;udi++) {
        if (ssrudint[udi]>=udint) break;
    }
    setbitu(rtcm->buff,i, 4,udi    ); i+= 4; /* update interval */
    setbitu(rtcm->buff,i, 1,sync   ); i+= 1; /* multiple message indicator */
    if (type==1||type==4) {
        setbitu(rtcm->buff,i,1,refd); i+= 1; /* satellite ref datum */
    }
    setbitu(rtcm->buff,i, 4,iod    ); i+= 4; /* iod ssr */
    setbitu(rtcm->buff,i,16,provid ); i+=16; /* provider id */
    setbitu(rtcm->buff,i, 4,solid  ); i+= 4; /* solution id */
    if (type==7) {
        setbitu(rtcm->buff,i,1,0); i+=1; /* dispersive bias consistency ind */
        setbitu(rtcm->buff,i,1,0); i+=1; /* MW consistency indicator */
    }
    setbitu(rtcm->buff,i,ns,nsat   ); i+=ns; /* no of satellites */
    return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %eax
movl %ecx, %r8d
movl %edx, %r13d
movq %rsi, %rbx
movl %edi, %r14d
movl %r9d, -0x34(%rbp)
movl %r9d, (%rsp)
leaq 0x24e98(%rip), %rsi     # 0x70513
movl $0x4, %edi
movl %r14d, %edx
movl %r13d, %ecx
movl %r8d, -0x38(%rbp)
movl %eax, -0x30(%rbp)
movl %eax, %r9d
movsd %xmm0, -0x48(%rbp)
movb $0x1, %al
callq 0x4d55d
xorl %r12d, %r12d
cmpl $0x10, %r13d
setne %dl
xorl %r15d, %r15d
leal -0x1(%r13), %eax
cmpl $0x7, %eax
ja 0x4b6da
leaq 0x24853(%rip), %rcx     # 0x6ff0c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb %dl, -0x29(%rbp)
leal 0x420(%r14), %eax
cmpl $0x7, %r14d
movl $0xb, %ecx
jmp 0x4b7d9
cmpl $0x10, %r13d
je 0x4b7c6
cmpl $0x20, %r13d
jne 0x4b93c
movb %dl, -0x29(%rbp)
leal 0x4e9(%r14), %eax
cmpl $0x7, %r14d
movl $0xe, %ecx
jmp 0x4b7d9
movb %dl, -0x29(%rbp)
leal 0x4d7(%r14), %eax
cmpl $0x7, %r14d
movl $0xc, %ecx
jmp 0x4b7d9
cmpl $0x7, %r14d
je 0x4b93c
movb %dl, -0x29(%rbp)
leal 0x4e3(%r14), %ecx
jmp 0x4b7dc
cmpl $0x7, %r14d
je 0x4b93c
movb %dl, -0x29(%rbp)
leal 0x426(%r14), %ecx
leaq 0x9f0c4(%rbx), %r13
movq %r13, %rdi
movl $0x18, %esi
movl $0xc, %edx
callq 0x4da98
movq 0x10(%rbx), %rdi
movsd 0x18(%rbx), %xmm0
callq 0x4f9b0
movsd 0x1f336(%rip), %xmm1    # 0x6aab0
movq %rax, %rdi
callq 0x4f4e7
leaq -0x3c(%rbp), %rsi
movq %rax, %rdi
callq 0x4f2b1
movsd 0x1f13a(%rip), %xmm1    # 0x6a8d0
callq 0x8850
addsd 0x204d5(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
cvttsd2si %xmm0, %ecx
movq %r13, %rdi
movl $0x24, %esi
movl $0x11, %edx
callq 0x4da98
movl $0x35, %r15d
jmp 0x4b830
movb %dl, -0x29(%rbp)
leal 0x4dd(%r14), %eax
cmpl $0x7, %r14d
movl $0xd, %ecx
cmovnel %eax, %ecx
leaq 0x9f0c4(%rbx), %r13
movq %r13, %rdi
movl $0x18, %esi
movl $0xc, %edx
callq 0x4da98
movq 0x10(%rbx), %rdi
movsd 0x18(%rbx), %xmm0
leaq -0x3c(%rbp), %rsi
callq 0x4f2b1
addsd 0x20469(%rip), %xmm0    # 0x6bc78
callq 0x8ac0
cvttsd2si %xmm0, %ecx
movq %r13, %rdi
movl $0x24, %esi
movl $0x14, %edx
callq 0x4da98
movl $0x38, %r15d
movb -0x29(%rbp), %al
movb %al, %r12b
leal 0x4(,%r12,2), %ebx
leaq 0x2472b(%rip), %rax     # 0x6ff70
xorl %ecx, %ecx
movsd -0x48(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jae 0x4b868
incq %rcx
addq $0x8, %rax
cmpq $0xf, %rcx
jne 0x4b84c
movl $0xf, %ecx
movq %r13, %rdi
movl %r15d, %esi
movl $0x4, %edx
callq 0x4da98
leal 0x4(%r15), %esi
movq %r13, %rdi
movl $0x1, %edx
movl -0x30(%rbp), %ecx
callq 0x4da98
leal 0x5(%r15), %r12d
cmpl $0x4, %r14d
je 0x4b89c
cmpl $0x1, %r14d
jne 0x4b8b6
movq %r13, %rdi
movl %r12d, %esi
movl $0x1, %edx
movl 0x10(%rbp), %ecx
callq 0x4da98
addl $0x6, %r15d
movl %r15d, %r12d
movq %r13, %rdi
movl %r12d, %esi
movl $0x4, %edx
movl -0x34(%rbp), %ecx
callq 0x4da98
leal 0x4(%r12), %esi
movq %r13, %rdi
movl $0x10, %edx
xorl %ecx, %ecx
callq 0x4da98
leal 0x14(%r12), %esi
movq %r13, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x4da98
leal 0x18(%r12), %r15d
cmpl $0x7, %r14d
jne 0x4b929
movq %r13, %rdi
movl %r15d, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4da98
leal 0x19(%r12), %esi
movq %r13, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4da98
addl $0x1a, %r12d
movl %r12d, %r15d
movq %r13, %rdi
movl %r15d, %esi
movl %ebx, %edx
movl -0x38(%rbp), %ecx
callq 0x4da98
addl %ebx, %r15d
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq