// File: 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 %r14
pushq %rbx
subq $0x80, %rsp
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x1c(%rbp), %edx
movl $0x3, %edi
leaq 0x44455(%rip), %rsi     # 0xc2610
movb $0x0, %al
callq 0x8b980
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x55(%rbp)
jge 0x7e1e4
cmpl $0x40, -0x28(%rbp)
setl %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x7e1ed
jmp 0x7e231
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %edi
leaq -0x30(%rbp), %rsi
callq 0x8b3b0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x7e21d
jmp 0x7e226
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7e1c9
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %ecx
movl -0x28(%rbp), %r8d
movl $0x3eb, %edi            # imm = 0x3EB
movl $0x1, %edx
callq 0x87580
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x56(%rbp)
jge 0x7e270
cmpl $0x40, -0x28(%rbp)
setl %al
movb %al, -0x56(%rbp)
movb -0x56(%rbp), %al
testb $0x1, %al
jne 0x7e27c
jmp 0x7e47c
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %edi
leaq -0x30(%rbp), %rsi
callq 0x8b3b0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x7e2af
jmp 0x7e46e
cmpl $0x2, -0x2c(%rbp)
jne 0x7e2be
movl -0x30(%rbp), %eax
subl $0x50, %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
movslq -0x24(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
leaq -0x34(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x3c(%rbp), %r8
leaq -0x40(%rbp), %r9
leaq -0x44(%rbp), %r14
xorl %eax, %eax
leaq -0x48(%rbp), %rbx
leaq -0x4c(%rbp), %r11
leaq -0x50(%rbp), %r10
leaq -0x54(%rbp), %rax
movq %r14, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
callq 0x877f0
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x30(%rbp), %ecx
movl $0x6, %edx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x34(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x38(%rbp), %ecx
movl $0x18, %edx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x3c(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x20(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x40(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x2, %edx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x4c(%rbp), %ecx
movl $0xe, %edx
callq 0x8c1d0
movl -0x20(%rbp), %eax
addl $0xe, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x50(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x20(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x20(%rbp), %esi
movl -0x54(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x20(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x20(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7e255
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, %eax
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw (%rax,%rax)