// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_type1012(bamboo::rtcm_t*, int)
static int encode_type1012(rtcm_t *rtcm, int sync)
{
    int i,j,nsat=0,sat,prn,fcn;
    int code1,pr1,ppr1,lock1,amb,cnr1,code2,pr21,ppr2,lock2,cnr2;
    
    trace(3,"encode_type1012: sync=%d\n",sync);
    
    for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
        sat=rtcm->obs.data[j].sat;
        if (satsys(sat,&prn)!=SYS_GLO) continue;
        nsat++;
    }
    /* encode header */
    i=encode_head(1012,rtcm,SYS_GLO,sync,nsat);
    
    for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
        sat=rtcm->obs.data[j].sat;
        if (satsys(sat,&prn)!=SYS_GLO) continue;
        fcn=fcn_glo(sat,rtcm);
        
        /* generate obs field data glonass */
        gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb,
                    &cnr1,&code2,&pr21,&ppr2,&lock2,&cnr2);
        
        if (fcn<0) fcn=0;
        setbitu(rtcm->buff,i, 6,prn  ); i+= 6;
        setbitu(rtcm->buff,i, 1,code1); i+= 1;
        setbitu(rtcm->buff,i, 5,fcn  ); i+= 5;
        setbitu(rtcm->buff,i,25,pr1  ); i+=25;
        setbits(rtcm->buff,i,20,ppr1 ); i+=20;
        setbitu(rtcm->buff,i, 7,lock1); i+= 7;
        setbitu(rtcm->buff,i, 7,amb  ); i+= 7;
        setbitu(rtcm->buff,i, 8,cnr1 ); i+= 8;
        setbitu(rtcm->buff,i, 2,code2); i+= 2;
        setbits(rtcm->buff,i,14,pr21 ); i+=14;
        setbits(rtcm->buff,i,20,ppr2 ); i+=20;
        setbitu(rtcm->buff,i, 7,lock2); i+= 7;
        setbitu(rtcm->buff,i, 8,cnr2 ); i+= 8;
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, -0x30(%rbp)
movl %esi, -0x34(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x34(%rbp), %edx
movl $0x3, %edi
leaq 0x42cad(%rip), %rsi     # 0xc26fe
movb $0x0, %al
callq 0x8b980
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x79(%rbp)
jge 0x7fa7a
cmpl $0x40, -0x40(%rbp)
setl %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x7fa83
jmp 0x7fac4
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
leaq -0x48(%rbp), %rsi
callq 0x8b3b0
cmpl $0x4, %eax
je 0x7fab0
jmp 0x7fab9
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x7fa5f
movq -0x30(%rbp), %rsi
movl -0x34(%rbp), %ecx
movl -0x40(%rbp), %r8d
movl $0x3f4, %edi            # imm = 0x3F4
movl $0x4, %edx
callq 0x87580
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x7a(%rbp)
jge 0x7fb03
cmpl $0x40, -0x40(%rbp)
setl %al
movb %al, -0x7a(%rbp)
movb -0x7a(%rbp), %al
testb $0x1, %al
jne 0x7fb0f
jmp 0x7fdaf
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
leaq -0x48(%rbp), %rsi
callq 0x8b3b0
cmpl $0x4, %eax
je 0x7fb3f
jmp 0x7fda1
movl -0x44(%rbp), %edi
movq -0x30(%rbp), %rsi
callq 0x87f70
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rsi
movslq -0x3c(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
movl -0x4c(%rbp), %edx
leaq -0x50(%rbp), %rcx
leaq -0x54(%rbp), %r8
leaq -0x58(%rbp), %r9
leaq -0x5c(%rbp), %r13
leaq -0x60(%rbp), %r12
leaq -0x64(%rbp), %r15
leaq -0x68(%rbp), %r14
leaq -0x6c(%rbp), %rbx
leaq -0x70(%rbp), %r11
leaq -0x74(%rbp), %r10
leaq -0x78(%rbp), %rax
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x87ff0
cmpl $0x0, -0x4c(%rbp)
jge 0x7fbcd
movl $0x0, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x6, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x50(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x4c(%rbp), %ecx
movl $0x5, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x54(%rbp), %ecx
movl $0x19, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x19, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x58(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x38(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x5c(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x60(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x64(%rbp), %ecx
movl $0x8, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x68(%rbp), %ecx
movl $0x2, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x6c(%rbp), %ecx
movl $0xe, %edx
callq 0x8c1d0
movl -0x38(%rbp), %eax
addl $0xe, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x70(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x38(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x74(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x38(%rbp), %esi
movl -0x78(%rbp), %ecx
movl $0x8, %edx
callq 0x8c0d0
movl -0x38(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x7fae8
movl -0x38(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)