// File: DoubleString[P]RtConverter/src/Rtklib/rtcm.cpp
// Function: bamboo::gen_rtcm3(bamboo::rtcm_t*, int, int)
extern int gen_rtcm3(rtcm_t *rtcm, int type, int sync)
{
    unsigned int crc;
    int i=0;
    
    trace(4,"gen_rtcm3: type=%d sync=%d\n",type,sync);
    
    rtcm->nbit=rtcm->len=rtcm->nbyte=0;
    
    /* set preamble and reserved */
    setbitu(rtcm->buff,i, 8,RTCM3PREAMB); i+= 8;
    setbitu(rtcm->buff,i, 6,0          ); i+= 6;
    setbitu(rtcm->buff,i,10,0          ); i+=10;
    
    /* encode rtcm 3 message body */
    if (!encode_rtcm3(rtcm,type,sync)) return 0;
    
    /* padding to align 8 bit boundary */
    for (i=rtcm->nbit;i%8;i++) {
        setbitu(rtcm->buff,i,1,0);
    }
    /* message length (header+data) (bytes) */
    if ((rtcm->len=i/8)>=3+1024) {
        trace(2,"generate rtcm 3 message length error len=%d\n",rtcm->len-3);
        rtcm->nbit=rtcm->len=0;
        return 0;
    }
    /* message length without header and parity */
    setbitu(rtcm->buff,14,10,rtcm->len-3);
    
    /* crc-24q */
    crc=rtk_crc24q(rtcm->buff,rtcm->len);
    setbitu(rtcm->buff,i,24,crc);
    
    /* length total (bytes) */
    rtcm->nbyte=rtcm->len+3;
    
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x4, %edi
leaq 0x54f1d(%rip), %rsi     # 0xc0508
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rax
movl $0x0, 0x9f0b8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x9f0c0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x9f0bc(%rax)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl $0x8, %edx
movl $0xd3, %ecx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl $0x6, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl $0xa, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0xa, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x7cbb0
cmpl $0x0, %eax
jne 0x6b6a8
movl $0x0, -0x4(%rbp)
jmp 0x6b7c8
movq -0x10(%rbp), %rax
movl 0x9f0bc(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x6b6ea
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x6b6b5
movl -0x20(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movq -0x10(%rbp), %rcx
movl %eax, 0x9f0c0(%rcx)
cmpl $0x403, %eax            # imm = 0x403
jl 0x6b74b
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %edx
subl $0x3, %edx
movl $0x2, %edi
leaq 0x54e05(%rip), %rsi     # 0xc0524
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rax
movl $0x0, 0x9f0c0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x9f0bc(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6b7c8
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %ecx
subl $0x3, %ecx
movl $0xe, %esi
movl $0xa, %edx
callq 0x8c0d0
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %esi
callq 0x8c2d0
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x18, %edx
callq 0x8c0d0
movq -0x10(%rbp), %rax
movl 0x9f0c0(%rax), %ecx
addl $0x3, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x9f0b8(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)