// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %r8d, %r10d
movl %ecx, %r13d
movl %edx, %ebx
movq %rsi, %r15
movl %edi, %edx
movl %r9d, -0x40(%rbp)
movl %r9d, (%rsp)
leaq 0x22cea(%rip), %rsi     # 0x664f3
pushq $0x4
popq %rdi
movq %rdx, -0x38(%rbp)
movl %ebx, %ecx
movl %r13d, %r8d
movl %r10d, -0x3c(%rbp)
movl %r10d, %r9d
movsd %xmm0, -0x50(%rbp)
movb $0x1, %al
callq 0x455bc
xorl %r12d, %r12d
cmpl $0x10, %ebx
setne %al
xorl %r14d, %r14d
leal -0x1(%rbx), %ecx
cmpl $0x7, %ecx
ja 0x43861
leaq 0x22809(%rip), %rdx     # 0x6604c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl %r13d, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
leal 0x420(%rcx), %edx
cmpl $0x7, %ecx
pushq $0xb
jmp 0x438de
cmpl $0x10, %ebx
je 0x438cb
cmpl $0x20, %ebx
movq -0x38(%rbp), %rcx
jne 0x43a71
movl %r13d, -0x2c(%rbp)
leal 0x4e9(%rcx), %edx
cmpl $0x7, %ecx
pushq $0xe
jmp 0x438de
movl %r13d, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
leal 0x4d7(%rcx), %edx
cmpl $0x7, %ecx
pushq $0xc
jmp 0x438de
movq -0x38(%rbp), %rcx
cmpl $0x7, %ecx
je 0x43a71
movl %r13d, -0x2c(%rbp)
addl $0x4e3, %ecx            # imm = 0x4E3
jmp 0x438e2
movq -0x38(%rbp), %rcx
cmpl $0x7, %ecx
je 0x43a71
movl %r13d, -0x2c(%rbp)
addl $0x426, %ecx            # imm = 0x426
jmp 0x438e2
movl %r13d, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
leal 0x4dd(%rcx), %edx
cmpl $0x7, %ecx
pushq $0xd
popq %rcx
cmovnel %edx, %ecx
movb %al, %r12b
leaq 0x9f0c4(%r15), %r13
pushq $0x18
popq %rsi
pushq $0xc
popq %rdx
movq %r13, %rdi
callq 0x45a69
movq 0x10(%r15), %rdi
movsd 0x18(%r15), %xmm0
cmpl $0x4, %ebx
jne 0x4393f
callq 0x47732
movsd 0x1d18a(%rip), %xmm1    # 0x60aa0
movq %rax, %rdi
callq 0x472ee
leaq -0x44(%rbp), %rsi
movq %rax, %rdi
callq 0x470f1
movsd 0x1cf8e(%rip), %xmm1    # 0x608c0
callq 0x8840
pushq $0x35
popq %r15
pushq $0x11
jmp 0x4394e
leaq -0x44(%rbp), %rsi
callq 0x470f1
pushq $0x38
popq %r15
pushq $0x14
popq %r14
leal 0x4(,%r12,2), %ebx
addsd 0x1e318(%rip), %xmm0    # 0x61c78
callq 0x8ac0
cvttsd2si %xmm0, %ecx
pushq $0x24
popq %rsi
movq %r13, %rdi
movl %r14d, %edx
callq 0x45a69
leaq 0x22732(%rip), %rdx     # 0x660b0
xorl %eax, %eax
pushq $0xf
popq %rcx
movsd -0x50(%rbp), %xmm1
cmpq $0xf, %rax
je 0x439a3
movsd (%rdx), %xmm0
ucomisd %xmm1, %xmm0
jae 0x439a1
incq %rax
addq $0x8, %rdx
jmp 0x43988
movl %eax, %ecx
pushq $0x4
popq %rdx
movq %r13, %rdi
movl %r15d, %esi
callq 0x45a69
leal 0x4(%r15), %esi
pushq $0x1
popq %rdx
movq %r13, %rdi
movl -0x3c(%rbp), %ecx
callq 0x45a69
leal 0x5(%r15), %r12d
movq -0x38(%rbp), %rax
cmpl $0x4, %eax
je 0x439d5
cmpl $0x1, %eax
jne 0x439ed
pushq $0x1
popq %rdx
movq %r13, %rdi
movl %r12d, %esi
movl 0x10(%rbp), %ecx
callq 0x45a69
addl $0x6, %r15d
movl %r15d, %r12d
pushq $0x4
popq %r14
movq %r13, %rdi
movl %r12d, %esi
movl %r14d, %edx
movl -0x40(%rbp), %ecx
callq 0x45a69
leal 0x4(%r12), %esi
pushq $0x10
popq %rdx
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x45a69
leal 0x14(%r12), %esi
movq %r13, %rdi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x45a69
leal 0x18(%r12), %r14d
cmpl $0x7, -0x38(%rbp)
jne 0x43a5e
pushq $0x1
popq %r15
movq %r13, %rdi
movl %r14d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x45a69
leal 0x19(%r12), %esi
movq %r13, %rdi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x45a69
addl $0x1a, %r12d
movl %r12d, %r14d
movq %r13, %rdi
movl %r14d, %esi
movl %ebx, %edx
movl -0x2c(%rbp), %ecx
callq 0x45a69
addl %ebx, %r14d
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq