// File: 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
subq $0xb0, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movl $0x18, -0x34(%rbp)
movl -0x8(%rbp), %edx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x1c(%rbp), %r9d
movl -0x20(%rbp), %esi
movsd -0x28(%rbp), %xmm0
movq %rsp, %rax
movl %esi, (%rax)
leaq 0x3a1bc(%rip), %rsi     # 0xc2803
movl $0x4, %edi
movb $0x1, %al
callq 0x8b980
movl -0x14(%rbp), %eax
subl $0x10, %eax
setne %al
movzbl %al, %ecx
movl %ecx, %eax
leal 0x4(%rax,%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x90(%rbp)
subl $0x1f, %eax
ja 0x887a1
movq -0x90(%rbp), %rax
leaq 0x39bcb(%rip), %rcx     # 0xc2258
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x7, -0x8(%rbp)
jne 0x886a9
movl $0xb, %eax
movl %eax, -0x94(%rbp)
jmp 0x886b7
movl -0x8(%rbp), %eax
addl $0x420, %eax            # imm = 0x420
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x887ad
cmpl $0x7, -0x8(%rbp)
jne 0x886d5
xorl %eax, %eax
movl %eax, -0x98(%rbp)
jmp 0x886e3
movl -0x8(%rbp), %eax
addl $0x426, %eax            # imm = 0x426
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x887ad
cmpl $0x7, -0x8(%rbp)
jne 0x88704
movl $0xc, %eax
movl %eax, -0x9c(%rbp)
jmp 0x88712
movl -0x8(%rbp), %eax
addl $0x4d7, %eax            # imm = 0x4D7
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x887ad
cmpl $0x7, -0x8(%rbp)
jne 0x88733
movl $0xd, %eax
movl %eax, -0xa0(%rbp)
jmp 0x88741
movl -0x8(%rbp), %eax
addl $0x4dd, %eax            # imm = 0x4DD
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x887ad
cmpl $0x7, -0x8(%rbp)
jne 0x8875f
movl $0xe, %eax
movl %eax, -0xa4(%rbp)
jmp 0x8876d
movl -0x8(%rbp), %eax
addl $0x4e9, %eax            # imm = 0x4E9
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x887ad
cmpl $0x7, -0x8(%rbp)
jne 0x88788
xorl %eax, %eax
movl %eax, -0xa8(%rbp)
jmp 0x88796
movl -0x8(%rbp), %eax
addl $0x4e3, %eax            # imm = 0x4E3
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x887ad
movl $0x0, -0x4(%rbp)
jmp 0x88a97
cmpl $0x0, -0x38(%rbp)
jne 0x887bf
movl $0x0, -0x4(%rbp)
jmp 0x88a97
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %ecx
movl $0xc, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x34(%rbp)
cmpl $0x4, -0x14(%rbp)
jne 0x8889e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x78(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x78(%rbp), %rdi
movsd -0x70(%rbp), %xmm0
callq 0x8ef80
movq %rax, -0x68(%rbp)
movsd %xmm0, -0x60(%rbp)
movq -0x68(%rbp), %rdi
movsd -0x60(%rbp), %xmm0
movsd 0x347c7(%rip), %xmm1    # 0xbcff0
callq 0x8e860
movq %rax, -0x58(%rbp)
movsd %xmm0, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
leaq -0x40(%rbp), %rsi
callq 0x8e540
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0x345c5(%rip), %xmm1    # 0xbce20
callq 0x99f0
movsd 0x34618(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl -0x3c(%rbp), %ecx
movl $0x11, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x11, %eax
movl %eax, -0x34(%rbp)
jmp 0x8890c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rdi
movsd -0x80(%rbp), %xmm0
leaq -0x40(%rbp), %rsi
callq 0x8e540
movsd %xmm0, -0x30(%rbp)
movsd 0x345a9(%rip), %xmm0    # 0xbce80
addsd -0x30(%rbp), %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl -0x3c(%rbp), %ecx
movl $0x14, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0xf, -0x44(%rbp)
jge 0x8893f
movslq -0x44(%rbp), %rcx
leaq 0x39abc(%rip), %rax     # 0xc23e0
movsd (%rax,%rcx,8), %xmm0
ucomisd -0x28(%rbp), %xmm0
jb 0x88932
jmp 0x8893f
jmp 0x88934
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x88913
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl -0x44(%rbp), %ecx
movl $0x4, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x1, -0x8(%rbp)
je 0x88993
cmpl $0x4, -0x8(%rbp)
jne 0x889b7
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl 0x10(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl -0x20(%rbp), %ecx
movl $0x4, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl 0x18(%rbp), %ecx
movl $0x10, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl 0x20(%rbp), %ecx
movl $0x4, %edx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x34(%rbp)
cmpl $0x7, -0x8(%rbp)
jne 0x88a6f
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x34(%rbp), %esi
movl -0x48(%rbp), %edx
movl -0x18(%rbp), %ecx
callq 0x8c0d0
movl -0x48(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)