// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movslq 0x278(%rdx), %rbp
movl (%rdx), %ecx
movl %ecx, %eax
cltd
idivl %ebp
testl %edx, %edx
je 0x337f
subl %edx, %ecx
xorl %eax, %eax
movq %rax, (%rsp)
movq 0x5c9c(%rip), %rdx      # 0x8fa8
movq 0x5c7d(%rip), %r9       # 0x8f90
movq %rbx, 0x10(%rsp)
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x21e0
movq (%rbx), %r12
leaq 0x2(%r12), %rdi
callq 0x2030
movq %rax, %r13
movl (%r15), %ecx
movl %ecx, %eax
cltd
idivl %ebp
subl %edx, %ecx
xorl %eax, %eax
movq %rax, (%rsp)
movq 0x5c2c(%rip), %rdx      # 0x8f80
movq %r13, %rdi
movl %r12d, %esi
movl $0x1, %r8d
movq 0x5c29(%rip), %r9       # 0x8f90
callq 0x21e0
movq %r13, (%r14)
movq (%rbx), %rax
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x34c7
cmpl $-0x1, %ebp
leaq 0x8(,%rbp,8), %rax
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x2030
movq %rax, %r8
movq (%rbx), %rcx
leaq -0x1(%rcx), %rax
cqto
idivq %rbp
testl %ebp, %ebp
jle 0x34b4
incq %rax
movq (%r14), %rdx
xorl %esi, %esi
movq %rax, %rdi
imulq %rsi, %rdi
cmpq %rcx, %rdi
jge 0x33d8
cmpb $0x3e, (%rdx,%rdi)
je 0x33d8
incq %rdi
cmpq %rcx, %rdi
jl 0x33c5
movq %rcx, %rdi
jmp 0x33e7
cmpq %rcx, %rdi
je 0x33e7
cmpb $0x3e, (%rdx,%rdi)
jne 0x34d6
movq %rdi, (%r8,%rsi,8)
incq %rsi
cmpq %rbp, %rsi
jne 0x33b9
movq %rcx, (%r8,%rbp,8)
cmpl $0x1, %ebp
je 0x34b8
movq %rbx, 0x10(%rsp)
movl %ebp, %eax
movq %rax, 0x40(%rsp)
movq 0x8(%r8), %rbx
movl $0x1, %r13d
movq %rbx, 0x20(%rsp)
movq %r15, 0x38(%rsp)
movq %r14, 0x28(%rsp)
movq %r8, 0x30(%rsp)
movq 0x38(%rsp), %r15
leaq 0x1(%r13), %r14
movq 0x8(%r8,%r13,8), %rbp
movq %rbp, %rax
subq %rbx, %rax
movq %rax, 0x18(%rsp)
movl (%r15), %ecx
addl %r13d, %ecx
leaq 0x18(%rsp), %rdi
movl $0x1, %esi
movq 0x5b4e(%rip), %rdx      # 0x8fa8
xorl %r8d, %r8d
movq 0x5b2c(%rip), %r12      # 0x8f90
movq %r12, %r9
callq 0x20b0
movq 0x28(%rsp), %rax
addq (%rax), %rbx
movl 0x18(%rsp), %esi
addl (%r15), %r13d
movq %rbx, %rdi
movq 0x5afb(%rip), %rdx      # 0x8f80
movl %r13d, %ecx
movl $0x1, %r8d
movq %r12, %r9
callq 0x20b0
movq 0x30(%rsp), %r8
movq %rbp, %rbx
movq %r14, %r13
cmpq %r14, 0x40(%rsp)
jne 0x342f
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %rax
jmp 0x34bc
movq %rcx, (%r8,%rbp,8)
movq 0x8(%r8), %rax
movq %rax, (%rbx)
movq %r8, %rdi
callq 0x2330
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d95(%rip), %rdi      # 0x6272
leaq 0x2b5f(%rip), %rsi      # 0x6043
leaq 0x2da6(%rip), %rcx      # 0x6291
movl $0x1a4, %edx            # imm = 0x1A4
callq 0x2170
nop