// File: /workspace/github_cpp_makefile_star2_O1/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, -0x40(%rbp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq 0xdc92(%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 0x8e68(%rip), %rsi      # 0x121ab
leaq 0x8e65(%rip), %rdx      # 0x121af
leaq -0xb0(%rbp), %rdi
callq 0xbb30
leaq -0xd8(%rbp), %rdi
leaq -0x2e0(%rbp), %rdx
movq %rbx, %rsi
callq 0x3100
leaq -0x2e0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb463
movq -0xb0(%rbp), %rcx
movq -0xa8(%rbp), %r8
leaq -0x2e0(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
leaq -0x78(%rbp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x93c1
movq %rdx, -0x88(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x78(%rbp)
jmp 0x93c9
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x80(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x2d0(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x93f5
callq 0x3270
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0xb764
leaq 0x8d92(%rip), %rsi      # 0x121b0
leaq -0x60(%rbp), %rdi
callq 0x3500
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0x30d0
movq %r14, -0x2e0(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9464
movq %rdx, -0x2e0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x2d0(%rbp)
jmp 0x946d
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x2e0(%rbp), %r13
movq %rdx, 0x8(%r13)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x3340
movq (%r13), %rdi
cmpq %r14, %rdi
je 0x94a8
callq 0x3270
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x94ba
callq 0x3270
movq -0x88(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
movl $0x8, %edx
callq 0x34e0
leaq -0x268(%rbp), %rdi
callq 0x3090
testb %al, %al
je 0x9761
leaq -0x2e0(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x3190
leaq -0x2e0(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x3190
movslq -0x64(%rbp), %rax
movl %eax, (%r12)
movq %rax, %r12
movl -0x2c(%rbp), %eax
movl %eax, (%r15)
leaq 0xde46(%rip), %rbx      # 0x17364
movl %eax, (%rbx)
movq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0xb3ae
testl %r12d, %r12d
jle 0x955c
leaq (,%r12,8), %rax
leaq (%rax,%rax,2), %r14
xorl %r15d, %r15d
movq -0x40(%rbp), %rax
movq (%rax), %rdi
addq %r15, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xb42c
addq $0x18, %r15
cmpq %r15, %r14
jne 0x9540
movq %r12, -0x38(%rbp)
movslq (%rbx), %r12
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xde81(%rip), %rcx      # 0x173f8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xde72(%rip), %rcx      # 0x17400
movq %rax, (%rcx)
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xde43(%rip), %rcx      # 0x173e8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r12, %rdi
callq 0x31b0
leaq 0xde34(%rip), %rcx      # 0x173f0
movq %rax, (%rcx)
leaq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
movq %rax, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
callq 0x30c0
movslq -0x2c(%rbp), %rdi
movl $0x8, %esi
callq 0x31b0
movq %rax, -0x90(%rbp)
cmpl $0x0, -0x38(%rbp)
jle 0x96d1
xorl %ebx, %ebx
leaq -0x2e0(%rbp), %r12
cmpl $0x0, -0x2c(%rbp)
jle 0x96c4
leaq (%rbx,%rbx,2), %r14
movq -0x90(%rbp), %r13
xorl %r15d, %r15d
movq %r12, %rdi
movq %r13, %rsi
callq 0x31a0
movsd (%r13), %xmm0
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq (%rcx,%r14,8), %rax
movsd %xmm0, (%rax,%r15,8)
testq %rbx, %rbx
je 0x9685
leaq 0xdda8(%rip), %rcx      # 0x173f8
movq (%rcx), %rcx
movsd (%rcx,%r15,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x9665
movsd %xmm0, (%rcx,%r15,8)
leaq 0xdd94(%rip), %rcx      # 0x17400
movq (%rcx), %rcx
movsd (%rax,%r15,8), %xmm0
ucomisd (%rcx,%r15,8), %xmm0
jbe 0x96b0
movsd %xmm0, (%rcx,%r15,8)
jmp 0x96b0
movq (%rcx), %rax
movsd (%rax), %xmm0
leaq 0xdd65(%rip), %rcx      # 0x173f8
movq (%rcx), %rcx
movsd %xmm0, (%rcx,%r15,8)
movsd (%rax), %xmm0
leaq 0xdd59(%rip), %rax      # 0x17400
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movslq -0x2c(%rbp), %rax
addq $0x8, %r13
cmpq %rax, %r15
jl 0x9622
incq %rbx
cmpq -0x38(%rbp), %rbx
jne 0x960a
movq -0x90(%rbp), %rdi
callq 0x3310
leaq -0x2e0(%rbp), %rdi
callq 0x3080
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
movq -0x38(%rbp), %rbx
je 0x96ff
callq 0x3270
leaq -0x2e0(%rbp), %rdi
callq 0x30a0
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x9720
callq 0x3270
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9735
callq 0x3270
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x974d
callq 0x3270
movl %ebx, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %r14
movq 0xd85d(%rip), %rdi      # 0x16fc8
leaq 0x8a40(%rip), %rsi      # 0x121b2
movl $0x5, %edx
callq 0x32d0
movl -0x30(%rbp), %esi
movq 0xd842(%rip), %rdi      # 0x16fc8
callq 0x34b0
movq %rax, %rbx
leaq 0x8a23(%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 0x97ff
jmp 0x97dc
jmp 0x97c5
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x9825
callq 0x3270
jmp 0x9825
movq %rax, %rbx
jmp 0x9825
movq %rax, %rbx
leaq -0x2d0(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x9830
movq %rax, %rbx
jmp 0x983a
movq %rax, %rbx
jmp 0x984f
jmp 0x9804
jmp 0x97ff
movq %rax, %rbx
jmp 0x9819
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x9819
callq 0x3270
leaq -0x2e0(%rbp), %rdi
callq 0x30a0
leaq -0x78(%rbp), %rax
movq -0x88(%rbp), %rdi
cmpq %rax, %rdi
je 0x983a
callq 0x3270
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x984f
callq 0x3270
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x9867
callq 0x3270
movq %rbx, %rdi
callq 0x34c0