// File: DoubleString[P]RtConverter/src/Rtklib/rtcm3e.cpp
// Function: bamboo::encode_type1004(bamboo::rtcm_t*, int)
static int encode_type1004(rtcm_t *rtcm, int sync)
{
    int i,j,nsat=0,sys,prn;
    int code1,pr1,ppr1,lock1,amb,cnr1,code2,pr21,ppr2,lock2,cnr2;
    
    trace(3,"encode_type1004: 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(1004,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,&code2,&pr21,&ppr2,&lock2,&cnr2);
        
        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;
        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 %r12
pushq %rbx
subq $0x90, %rsp
movq %rdi, -0x28(%rbp)
movl %esi, -0x2c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x2c(%rbp), %edx
movl $0x3, %edi
leaq 0x4415b(%rip), %rsi     # 0xc262a
movb $0x0, %al
callq 0x8b980
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x6d(%rbp)
jge 0x7e4f8
cmpl $0x40, -0x38(%rbp)
setl %al
movb %al, -0x6d(%rbp)
movb -0x6d(%rbp), %al
testb $0x1, %al
jne 0x7e501
jmp 0x7e545
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %edi
leaq -0x40(%rbp), %rsi
callq 0x8b3b0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x7e531
jmp 0x7e53a
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x7e4dd
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %ecx
movl -0x38(%rbp), %r8d
movl $0x3ec, %edi            # imm = 0x3EC
movl $0x1, %edx
callq 0x87580
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x6e(%rbp)
jge 0x7e584
cmpl $0x40, -0x38(%rbp)
setl %al
movb %al, -0x6e(%rbp)
movb -0x6e(%rbp), %al
testb $0x1, %al
jne 0x7e590
jmp 0x7e7fa
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movzbl 0x10(%rax), %edi
leaq -0x40(%rbp), %rsi
callq 0x8b3b0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x7e5c3
jmp 0x7e7ec
cmpl $0x2, -0x3c(%rbp)
jne 0x7e5d2
movl -0x40(%rbp), %eax
subl $0x50, %eax
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rsi
movslq -0x34(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
leaq -0x44(%rbp), %rdx
leaq -0x48(%rbp), %rcx
leaq -0x4c(%rbp), %r8
leaq -0x50(%rbp), %r9
leaq -0x54(%rbp), %r12
leaq -0x58(%rbp), %r15
leaq -0x5c(%rbp), %r14
leaq -0x60(%rbp), %rbx
leaq -0x64(%rbp), %r11
leaq -0x68(%rbp), %r10
leaq -0x6c(%rbp), %rax
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq %r11, 0x20(%rsp)
movq %r10, 0x28(%rsp)
movq %rax, 0x30(%rsp)
callq 0x877f0
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x40(%rbp), %ecx
movl $0x6, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x44(%rbp), %ecx
movl $0x1, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x18, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x4c(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x30(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x50(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x54(%rbp), %ecx
movl $0x8, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x58(%rbp), %ecx
movl $0x8, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x5c(%rbp), %ecx
movl $0x2, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x60(%rbp), %ecx
movl $0xe, %edx
callq 0x8c1d0
movl -0x30(%rbp), %eax
addl $0xe, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x64(%rbp), %ecx
movl $0x14, %edx
callq 0x8c1d0
movl -0x30(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x68(%rbp), %ecx
movl $0x7, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
addq $0x9f0c4, %rdi          # imm = 0x9F0C4
movl -0x30(%rbp), %esi
movl -0x6c(%rbp), %ecx
movl $0x8, %edx
callq 0x8c0d0
movl -0x30(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x7e569
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x9f0bc(%rax)
movl $0x1, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)