// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Encoder/RtcmExEncoder.cpp
// Function: bamboo::RtcmExEncoder::m_encodeObsMsg(char const*, bamboo::gtime_t, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bamboo::RtSatObs, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, bamboo::RtSatObs>>>&)
int RtcmExEncoder::m_encodeObsMsg(const char* sitname,gtime_t tt,map<string, RtSatObs>& obs_in){
	int isys,ifreq,gotobs[MAXSYS] = { 0 },lsync,wk;
	char code[8];
	time2gpst(tt,&wk);
	strncpy(buff + 3,sitname,4);
	setbitu((unsigned char*)buff, 7 * 8, 16, wk); /*set the gps week here*/
	m_rtcm.obs.n = 0;
	m_rtcm.time = tt;
	map<string,RtSatObs>::iterator mapItr;
	for(mapItr = obs_in.begin();mapItr != obs_in.end();++mapItr){
		string cprn = (*mapItr).first;
		RtSatObs& obs = (*mapItr).second;
		isys = index_string(SYS, cprn[0]);
		gotobs[isys] = 1;
		m_rtcm.obs.data[m_rtcm.obs.n].sat = satid2no(cprn.c_str());
		if(m_rtcm.obs.data[m_rtcm.obs.n].sat == 0) continue;
		for(ifreq = 0;ifreq < MAXFREQ;ifreq++){
			m_rtcm.obs.data[m_rtcm.obs.n].L[ifreq] = obs.obs[ifreq];
			m_rtcm.obs.data[m_rtcm.obs.n].P[ifreq] = obs.obs[MAXFREQ + ifreq];
			m_rtcm.obs.data[m_rtcm.obs.n].SNR[ifreq] = static_cast<unsigned char>(obs.snr[ifreq] / 0.25);
			strcpy(code, obs.fob[MAXFREQ + ifreq].c_str());
			if (cprn[0] == 'C' && code[1] == '2')
				code[1] = '1';
			if (cprn[0] == 'G' && code[1] == '2')
				strcpy(code, "L2W");
			m_rtcm.obs.data[m_rtcm.obs.n].code[ifreq] = obs2code(code + 1, NULL);
		}
		m_rtcm.obs.n++;
	}
	nbyte = 3 + 4 + 2; // pre,len,sitname
	/////////////////// GPS /////////////////
	if (gotobs[index_string(SYS, 'G')]) {
		lsync = gotobs[index_string(SYS, 'C')] || gotobs[index_string(SYS, 'R')] || gotobs[index_string(SYS, 'E')];
		gen_rtcm3(&m_rtcm, 1074, lsync);
		if(nbyte + m_rtcm.nbyte >  sizeof(buff) - 4) return 0;
		memcpy(buff + nbyte, m_rtcm.buff, m_rtcm.nbyte);
		nbyte = nbyte + m_rtcm.nbyte;
	}
	////////////////// BDS ////////////////
	if (gotobs[index_string(SYS, 'C')]) {
		lsync = gotobs[index_string(SYS, 'R')] || gotobs[index_string(SYS, 'E')];
		gen_rtcm3(&m_rtcm, 1124, lsync);
		if(nbyte + m_rtcm.nbyte >  sizeof(buff) - 4) return 0;
		memcpy(buff + nbyte, m_rtcm.buff, m_rtcm.nbyte);
		nbyte = nbyte + m_rtcm.nbyte;
	}
	//////////////////// GLO ////////////////
	if (gotobs[index_string(SYS, 'R')]) {
		lsync = gotobs[index_string(SYS, 'E')];
		gen_rtcm3(&m_rtcm, 1084, lsync);
		if(nbyte + m_rtcm.nbyte >  sizeof(buff) - 4) return 0;
		memcpy(buff + nbyte, m_rtcm.buff, m_rtcm.nbyte);
		nbyte = nbyte + m_rtcm.nbyte;
	}
	if (gotobs[index_string(SYS, 'E')]) {
		gen_rtcm3(&m_rtcm, 1094, 0);
		if(nbyte + m_rtcm.nbyte >  sizeof(buff) - 4) return 0;
		memcpy(buff + nbyte, m_rtcm.buff, m_rtcm.nbyte);
		nbyte = nbyte + m_rtcm.nbyte;
	}
	return nbyte * 8;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r12
movsd %xmm0, -0x38(%rbp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorps %xmm1, %xmm1
movups %xmm1, -0x54(%rbp)
movaps %xmm1, -0x60(%rbp)
leaq -0x6c(%rbp), %r13
movq %rdx, %rdi
movq %r13, %rsi
callq 0x470f1
leaq 0x3(%rbx), %rdi
pushq $0x4
popq %rdx
movq %r15, %rsi
callq 0x8360
movl (%r13), %ecx
pushq $0x38
popq %rsi
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x45a69
andl $0x0, 0x840(%rbx)
leaq 0x810(%rbx), %rax
movq %rax, -0x68(%rbp)
movq %r14, 0x820(%rbx)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x828(%rbx)
movq 0x18(%r12), %r13
addq $0x8, %r12
movq %r12, -0x38(%rbp)
leaq -0x90(%rbp), %r14
leaq -0x30(%rbp), %r15
cmpq -0x38(%rbp), %r13
je 0x198cf
leaq 0x20(%r13), %rsi
movq %r14, %rdi
callq 0x8870
movq -0x90(%rbp), %rax
movsbl (%rax), %esi
leaq 0x470f4(%rip), %rdi     # 0x608a0
callq 0x1a5f7
cltq
movl $0x1, -0x60(%rbp,%rax,4)
movq -0x90(%rbp), %rdi
callq 0x453cc
movq 0x848(%rbx), %rcx
movslq 0x840(%rbx), %rdx
imulq $0x60, %rdx, %rdx
movb %al, 0x10(%rcx,%rdx)
testb %al, %al
je 0x198b7
movl $0xe8, %r14d
pushq $0x18
popq %r12
cmpq $0x1b, %r12
je 0x198aa
movsd -0x80(%r13,%r12,8), %xmm0
movslq 0x840(%rbx), %rax
imulq $0x60, %rax, %rax
addq 0x848(%rbx), %rax
movsd %xmm0, -0xa0(%rax,%r12,8)
movsd -0x68(%r13,%r12,8), %xmm0
movsd %xmm0, -0x88(%rax,%r12,8)
movsd -0x50(%r13,%r12,8), %xmm0
mulsd 0x4705c(%rip), %xmm0    # 0x60898
cvttsd2si %xmm0, %ecx
movb %cl, -0x6(%r12,%rax)
movq (%r13,%r14), %rsi
movq %r15, %rdi
callq 0x85c0
movq -0x90(%rbp), %rax
movb (%rax), %al
movl %eax, %edx
xorb $0x43, %dl
movb -0x2f(%rbp), %cl
xorb $0x32, %cl
orb %cl, %dl
jne 0x19870
movb $0x31, -0x2f(%rbp)
jmp 0x1987d
xorb $0x47, %al
orb %cl, %al
jne 0x1987d
movl $0x57324c, -0x30(%rbp)  # imm = 0x57324C
leaq -0x2f(%rbp), %rdi
xorl %esi, %esi
callq 0x45694
movslq 0x840(%rbx), %rcx
imulq $0x60, %rcx, %rcx
addq 0x848(%rbx), %rcx
movb %al, (%r12,%rcx)
incq %r12
addq $0x20, %r14
jmp 0x197ef
incl 0x840(%rbx)
leaq -0x90(%rbp), %r14
movq %r14, %rdi
callq 0x82c0
movq %r13, %rdi
callq 0x8460
movq %rax, %r13
jmp 0x19785
movl $0x9, 0x800(%rbx)
leaq 0x46fc0(%rip), %rdi     # 0x608a0
pushq $0x47
popq %rsi
callq 0x1a5f7
cltq
cmpl $0x0, -0x60(%rbp,%rax,4)
movq -0x68(%rbp), %r15
je 0x19991
pushq $0x1
popq %r14
leaq 0x46f9c(%rip), %rdi     # 0x608a0
pushq $0x43
popq %rsi
callq 0x1a5f7
cltq
cmpl $0x0, -0x60(%rbp,%rax,4)
jne 0x1994a
leaq 0x46f84(%rip), %rdi     # 0x608a0
pushq $0x52
popq %rsi
callq 0x1a5f7
cltq
cmpl $0x0, -0x60(%rbp,%rax,4)
jne 0x1994a
leaq 0x46f6c(%rip), %rdi     # 0x608a0
pushq $0x45
popq %rsi
callq 0x1a5f7
cltq
xorl %r14d, %r14d
cmpl $0x0, -0x60(%rbp,%rax,4)
setne %r14b
movq %r15, %rdi
movl $0x432, %esi            # imm = 0x432
movl %r14d, %edx
callq 0x32f04
movslq 0x800(%rbx), %rdi
movslq 0x9f8c8(%rbx), %rdx
leal (%rdx,%rdi), %eax
cmpl $0x7fc, %eax            # imm = 0x7FC
ja 0x19a73
addq %rbx, %rdi
leaq 0x9f8d4(%rbx), %rsi
callq 0x84f0
movl 0x9f8c8(%rbx), %eax
addl %eax, 0x800(%rbx)
leaq 0x46f08(%rip), %rdi     # 0x608a0
pushq $0x43
popq %rsi
callq 0x1a5f7
cltq
cmpl $0x0, -0x60(%rbp,%rax,4)
je 0x19a21
leaq 0x46ef0(%rip), %rdi     # 0x608a0
pushq $0x52
popq %rsi
callq 0x1a5f7
cltq
cmpl $0x0, -0x60(%rbp,%rax,4)
je 0x199c6
pushq $0x1
popq %rdx
jmp 0x199e1
leaq 0x46ed3(%rip), %rdi     # 0x608a0
pushq $0x45
popq %rsi
callq 0x1a5f7
cltq
xorl %edx, %edx
cmpl $0x0, -0x60(%rbp,%rax,4)
setne %dl
movq %r15, %rdi
movl $0x464, %esi            # imm = 0x464
callq 0x32f04
movslq 0x800(%rbx), %rdi
movslq 0x9f8c8(%rbx), %rdx
leal (%rdx,%rdi), %eax
cmpl $0x7fc, %eax            # imm = 0x7FC
ja 0x19a73
addq %rbx, %rdi
leaq 0x9f8d4(%rbx), %rsi
callq 0x84f0
movl 0x9f8c8(%rbx), %eax
addl %eax, 0x800(%rbx)
leaq 0x46e78(%rip), %rdi     # 0x608a0
pushq $0x52
popq %rsi
callq 0x1a5f7
cltq
cmpl $0x0, -0x60(%rbp,%rax,4)
je 0x19a96
leaq 0x46e60(%rip), %rdi     # 0x608a0
pushq $0x45
popq %rsi
callq 0x1a5f7
cltq
movl -0x60(%rbp,%rax,4), %edx
movq %r15, %rdi
movl $0x43c, %esi            # imm = 0x43C
callq 0x32f04
movslq 0x800(%rbx), %rdi
movslq 0x9f8c8(%rbx), %rdx
leal (%rdx,%rdi), %eax
cmpl $0x7fc, %eax            # imm = 0x7FC
jbe 0x19a7b
xorl %r14d, %r14d
jmp 0x19b09
addq %rbx, %rdi
leaq 0x9f8d4(%rbx), %rsi
callq 0x84f0
movl 0x9f8c8(%rbx), %eax
addl %eax, 0x800(%rbx)
leaq 0x46e03(%rip), %rdi     # 0x608a0
pushq $0x45
popq %rsi
callq 0x1a5f7
cltq
cmpl $0x0, -0x60(%rbp,%rax,4)
je 0x19afe
xorl %r14d, %r14d
movq %r15, %rdi
movl $0x446, %esi            # imm = 0x446
xorl %edx, %edx
callq 0x32f04
movslq 0x800(%rbx), %rdi
movslq 0x9f8c8(%rbx), %rdx
leal (%rdx,%rdi), %eax
cmpl $0x7fc, %eax            # imm = 0x7FC
ja 0x19b09
addq %rbx, %rdi
leaq 0x9f8d4(%rbx), %rsi
callq 0x84f0
movl 0x9f8c8(%rbx), %r14d
addl 0x800(%rbx), %r14d
movl %r14d, 0x800(%rbx)
jmp 0x19b05
movl 0x800(%rbx), %r14d
shll $0x3, %r14d
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x19b1d
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x82c0
movq %rbx, %rdi
callq 0x8b30