// File: /workspace/github_cpp_makefile_star2_O1/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, %r13d
movl %edx, %ebx
movq %rsi, %r15
movl %edi, %r14d
movl %r9d, -0x34(%rbp)
movl %r9d, (%rsp)
leaq 0x244ea(%rip), %rsi     # 0x70513
movl $0x4, %edi
movl %r14d, %edx
movl %ebx, %ecx
movl %r13d, %r8d
movl %eax, -0x30(%rbp)
movl %eax, %r9d
movsd %xmm0, -0x48(%rbp)
movb $0x1, %al
callq 0x4ded0
xorl %esi, %esi
cmpl $0x10, %ebx
setne %al
xorl %r12d, %r12d
leal -0x1(%rbx), %ecx
cmpl $0x7, %ecx
ja 0x4c077
leaq 0x23eaa(%rip), %rdx     # 0x6ff0c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0xb, %edx
movl $0x420, %ecx            # imm = 0x420
jmp 0x4c0b9
cmpl $0x10, %ebx
je 0x4c0af
cmpl $0x20, %ebx
jne 0x4c277
movl $0xe, %edx
movl $0x4e9, %ecx            # imm = 0x4E9
jmp 0x4c0b9
movl $0xc, %edx
movl $0x4d7, %ecx            # imm = 0x4D7
jmp 0x4c0b9
xorl %edx, %edx
movl $0x4e3, %ecx            # imm = 0x4E3
jmp 0x4c0b9
xorl %edx, %edx
movl $0x426, %ecx            # imm = 0x426
jmp 0x4c0b9
movl $0xd, %edx
movl $0x4dd, %ecx            # imm = 0x4DD
addl %r14d, %ecx
cmpl $0x7, %r14d
cmovel %edx, %ecx
testl %ecx, %ecx
je 0x4c277
movl %r13d, -0x2c(%rbp)
movb %al, %sil
movq %rsi, -0x40(%rbp)
leaq 0x9f0c4(%r15), %r13
movq %r13, %rdi
movl $0x18, %esi
movl $0xc, %edx
callq 0x4e403
movq 0x10(%r15), %rdi
movsd 0x18(%r15), %xmm0
cmpl $0x4, %ebx
jne 0x4c13a
callq 0x5034e
movsd 0x1e9a5(%rip), %xmm1    # 0x6aab0
movq %rax, %rdi
callq 0x4fe63
leaq -0x38(%rbp), %rsi
movq %rax, %rdi
callq 0x4fc2d
movsd 0x1e7a9(%rip), %xmm1    # 0x6a8d0
callq 0x8860
movl $0x35, %r12d
movl $0x11, %r15d
jmp 0x4c14f
leaq -0x38(%rbp), %rsi
callq 0x4fc2d
movl $0x38, %r12d
movl $0x14, %r15d
movq -0x40(%rbp), %rax
leal 0x4(,%rax,2), %ebx
addsd 0x1fb16(%rip), %xmm0    # 0x6bc78
callq 0x8ad0
cvttsd2si %xmm0, %ecx
movq %r13, %rdi
movl $0x24, %esi
movl %r15d, %edx
callq 0x4e403
leaq 0x23dee(%rip), %rax     # 0x6ff70
xorl %ecx, %ecx
movsd -0x48(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jae 0x4c1a5
incq %rcx
addq $0x8, %rax
cmpq $0xf, %rcx
jne 0x4c189
movl $0xf, %ecx
movq %r13, %rdi
movl %r12d, %esi
movl $0x4, %edx
callq 0x4e403
leal 0x4(%r12), %esi
movq %r13, %rdi
movl $0x1, %edx
movl -0x30(%rbp), %ecx
callq 0x4e403
leal 0x5(%r12), %r15d
cmpl $0x4, %r14d
je 0x4c1db
cmpl $0x1, %r14d
jne 0x4c1f5
movq %r13, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl 0x10(%rbp), %ecx
callq 0x4e403
addl $0x6, %r12d
movl %r12d, %r15d
movq %r13, %rdi
movl %r15d, %esi
movl $0x4, %edx
movl -0x34(%rbp), %ecx
callq 0x4e403
leal 0x4(%r15), %esi
movq %r13, %rdi
movl $0x10, %edx
xorl %ecx, %ecx
callq 0x4e403
leal 0x14(%r15), %esi
movq %r13, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x4e403
leal 0x18(%r15), %r12d
cmpl $0x7, %r14d
jne 0x4c264
movq %r13, %rdi
movl %r12d, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4e403
leal 0x19(%r15), %esi
movq %r13, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4e403
addl $0x1a, %r15d
movl %r15d, %r12d
movq %r13, %rdi
movl %r12d, %esi
movl %ebx, %edx
movl -0x2c(%rbp), %ecx
callq 0x4e403
addl %ebx, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq