// File: /workspace/github_cpp_makefile_star2_O2/Mengjintao[P]SWAPCounter/src/kmerGraph.cpp
// Function: kmerGraph::dataShuttleBetweenGroupProcs(parameter*, MPIEnviroment*, char*&, long long&, long long)
void  kmerGraph::dataShuttleBetweenGroupProcs(parameter *parameters, MPIEnviroment *MPIcontrol, char *& readBuf, long long int& localEnd, long long int readRound)
{
	int gProc = MPIcontrol->groupProc;
	//divide the sequences data for each group process, then distribute data to all its group processes. 
	if(MPIcontrol->rank%gProc==0)	
	{
		unsigned long long step;
		unsigned long long *start_pos = new unsigned long long [gProc+1];
        	step = (localEnd-1)/gProc + 1;
		for(int k=0;k<gProc;k++)
		{
			long long int i = step*k;
			while(i<localEnd && readBuf[i]!='>') i++; 
			assert(i==localEnd || readBuf[i]=='>');
			start_pos[k] = i;
		}
		start_pos[gProc]=localEnd;
		
		for(int k=1;k<gProc;k++)
		{
			unsigned long long int length = start_pos[k+1]-start_pos[k];
			MPI_Send(&length, 1, MPI_LONG_LONG_INT, MPIcontrol->rank+k, 0, MPI_COMM_WORLD);
			MPI_Send(readBuf+start_pos[k], length, MPI_CHAR, MPIcontrol->rank+k, 1, MPI_COMM_WORLD);
		}
		localEnd = start_pos[1];
		delete [] start_pos;
	}	
	else
	{
		unsigned long long length;
		MPI_Recv(&length, 1, MPI_LONG_LONG_INT, MPIcontrol->rank-MPIcontrol->rank%gProc, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
		char *buffer = new char [length+2];	
		MPI_Recv(buffer, length, MPI_CHAR, MPIcontrol->rank-MPIcontrol->rank%gProc, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
		readBuf = buffer;
		localEnd = length;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %rbp
movq %rcx, %r14
movq %rdx, %r13
movslq 0x278(%rdx), %r15
movl (%rdx), %ecx
movl %ecx, %eax
cltd
idivl %r15d
testl %edx, %edx
je 0x3262
subl %edx, %ecx
andq $0x0, (%rsp)
movq 0x5dae(%rip), %rdx      # 0x8fa8
movq 0x5d97(%rip), %r9       # 0x8f98
leaq 0x8(%rsp), %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x21c0
movq (%rbx), %r12
leaq 0x2(%r12), %rdi
callq 0x2030
movq %r13, %rcx
movq %rax, %r13
movl (%rcx), %ecx
movl %ecx, %eax
cltd
idivl %r15d
subl %edx, %ecx
andq $0x0, (%rsp)
movq 0x5d4b(%rip), %rdx      # 0x8f88
movq %r13, %rdi
movl %r12d, %esi
pushq $0x1
popq %r8
movq 0x5d4a(%rip), %r9       # 0x8f98
callq 0x21c0
movq %r13, (%r14)
movq (%rbx), %rax
movq %rax, (%rbp)
jmp 0x339c
cmpl $-0x1, %r15d
leaq 0x8(,%r15,8), %rax
pushq $-0x1
popq %rdi
cmovgeq %rax, %rdi
callq 0x2030
movq %rax, %r11
movq (%rbp), %rcx
leaq -0x1(%rcx), %rax
cqto
idivq %r15
incq %rax
movq (%r14), %rdx
xorl %esi, %esi
testl %r15d, %r15d
movl $0x0, %edi
cmovgl %r15d, %edi
xorl %r8d, %r8d
cmpq %r8, %rcx
movq %r8, %r9
cmovgq %rcx, %r9
cmpq %rdi, %rsi
je 0x32e7
movq %rax, %r10
imulq %rsi, %r10
cmpq %rcx, %r10
jge 0x32cb
cmpb $0x3e, (%rdx,%r10)
je 0x32c8
incq %r10
jmp 0x32b7
movq %r10, %r9
cmpq %rcx, %r9
je 0x32db
cmpb $0x3e, (%rdx,%r9)
jne 0x33ab
movq %r9, (%r11,%rsi,8)
incq %rsi
addq %rax, %r8
jmp 0x32a1
movq %r13, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %rbp, 0x18(%rsp)
movq %r11, 0x10(%rsp)
movq %rcx, (%r11,%r15,8)
pushq $0x1
popq %r13
movq %r15, 0x20(%rsp)
movq 0x28(%rsp), %r14
pushq $0x1
popq %rbp
cmpq %r15, %r13
jge 0x3386
leaq 0x1(%r13), %r15
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rbx
movq 0x8(%rax,%r13,8), %rax
subq %rbx, %rax
movq %rax, 0x8(%rsp)
movl (%r14), %ecx
addl %r13d, %ecx
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
movq 0x5c65(%rip), %rdx      # 0x8fa8
xorl %r8d, %r8d
movq 0x5c4b(%rip), %r12      # 0x8f98
movq %r12, %r9
callq 0x2090
movq 0x30(%rsp), %rax
addq (%rax), %rbx
movl 0x8(%rsp), %esi
addl (%r14), %r13d
movq %rbx, %rdi
movq 0x5c1a(%rip), %rdx      # 0x8f88
movl %r13d, %ecx
movl %ebp, %r8d
movq %r12, %r9
callq 0x2090
movq %r15, %r13
movq 0x20(%rsp), %r15
jmp 0x3310
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
callq 0x22f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ec0(%rip), %rdi      # 0x6272
leaq 0x2c8a(%rip), %rsi      # 0x6043
leaq 0x2ed1(%rip), %rcx      # 0x6291
movl $0x1a4, %edx            # imm = 0x1A4
callq 0x2160