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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x18(%rbp)
movl -0xc(%rbp), %edx
movl $0x3, %edi
leaq 0x4492a(%rip), %rsi     # 0xc25af
movb $0x0, %al
callq 0x8b980
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x35(%rbp)
jge 0x7dcae
cmpl $0x40, -0x18(%rbp)
setl %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x7dcb7
jmp 0x7dcfb
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %edi
leaq -0x20(%rbp), %rsi
callq 0x8b3b0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x7dce7
jmp 0x7dcf0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7dc93
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl $0x3e9, %edi            # imm = 0x3E9
movl $0x1, %edx
callq 0x87580
movl %eax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x36(%rbp)
jge 0x7dd3a
cmpl $0x40, -0x18(%rbp)
setl %al
movb %al, -0x36(%rbp)
movb -0x36(%rbp), %al
testb $0x1, %al
jne 0x7dd46
jmp 0x7deb7
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %edi
leaq -0x20(%rbp), %rsi
callq 0x8b3b0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x7dd79
jmp 0x7dea9
cmpl $0x2, -0x1c(%rbp)
jne 0x7dd88
movl -0x20(%rbp), %eax
subl $0x50, %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movslq -0x14(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
leaq -0x24(%rbp), %rdx
leaq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %r8
leaq -0x30(%rbp), %r9
leaq -0x34(%rbp), %rax
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
callq 0x877f0
movq -0x8(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x10(%rbp), %esi
movl -0x20(%rbp), %ecx
movl $0x6, %edx
callq 0x8c0d0
movl -0x10(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x10(%rbp), %esi
movl -0x24(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x10(%rbp), %esi
movl -0x28(%rbp), %ecx
movl $0x18, %edx
callq 0x8c0d0
movl -0x10(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x10(%rbp), %esi
movl -0x2c(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x10(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x10(%rbp), %esi
movl -0x30(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x10(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x10(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7dd1f
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, %eax
addq $0x70, %rsp
popq %rbp
retq
nop