// File: /workspace/github_cpp_makefile_star2_O3/ADAPTLab[P]MuDBSCAN/partition.cpp
// Function: fileReadMulti(char*, int*, int*, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>&)
int fileReadMulti(char* infilename, int* numObjs, int* numCoords, vector< vector<double> >& objects)     /* no. coordinates */
{    
	int i, j, rank, nproc;
	int num_points,  dims;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &nproc);

	//cout << "Process " << rank << " entered fileReadMulti\n";

	string out("out_");
	string infolder(infilename);
	//cout<<"infolder "<<infolder<<"\n";
	string file_acc_to_rank = out + patch::to_string(rank);
	//cout<<"file_acc_to_rank "<<file_acc_to_rank<<"\n";
	file_acc_to_rank = infolder + "/" + file_acc_to_rank;
	//cout<<"file_acc_to_rank "<<file_acc_to_rank<<"\n";
	ifstream file(file_acc_to_rank.c_str(), ios::in);
	int local_points = 0;

	if (file.is_open())
	{
		file >> num_points;
		file >> dims;
		long long sch, lower, upper;

		// if(num_points % nproc == 0)
		//     sch = num_points/nproc;
		// else
		//     sch = num_points/nproc + 1;

		lower = 0;
		upper = num_points;

		// if(lower > num_points)
		// 	lower = num_points;

		// if(upper > num_points)
		//     upper = num_points;

		*numObjs = num_points;
		*numCoords = dims;

		DIMENSION = dims;
		local_points = upper - lower;

		objects.resize(local_points);
		for(int ll = 0; ll < local_points; ll++)
			objects[ll].resize(dims);

		MINGRIDSIZEglobal = (double*) calloc(DIMENSION, sizeof(double));
		// assert(MINGRIDSIZEglobal != NULL);

		MAXGRIDSIZEglobal = (double*) calloc(DIMENSION, sizeof(double));
		// assert(MAXGRIDSIZEglobal != NULL);

		MINGRIDSIZE = (double*) calloc(DIMENSION, sizeof(double));
		// assert(MINGRIDSIZE != NULL);

		MAXGRIDSIZE = (double*) calloc(DIMENSION, sizeof(double));
		// assert(MAXGRIDSIZE != NULL);

		int iNum=0;
		double* pt;

		string s;
		s.resize(1000, 0);

		for(i=0;i<lower;i++)
			getline(file, s);

		pt = (double*) calloc(dims, sizeof(double));
		// assert(pt != NULL);

		for (i = 0; i < local_points; i++)
		{
			for (j = 0; j < dims; j++)
			{
				file >> pt[j];
				(objects)[i][j] = pt[j];

				if(i==0)
				{
					MINGRIDSIZEglobal[j] = (objects)[0][0];
					MAXGRIDSIZEglobal[j] = (objects)[0][0];    
				}
				else
				{
					if(MINGRIDSIZEglobal[j] > (objects)[i][j])
					{
						MINGRIDSIZEglobal[j] = (objects)[i][j]; 
					}
					if(MAXGRIDSIZEglobal[j] < (objects)[i][j])
					{
						MAXGRIDSIZEglobal[j] = (objects)[i][j];
					}
				}
			}
		}

		free(pt);
		pt = NULL;
		
		file.close();
		return local_points;
	}
	else
	{
		cout << "rank " << rank << " Error: no such file: " << infilename << endl;
		exit(-1);
	}
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rcx, -0x38(%rbp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq 0xdcd9(%rip), %r13      # 0x16fa8
leaq -0x30(%rbp), %rsi
movq %r13, %rdi
callq 0x33e0
leaq -0xb4(%rbp), %rsi
movq %r13, %rdi
callq 0x32e0
leaq -0xa0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x8eaf(%rip), %rsi      # 0x121ab
leaq 0x8eac(%rip), %rdx      # 0x121af
leaq -0xb0(%rbp), %rdi
callq 0xbad8
leaq -0xd8(%rbp), %rdi
leaq -0x2e0(%rbp), %rdx
movq %r14, %rsi
callq 0x3100
leaq -0x2e0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb3f7
movq -0xb0(%rbp), %rcx
movq -0xa8(%rbp), %r8
leaq -0x2e0(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
leaq -0x70(%rbp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9377
movq %rdx, -0x80(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x70(%rbp)
jmp 0x937f
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x78(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x2d0(%rbp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x93ab
callq 0x3270
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %rdi
callq 0xb706
leaq 0x8ddc(%rip), %rsi      # 0x121b0
leaq -0x58(%rbp), %rdi
callq 0x3500
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x30d0
movq %rbx, -0x2e0(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9417
movq %rdx, -0x2e0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x2d0(%rbp)
jmp 0x941f
movupd (%rcx), %xmm0
movupd %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq -0x2e0(%rbp), %r13
movq %rdx, 0x8(%r13)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
callq 0x3340
movq (%r13), %rdi
cmpq %rbx, %rdi
je 0x9457
callq 0x3270
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9469
callq 0x3270
movq -0x80(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
movl $0x8, %edx
callq 0x34e0
leaq -0x268(%rbp), %rdi
callq 0x3090
testb %al, %al
je 0x9701
leaq -0x2e0(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x3190
leaq -0x2e0(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x3190
movslq -0x5c(%rbp), %r13
movl %r13d, (%r12)
movl -0x2c(%rbp), %eax
movl %eax, (%r15)
leaq 0xde9d(%rip), %rbx      # 0x17364
movl %eax, (%rbx)
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0xb342
testl %r13d, %r13d
jle 0x9505
leaq (,%r13,8), %rax
leaq (%rax,%rax,2), %r14
xorl %r15d, %r15d
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq %r15, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xb3c0
addq $0x18, %r15
cmpq %r15, %r14
jne 0x94e9
movslq (%rbx), %r12
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xdedc(%rip), %rcx      # 0x173f8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xdecd(%rip), %rcx      # 0x17400
movq %rax, (%rcx)
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xde9e(%rip), %rcx      # 0x173e8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xde8f(%rip), %rcx      # 0x173f0
movq %rax, (%rcx)
leaq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
movq %rax, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
callq 0x30c0
movl -0x2c(%rbp), %r12d
movslq %r12d, %rdi
movl $0x8, %esi
callq 0x31b0
movq %rax, -0x88(%rbp)
testl %r13d, %r13d
jle 0x9677
xorl %ebx, %ebx
movq %r13, -0x90(%rbp)
testl %r12d, %r12d
jle 0x966b
leaq (%rbx,%rbx,2), %r14
movq -0x88(%rbp), %r13
xorl %r15d, %r15d
leaq -0x2e0(%rbp), %rdi
movq %r13, %rsi
callq 0x31a0
movsd (%r13), %xmm0
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq (%rcx,%r14,8), %rax
movsd %xmm0, (%rax,%r15,8)
testq %rbx, %rbx
je 0x9629
leaq 0xddfe(%rip), %rcx      # 0x173f8
movq (%rcx), %rcx
movsd (%rcx,%r15,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x9615
movsd %xmm0, (%rcx,%r15,8)
movsd (%rax,%r15,8), %xmm0
leaq 0xdde4(%rip), %rax      # 0x17400
movq (%rax), %rax
ucomisd (%rax,%r15,8), %xmm0
ja 0x964a
jmp 0x9650
movq (%rcx), %rax
movsd (%rax), %xmm0
leaq 0xddc1(%rip), %rax      # 0x173f8
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
leaq 0xddb9(%rip), %rax      # 0x17400
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movslq -0x2c(%rbp), %r12
addq $0x8, %r13
cmpq %r12, %r15
jl 0x95c8
movq -0x90(%rbp), %r13
incq %rbx
cmpq %r13, %rbx
jne 0x95b1
movq -0x88(%rbp), %rdi
callq 0x3310
leaq -0x2e0(%rbp), %rdi
callq 0x3080
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x96a1
callq 0x3270
leaq -0x2e0(%rbp), %rdi
callq 0x30a0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x96bf
callq 0x3270
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x96d4
callq 0x3270
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x96ec
callq 0x3270
movl %r13d, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd8c0(%rip), %rdi      # 0x16fc8
leaq 0x8aa3(%rip), %rsi      # 0x121b2
movl $0x5, %edx
callq 0x32d0
movl -0x30(%rbp), %esi
movq 0xd8a5(%rip), %rdi      # 0x16fc8
callq 0x34b0
movq %rax, %rbx
leaq 0x8a86(%rip), %rsi      # 0x121b8
movl $0x16, %edx
movq %rax, %rdi
callq 0x32d0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3290
movq %rax, %rdi
callq 0x3140
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3330
jmp 0x979c
jmp 0x9779
jmp 0x9762
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x97c2
callq 0x3270
jmp 0x97c2
movq %rax, %rbx
jmp 0x97c2
movq %rax, %rbx
leaq -0x2d0(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x97ca
movq %rax, %rbx
jmp 0x97d4
movq %rax, %rbx
jmp 0x97e9
jmp 0x97a1
jmp 0x979c
movq %rax, %rbx
jmp 0x97b6
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x97b6
callq 0x3270
leaq -0x2e0(%rbp), %rdi
callq 0x30a0
leaq -0x70(%rbp), %rax
movq -0x80(%rbp), %rdi
cmpq %rax, %rdi
je 0x97d4
callq 0x3270
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x97e9
callq 0x3270
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x9801
callq 0x3270
movq %rbx, %rdi
callq 0x34c0