// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_msm_head(int, bamboo::rtcm_t*, int, int, int*, int*, double*, double*, unsigned char*, double*, double*, double*, double*, unsigned char*, float*)
static int encode_msm_head(int type, rtcm_t *rtcm, int sys, int sync, int *nsat,
                           int *ncell, double *rrng, double *rrate,
                           unsigned char *info, double *psrng, double *phrng,
                           double *rate, double *lock, unsigned char *half,
                           float *cnr)
{
    double tow;
    unsigned char sat_ind[64]={0},sig_ind[32]={0},cell_ind[32*64]={0};
    unsigned int dow,epoch;
    int i=24,j,nsig=0;
    
    switch (sys) {
        case SYS_GPS: type+=1070; break;
        case SYS_GLO: type+=1080; break;
        case SYS_GAL: type+=1090; break;
        case SYS_QZS: type+=1110; break;
        case SYS_SBS: type+=1100; break;
        case SYS_CMP: type+=1120; break;
        default: return 0;
    }
    /* generate msm satellite, signal and cell index */
    gen_msm_index(rtcm,sys,nsat,&nsig,ncell,sat_ind,sig_ind,cell_ind);
    
    if (sys==SYS_GLO) {
        /* glonass time (dow + tod-ms) */
        tow=time2gpst(timeadd(gpst2utc(rtcm->time),10800.0),NULL);
        dow=(unsigned int)(tow/86400.0);
        epoch=(dow<<27)+ROUND_U(fmod(tow,86400.0)*1E3);
    }
    else if (sys==SYS_CMP) {
        /* beidou time (tow-ms) */
        epoch=ROUND_U(time2gpst(gpst2bdt(rtcm->time),NULL)*1E3);
    }
    else {
        /* gps, qzs and galileo time (tow-ms) */
        epoch=ROUND_U(time2gpst(rtcm->time,NULL)*1E3);
    }
    /* encode msm header (ref [15] table 3.5-78) */
    setbitu(rtcm->buff,i,12,type       ); i+=12; /* message number */
    setbitu(rtcm->buff,i,12,rtcm->staid); i+=12; /* reference station id */
    setbitu(rtcm->buff,i,30,epoch      ); i+=30; /* epoch time */
    setbitu(rtcm->buff,i, 1,sync       ); i+= 1; /* multiple message bit */
    setbitu(rtcm->buff,i, 3,rtcm->seqno); i+= 3; /* issue of data station */
    setbitu(rtcm->buff,i, 7,0          ); i+= 7; /* reserved */
    setbitu(rtcm->buff,i, 2,0          ); i+= 2; /* clock streering indicator */
    setbitu(rtcm->buff,i, 2,0          ); i+= 2; /* external clock indicator */
    setbitu(rtcm->buff,i, 1,0          ); i+= 1; /* smoothing indicator */
    setbitu(rtcm->buff,i, 3,0          ); i+= 3; /* smoothing interval */
    
    /* satellite mask */
    for (j=0;j<64;j++) {
        setbitu(rtcm->buff,i,1,sat_ind[j]?1:0); i+=1;
    }
    /* signal mask */
    for (j=0;j<32;j++) {
        setbitu(rtcm->buff,i,1,sig_ind[j]?1:0); i+=1;
    }
    /* cell mask */
    for (j=0;j<*nsat*nsig&&j<64;j++) {
        setbitu(rtcm->buff,i,1,cell_ind[j]?1:0); i+=1;
    }
    /* generate msm satellite data fields */
    gen_msm_sat(rtcm,sys,*nsat,sat_ind,rrng,rrate,info);
    
    /* generate msm signal data fields */
    gen_msm_sig(rtcm,sys,*nsat,nsig,*ncell,sat_ind,sig_ind,cell_ind,rrng,rrate,
                psrng,phrng,rate,lock,half,cnr);
    
    return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x998, %rsp            # imm = 0x998
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movl %edx, -0x3c(%rbp)
movl %ecx, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
leaq -0x8c0(%rbp), %rdi
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x93d0
movl $0x18, -0x8cc(%rbp)
movl $0x0, -0x8d4(%rbp)
movl -0x3c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x948(%rbp)
subl $0x1f, %eax
ja 0x88bc3
movq -0x948(%rbp), %rax
leaq 0x3976c(%rip), %rcx     # 0xc22d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x30(%rbp), %eax
addl $0x42e, %eax            # imm = 0x42E
movl %eax, -0x30(%rbp)
jmp 0x88bcf
movl -0x30(%rbp), %eax
addl $0x438, %eax            # imm = 0x438
movl %eax, -0x30(%rbp)
jmp 0x88bcf
movl -0x30(%rbp), %eax
addl $0x442, %eax            # imm = 0x442
movl %eax, -0x30(%rbp)
jmp 0x88bcf
movl -0x30(%rbp), %eax
addl $0x456, %eax            # imm = 0x456
movl %eax, -0x30(%rbp)
jmp 0x88bcf
movl -0x30(%rbp), %eax
addl $0x44c, %eax            # imm = 0x44C
movl %eax, -0x30(%rbp)
jmp 0x88bcf
movl -0x30(%rbp), %eax
addl $0x460, %eax            # imm = 0x460
movl %eax, -0x30(%rbp)
jmp 0x88bcf
movl $0x0, -0x2c(%rbp)
jmp 0x891d9
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %r8
leaq -0xa0(%rbp), %r9
leaq -0xc0(%rbp), %r10
leaq -0x8c0(%rbp), %rax
leaq -0x8d4(%rbp), %rcx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x89410
cmpl $0x4, -0x3c(%rbp)
jne 0x88cf6
movq -0x38(%rbp), %rax
movups 0x10(%rax), %xmm0
movaps %xmm0, -0x910(%rbp)
movq -0x910(%rbp), %rdi
movsd -0x908(%rbp), %xmm0
callq 0x8ef80
movq %rax, -0x8f8(%rbp)
movsd %xmm0, -0x8f0(%rbp)
movq -0x8f8(%rbp), %rdi
movsd -0x8f0(%rbp), %xmm0
movsd 0x34395(%rip), %xmm1    # 0xbcff0
callq 0x8e860
movq %rax, -0x8e8(%rbp)
movsd %xmm0, -0x8e0(%rbp)
movq -0x8e8(%rbp), %rdi
movsd -0x8e0(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %esi
callq 0x8e540
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd 0x34187(%rip), %xmm1    # 0xbce20
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x8c4(%rbp)
movl -0x8c4(%rbp), %eax
shll $0x1b, %eax
movl %eax, -0x94c(%rbp)
movsd -0x58(%rbp), %xmm0
callq 0x99f0
movsd 0x3475f(%rip), %xmm1    # 0xbd428
mulsd %xmm1, %xmm0
movsd 0x341ab(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
movl -0x94c(%rbp), %eax
cvttsd2si %xmm0, %rcx
addl %ecx, %eax
movl %eax, -0x8c8(%rbp)
jmp 0x88dc1
cmpl $0x20, -0x3c(%rbp)
jne 0x88d70
movq -0x38(%rbp), %rax
movups 0x10(%rax), %xmm0
movaps %xmm0, -0x930(%rbp)
movq -0x930(%rbp), %rdi
movsd -0x928(%rbp), %xmm0
callq 0x8f1c0
movq %rax, -0x920(%rbp)
movsd %xmm0, -0x918(%rbp)
movq -0x920(%rbp), %rdi
movsd -0x918(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %esi
callq 0x8e540
movsd 0x346da(%rip), %xmm1    # 0xbd428
mulsd %xmm1, %xmm0
movsd 0x34126(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %rax
movl %eax, -0x8c8(%rbp)
jmp 0x88dbf
movq -0x38(%rbp), %rax
movups 0x10(%rax), %xmm0
movaps %xmm0, -0x940(%rbp)
movq -0x940(%rbp), %rdi
movsd -0x938(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %esi
callq 0x8e540
movsd 0x34689(%rip), %xmm1    # 0xbd428
mulsd %xmm1, %xmm0
movsd 0x340d5(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %rax
movl %eax, -0x8c8(%rbp)
jmp 0x88dc1
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl -0x30(%rbp), %ecx
movl $0xc, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movq -0x38(%rbp), %rax
movl (%rax), %ecx
movl $0xc, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl -0x8c8(%rbp), %ecx
movl $0x1e, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x1e, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl -0x40(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
movl $0x3, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl $0x7, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8cc(%rbp)
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movl $0x3, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x8cc(%rbp)
movl $0x0, -0x8d0(%rbp)
cmpl $0x40, -0x8d0(%rbp)
jge 0x88ff1
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movslq -0x8d0(%rbp), %rax
movb -0xa0(%rbp,%rax), %dl
xorl %ecx, %ecx
movl $0x1, %eax
cmpb $0x0, %dl
cmovnel %eax, %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8cc(%rbp)
movl -0x8d0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d0(%rbp)
jmp 0x88f92
movl $0x0, -0x8d0(%rbp)
cmpl $0x20, -0x8d0(%rbp)
jge 0x8905a
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movslq -0x8d0(%rbp), %rax
movb -0xc0(%rbp,%rax), %dl
xorl %ecx, %ecx
movl $0x1, %eax
cmpb $0x0, %dl
cmovnel %eax, %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8cc(%rbp)
movl -0x8d0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d0(%rbp)
jmp 0x88ffb
movl $0x0, -0x8d0(%rbp)
movl -0x8d0(%rbp), %ecx
movq -0x48(%rbp), %rax
movl (%rax), %edx
imull -0x8d4(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x94d(%rbp)
jge 0x89093
cmpl $0x40, -0x8d0(%rbp)
setl %al
movb %al, -0x94d(%rbp)
movb -0x94d(%rbp), %al
testb $0x1, %al
jne 0x8909f
jmp 0x890f8
movq -0x38(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x8cc(%rbp), %esi
movslq -0x8d0(%rbp), %rax
movb -0x8c0(%rbp,%rax), %dl
xorl %ecx, %ecx
movl $0x1, %eax
cmpb $0x0, %dl
cmovnel %eax, %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x8cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8cc(%rbp)
movl -0x8d0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d0(%rbp)
jmp 0x89064
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
movq -0x48(%rbp), %rax
movl (%rax), %edx
leaq -0xa0(%rbp), %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x20(%rbp), %rax
movq %rax, (%rsp)
callq 0x896e0
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
movq -0x48(%rbp), %rax
movl (%rax), %edx
movl -0x8d4(%rbp), %ecx
movq -0x50(%rbp), %rax
movl (%rax), %r8d
leaq -0xa0(%rbp), %r9
leaq -0xc0(%rbp), %rax
movq %rax, -0x968(%rbp)
leaq -0x8c0(%rbp), %rax
movq %rax, -0x960(%rbp)
movq 0x10(%rbp), %r13
movq 0x18(%rbp), %r12
movq 0x28(%rbp), %r15
movq 0x30(%rbp), %r14
movq 0x38(%rbp), %rbx
movq 0x40(%rbp), %r11
movq 0x48(%rbp), %r10
movq 0x50(%rbp), %rax
movq %rax, -0x958(%rbp)
movq -0x968(%rbp), %rax
movq %rax, (%rsp)
movq -0x960(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x958(%rbp), %rax
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x899b0
movl -0x8cc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x998, %rsp            # imm = 0x998
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop