// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq 0xc8ed(%rip), %r13      # 0x13fb0
leaq -0x30(%rbp), %rsi
movq %r13, %rdi
callq 0x2370
leaq -0x74(%rbp), %rsi
movq %r13, %rdi
callq 0x2250
leaq 0x7aa9(%rip), %rsi      # 0xf18b
leaq -0xd8(%rbp), %rdi
leaq -0x2e0(%rbp), %rdx
callq 0x20f0
leaq -0xb8(%rbp), %rdi
leaq -0x2e0(%rbp), %rdx
movq %rbx, %rsi
callq 0x20f0
leaq -0x2e0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x934d
leaq -0x98(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x2e0(%rbp), %rdx
callq 0x931f
leaq -0x2e0(%rbp), %rdi
callq 0x2110
leaq 0x7a48(%rip), %rdx      # 0xf190
leaq -0x70(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x93e9
leaq -0x2e0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x93c0
leaq -0x98(%rbp), %r13
leaq -0x2e0(%rbp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x22b0
movq %r14, %rdi
callq 0x2110
leaq -0x70(%rbp), %rdi
callq 0x2110
movq (%r13), %rsi
leaq -0x2e0(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2470
leaq -0x268(%rbp), %rdi
callq 0x2080
testb %al, %al
je 0x79f0
leaq -0x2e0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2160
leaq -0x2e0(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x2160
movl -0x40(%rbp), %r13d
movslq %r13d, %rsi
movl %esi, (%r12)
movl -0x2c(%rbp), %eax
movl %eax, (%r15)
leaq 0xcb3c(%rip), %rbx      # 0x14334
movl %eax, (%rbx)
movq -0x38(%rbp), %rdi
callq 0x92a6
xorl %r14d, %r14d
testl %r13d, %r13d
movl $0x0, %eax
cmovgl %r13d, %eax
movq %rax, -0x50(%rbp)
imulq $0x18, %rax, %r15
cmpq %r14, %r15
je 0x7838
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq %r14, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x92e8
addq $0x18, %r14
jmp 0x781a
movl %r13d, -0x3c(%rbp)
movslq (%rbx), %r13
pushq $0x8
popq %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x2180
leaq 0xcb73(%rip), %rcx      # 0x143c8
movq %rax, (%rcx)
movq %r13, %rdi
movq %r12, %rsi
callq 0x2180
leaq 0xcb66(%rip), %rcx      # 0x143d0
movq %rax, (%rcx)
movq %r13, %rdi
movq %r12, %rsi
callq 0x2180
leaq 0xcb39(%rip), %rcx      # 0x143b8
movq %rax, (%rcx)
movq %r13, %rdi
movq %r12, %rsi
callq 0x2180
leaq 0xcb2c(%rip), %rcx      # 0x143c0
movq %rax, (%rcx)
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x70(%rbp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
callq 0x20d0
movl -0x2c(%rbp), %r12d
movslq %r12d, %rdi
pushq $0x8
popq %rsi
callq 0x2180
movq %rax, -0x48(%rbp)
xorl %ebx, %ebx
cmpq -0x50(%rbp), %rbx
je 0x798d
imulq $0x18, %rbx, %r14
movq -0x48(%rbp), %r13
xorl %r15d, %r15d
movslq %r12d, %rax
cmpq %rax, %r15
jge 0x7985
leaq -0x2e0(%rbp), %rdi
movq %r13, %rsi
callq 0x2170
movsd (%r13), %xmm0
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq (%rcx,%r14), %rax
movsd %xmm0, (%rax,%r15,8)
testq %rbx, %rbx
je 0x794e
leaq 0xcaa9(%rip), %rcx      # 0x143c8
movq (%rcx), %rcx
movsd (%rcx,%r15,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x793a
movsd %xmm0, (%rcx,%r15,8)
movsd (%rax,%r15,8), %xmm0
leaq 0xca8f(%rip), %rax      # 0x143d0
movq (%rax), %rax
ucomisd (%rax,%r15,8), %xmm0
ja 0x796f
jmp 0x7975
movq (%rcx), %rax
movsd (%rax), %xmm0
leaq 0xca6c(%rip), %rax      # 0x143c8
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
leaq 0xca64(%rip), %rax      # 0x143d0
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movl -0x2c(%rbp), %r12d
addq $0x8, %r13
jmp 0x78e1
incq %rbx
jmp 0x78cc
movq -0x48(%rbp), %rdi
callq 0x2280
leaq -0x2e0(%rbp), %rdi
callq 0x2070
leaq -0x70(%rbp), %rdi
callq 0x2110
leaq -0x2e0(%rbp), %rdi
callq 0x20b0
leaq -0x98(%rbp), %rdi
callq 0x2110
leaq -0xb8(%rbp), %rdi
callq 0x2110
leaq -0xd8(%rbp), %rdi
callq 0x2110
movl -0x3c(%rbp), %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc5d1(%rip), %rdi      # 0x13fc8
leaq 0x7794(%rip), %rsi      # 0xf192
callq 0x2220
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x2450
leaq 0x7783(%rip), %rsi      # 0xf198
movq %rax, %rdi
callq 0x2220
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2220
movq %rax, %rdi
callq 0x2130
pushq $-0x1
popq %rdi
callq 0x22a0
jmp 0x7a69
jmp 0x7a4a
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2110
jmp 0x7a86
movq %rax, %rbx
jmp 0x7a86
movq %rax, %rbx
leaq -0x2e0(%rbp), %rdi
jmp 0x7a8d
movq %rax, %rbx
jmp 0x7a92
movq %rax, %rbx
jmp 0x7a9e
jmp 0x7a6e
jmp 0x7a69
movq %rax, %rbx
jmp 0x7a7a
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2110
leaq -0x2e0(%rbp), %rdi
callq 0x20b0
leaq -0x98(%rbp), %rdi
callq 0x2110
leaq -0xb8(%rbp), %rdi
callq 0x2110
leaq -0xd8(%rbp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x2460