// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rcx, %r14
movq %rdx, %r15
movslq 0x278(%rdx), %r13
movl (%rdx), %ecx
movl %ecx, %eax
cltd
idivl %r13d
testl %edx, %edx
movq %r8, 0x18(%rsp)
je 0x33a0
subl %edx, %ecx
xorl %eax, %eax
movq %rax, (%rsp)
movq 0x5c77(%rip), %rdx      # 0x8fa8
movq 0x5c58(%rip), %r9       # 0x8f90
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x21e0
movq (%rbx), %r12
leaq 0x2(%r12), %rdi
callq 0x2030
movq %rax, %rbp
movl (%r15), %ecx
movl %ecx, %eax
cltd
idivl %r13d
subl %edx, %ecx
xorl %eax, %eax
movq %rax, (%rsp)
movq 0x5c0b(%rip), %rdx      # 0x8f80
movq %rbp, %rdi
movl %r12d, %esi
movl $0x1, %r8d
movq 0x5c08(%rip), %r9       # 0x8f90
callq 0x21e0
movq %rbp, (%r14)
movq (%rbx), %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x34a8
movq %r8, %rbx
cmpl $-0x1, %r13d
leaq 0x8(,%r13,8), %rax
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x2030
movq %rax, %r12
movq (%rbx), %rcx
leaq -0x1(%rcx), %rax
cqto
idivq %r13
testl %r13d, %r13d
jle 0x3413
incq %rax
movq (%r14), %rdx
xorl %esi, %esi
movq %rax, %rdi
imulq %rsi, %rdi
cmpq %rcx, %rdi
jge 0x33f8
cmpb $0x3e, (%rdx,%rdi)
je 0x33f8
incq %rdi
cmpq %rcx, %rdi
jl 0x33e7
movq %rcx, %rdi
cmpq %rcx, %rdi
je 0x3407
cmpb $0x3e, (%rdx,%rdi)
jne 0x34b7
movq %rdi, (%r12,%rsi,8)
incq %rsi
cmpq %r13, %rsi
jne 0x33db
movq %rcx, (%r12,%r13,8)
cmpl $0x2, %r13d
movq %r14, 0x20(%rsp)
jl 0x3493
movl $0x1, %ebx
movq 0x5b62(%rip), %rbp      # 0x8f90
movq 0x8(%r12,%rbx,8), %rax
subq (%r12,%rbx,8), %rax
leaq 0x1(%rbx), %r14
movq %rax, 0x10(%rsp)
movl (%r15), %ecx
addl %ebx, %ecx
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x5b52(%rip), %rdx      # 0x8fa8
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x20b0
movq 0x20(%rsp), %rax
movq (%rax), %rdi
addq (%r12,%rbx,8), %rdi
movl 0x10(%rsp), %esi
movl (%r15), %ecx
addl %ebx, %ecx
movq 0x5b03(%rip), %rdx      # 0x8f80
movl $0x1, %r8d
movq %rbp, %r9
callq 0x20b0
movq %r14, %rbx
cmpq %r14, %r13
jne 0x342e
movq 0x8(%r12), %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq %r12, %rdi
callq 0x2330
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2db4(%rip), %rdi      # 0x6272
leaq 0x2b7e(%rip), %rsi      # 0x6043
leaq 0x2dc5(%rip), %rcx      # 0x6291
movl $0x1a4, %edx            # imm = 0x1A4
callq 0x2170