// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_type1002(bamboo::rtcm_t*, int)
static int encode_type1002(rtcm_t *rtcm, int sync)
{
    int i,j,nsat=0,sys,prn;
    int code1,pr1,ppr1,lock1,amb,cnr1;
    
    trace(3,"encode_type1002: sync=%d\n",sync);
    
    for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
        sys=satsys(rtcm->obs.data[j].sat,&prn);
        if (!(sys&(SYS_GPS|SYS_SBS))) continue;
        nsat++;
    }
    /* encode header */
    i=encode_head(1002,rtcm,SYS_GPS,sync,nsat);
    
    for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
        sys=satsys(rtcm->obs.data[j].sat,&prn);
        if (!(sys&(SYS_GPS|SYS_SBS))) continue;
        
        if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */
        
        /* generate obs field data gps */
        gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb,&cnr1,
                    NULL,NULL,NULL,NULL,NULL);
        
        setbitu(rtcm->buff,i, 6,prn  ); i+= 6;
        setbitu(rtcm->buff,i, 1,code1); i+= 1;
        setbitu(rtcm->buff,i,24,pr1  ); i+=24;
        setbits(rtcm->buff,i,20,ppr1 ); i+=20;
        setbitu(rtcm->buff,i, 7,lock1); i+= 7;
        setbitu(rtcm->buff,i, 8,amb  ); i+= 8;
        setbitu(rtcm->buff,i, 8,cnr1 ); i+= 8;
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %edx
movq %rdi, %rbx
leaq 0x2b68b(%rip), %rsi     # 0x70306
xorl %r15d, %r15d
movl $0x3, %edi
movl %edx, -0x34(%rbp)
xorl %eax, %eax
callq 0x4ded0
cmpl $0x0, 0x30(%rbx)
jle 0x44ce0
xorl %r15d, %r15d
movl $0x10, %r13d
movl $0x1, %r14d
leaq -0x30(%rbp), %r12
movq 0x38(%rbx), %rax
movzbl (%rax,%r13), %edi
movq %r12, %rsi
callq 0x4dc2a
andl $0x3, %eax
cmpl $0x1, %eax
sbbl $-0x1, %r15d
movslq 0x30(%rbx), %rax
cmpl $0x40, %r15d
setb %cl
cmpq %rax, %r14
jge 0x44ce2
addq $0x60, %r13
incq %r14
cmpl $0x40, %r15d
jb 0x44ca6
jmp 0x44ce2
movb $0x1, %cl
movb %cl, -0x29(%rbp)
movl $0x3ea, %edi            # imm = 0x3EA
movq %rbx, %rsi
movl $0x1, %edx
movl -0x34(%rbp), %ecx
movl %r15d, %r8d
callq 0x4b5ce
movl %eax, %r14d
cmpl $0x0, 0x30(%rbx)
jle 0x44e37
cmpb $0x0, -0x29(%rbp)
je 0x44e37
leaq 0x9f0c4(%rbx), %r15
movl $0x1, %r12d
xorl %r13d, %r13d
movq 0x38(%rbx), %rax
movzbl 0x10(%rax,%r13), %edi
leaq -0x30(%rbp), %rsi
callq 0x4dc2a
testb $0x3, %al
je 0x44e1d
cmpl $0x2, %eax
jne 0x44d48
addl $-0x50, -0x30(%rbp)
movq 0x38(%rbx), %rsi
addq %r13, %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movups %xmm0, 0x10(%rsp)
leaq -0x38(%rbp), %rax
movq %rax, 0x8(%rsp)
leaq -0x3c(%rbp), %rax
movq %rax, (%rsp)
movq $0x0, 0x30(%rsp)
movq %rbx, %rdi
leaq -0x4c(%rbp), %rdx
leaq -0x48(%rbp), %rcx
leaq -0x44(%rbp), %r8
leaq -0x40(%rbp), %r9
callq 0x4b727
movl -0x30(%rbp), %ecx
movq %r15, %rdi
movl %r14d, %esi
movl $0x6, %edx
callq 0x4e403
leal 0x6(%r14), %esi
movl -0x4c(%rbp), %ecx
movq %r15, %rdi
movl $0x1, %edx
callq 0x4e403
leal 0x7(%r14), %esi
movl -0x48(%rbp), %ecx
movq %r15, %rdi
movl $0x18, %edx
callq 0x4e403
leal 0x1f(%r14), %esi
movl -0x44(%rbp), %ecx
movq %r15, %rdi
movl $0x14, %edx
callq 0x4e47b
leal 0x33(%r14), %esi
movl -0x40(%rbp), %ecx
movq %r15, %rdi
movl $0x7, %edx
callq 0x4e403
leal 0x3a(%r14), %esi
movl -0x3c(%rbp), %ecx
movq %r15, %rdi
movl $0x8, %edx
callq 0x4e403
leal 0x42(%r14), %esi
movl -0x38(%rbp), %ecx
movq %r15, %rdi
movl $0x8, %edx
callq 0x4e403
addl $0x4a, %r14d
movslq 0x30(%rbx), %rax
cmpq %rax, %r12
setl %al
addq $0x60, %r13
incq %r12
testb %al, -0x29(%rbp)
jne 0x44d24
movl %r14d, 0x9f0bc(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq