// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_type1003(bamboo::rtcm_t*, int)
static int encode_type1003(rtcm_t *rtcm, int sync)
{
    int i,j,nsat=0,sys,prn;
    int code1,pr1,ppr1,lock1,amb,code2,pr21,ppr2,lock2;
    
    trace(3,"encode_type1003: 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(1003,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,
                    NULL,&code2,&pr21,&ppr2,&lock2,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, 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;
    }
    rtcm->nbit=i;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %edx
movq %rdi, %rbx
leaq 0x2bddc(%rip), %rsi     # 0x70320
xorl %r15d, %r15d
movl $0x3, %edi
movl %edx, -0x30(%rbp)
xorl %eax, %eax
callq 0x4d55d
cmpl $0x0, 0x30(%rbx)
jle 0x445a7
xorl %r15d, %r15d
movl $0x10, %r13d
movl $0x1, %r14d
movq 0x38(%rbx), %rax
movzbl (%rax,%r13), %edi
leaq -0x2c(%rbp), %rsi
callq 0x4d2f2
andl $0x3, %eax
cmpl $0x1, %eax
sbbl $-0x1, %r15d
movslq 0x30(%rbx), %rax
cmpl $0x40, %r15d
setb %r12b
cmpq %rax, %r14
jge 0x445aa
addq $0x60, %r13
incq %r14
cmpl $0x40, %r15d
jb 0x4456b
jmp 0x445aa
movb $0x1, %r12b
movl $0x3eb, %edi            # imm = 0x3EB
movq %rbx, %rsi
movl $0x1, %edx
movl -0x30(%rbp), %ecx
movl %r15d, %r8d
callq 0x4ac42
movl %eax, %r14d
cmpl $0x0, 0x30(%rbx)
jle 0x4471c
testb %r12b, %r12b
je 0x4471c
leaq 0x9f0c4(%rbx), %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x38(%rbx), %rax
movzbl 0x10(%rax,%r12), %edi
leaq -0x2c(%rbp), %rsi
callq 0x4d2f2
testb $0x3, %al
je 0x44708
cmpl $0x2, %eax
jne 0x44609
addl $-0x50, -0x2c(%rbp)
movq 0x38(%rbx), %rsi
addq %r12, %rsi
subq $0x8, %rsp
movq %rbx, %rdi
leaq -0x50(%rbp), %rdx
leaq -0x4c(%rbp), %rcx
leaq -0x48(%rbp), %r8
leaq -0x44(%rbp), %r9
xorl %eax, %eax
pushq %rax
leaq -0x34(%rbp), %r10
pushq %r10
leaq -0x38(%rbp), %r10
pushq %r10
leaq -0x3c(%rbp), %r10
pushq %r10
leaq -0x40(%rbp), %r10
pushq %r10
pushq %rax
leaq -0x54(%rbp), %rax
pushq %rax
callq 0x4ad9b
addq $0x40, %rsp
movl -0x2c(%rbp), %ecx
movq %r15, %rdi
movl %r14d, %esi
movl $0x6, %edx
callq 0x4da98
leal 0x6(%r14), %esi
movl -0x50(%rbp), %ecx
movq %r15, %rdi
movl $0x1, %edx
callq 0x4da98
leal 0x7(%r14), %esi
movl -0x4c(%rbp), %ecx
movq %r15, %rdi
movl $0x18, %edx
callq 0x4da98
leal 0x1f(%r14), %esi
movl -0x48(%rbp), %ecx
movq %r15, %rdi
movl $0x14, %edx
callq 0x4db0c
leal 0x33(%r14), %esi
movl -0x44(%rbp), %ecx
movq %r15, %rdi
movl $0x7, %edx
callq 0x4da98
leal 0x3a(%r14), %esi
movl -0x40(%rbp), %ecx
movq %r15, %rdi
movl $0x2, %edx
callq 0x4da98
leal 0x3c(%r14), %esi
movl -0x3c(%rbp), %ecx
movq %r15, %rdi
movl $0xe, %edx
callq 0x4db0c
leal 0x4a(%r14), %esi
movl -0x38(%rbp), %ecx
movq %r15, %rdi
movl $0x14, %edx
callq 0x4db0c
leal 0x5e(%r14), %esi
movl -0x34(%rbp), %ecx
movq %r15, %rdi
movl $0x7, %edx
callq 0x4da98
addl $0x65, %r14d
incq %r13
movslq 0x30(%rbx), %rax
addq $0x60, %r12
cmpq %rax, %r13
jl 0x445e5
movl %r14d, 0x9f0bc(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq