// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_head(int, bamboo::rtcm_t*, int, int, int)
static int encode_head(int type, rtcm_t *rtcm, int sys, int sync, int nsat)
{
    double tow;
    int i=24,week,epoch;
    
    trace(4,"encode_head: type=%d sync=%d sys=%d nsat=%d\n",type,sync,sys,nsat);
    
    setbitu(rtcm->buff,i,12,type       ); i+=12; /* message no */
    setbitu(rtcm->buff,i,12,rtcm->staid); i+=12; /* ref station id */
    
    if (sys==SYS_GLO) {
        tow=time2gpst(timeadd(gpst2utc(rtcm->time),10800.0),&week);
        epoch=ROUND(fmod(tow,86400.0)/0.001);
        setbitu(rtcm->buff,i,27,epoch); i+=27; /* glonass epoch time */
    }
    else {
        tow=time2gpst(rtcm->time,&week);
        epoch=ROUND(tow/0.001);
        setbitu(rtcm->buff,i,30,epoch); i+=30; /* gps epoch time */
    }
    setbitu(rtcm->buff,i, 1,sync); i+= 1; /* synchronous gnss flag */
    setbitu(rtcm->buff,i, 5,nsat); i+= 5; /* no of satellites */
    setbitu(rtcm->buff,i, 1,0   ); i+= 1; /* smoothing indicator */
    setbitu(rtcm->buff,i, 3,0   ); i+= 3; /* smoothing interval */
    return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl $0x18, -0x2c(%rbp)
movl -0x4(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0x14(%rbp), %r8d
movl -0x1c(%rbp), %r9d
movl $0x4, %edi
leaq 0x3b00c(%rip), %rsi     # 0xc25c9
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x4(%rbp), %ecx
movl $0xc, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movl $0xc, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x4, -0x14(%rbp)
jne 0x876d6
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x68(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rdi
movsd -0x60(%rbp), %xmm0
callq 0x8ef80
movq %rax, -0x58(%rbp)
movsd %xmm0, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movsd -0x50(%rbp), %xmm0
movsd 0x3599b(%rip), %xmm1    # 0xbcff0
callq 0x8e860
movq %rax, -0x48(%rbp)
movsd %xmm0, -0x40(%rbp)
movq -0x48(%rbp), %rdi
movsd -0x40(%rbp), %xmm0
leaq -0x30(%rbp), %rsi
callq 0x8e540
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x35799(%rip), %xmm1    # 0xbce20
callq 0x99f0
movsd 0x366b4(%rip), %xmm1    # 0xbdd48
divsd %xmm1, %xmm0
movsd 0x357e0(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x34(%rbp), %ecx
movl $0x1b, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x1b, %eax
movl %eax, -0x2c(%rbp)
jmp 0x8774e
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
leaq -0x30(%rbp), %rsi
callq 0x8e540
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x3663a(%rip), %xmm1    # 0xbdd48
divsd %xmm1, %xmm0
movsd 0x35766(%rip), %xmm1    # 0xbce80
addsd %xmm1, %xmm0
callq 0x9c90
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x34(%rbp), %ecx
movl $0x1e, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x1e, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x18(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x5, %edx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x2c(%rbp), %esi
movl $0x3, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x2c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)