// File: /workspace/github_cpp_makefile_star2_O2/ADAPTLab[P]MuDBSCAN/partition.cpp
// Function: fileReadSingle(char*, int*, int*, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>&)
int fileReadSingle(char* filename, int* numObjs, int* numCoords, vector< vector<double> >& objects)     /* no. coordinates */
{            
	FILE *infile;

	if ((infile = fopen(filename, "r")) == NULL)
	{
		fprintf(stderr, "Error: no such file (%s)\n", filename);
		return -1;
	}

	DataPoint dataPointTemp = NULL;

	fscanf(infile, "%d", numObjs); //Number Of Objects       
	fscanf(infile, "%d", numCoords);	//Number Of Features

	DIMENSION = *numCoords; // CHECK
	int totalPoints = *numObjs;

	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;
	int local_points = totalPoints;
	/* allocate space for objects[][] and read all objects */
	int i, j, iDim;

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

	dataPointTemp = (DataPoint) calloc(DIMENSION,  sizeof(dataPoint)); 
	// assert(dataPointTemp != NULL);

	i=0;
	int e;

	while(1)
	{ 
		double temp;
		for (j=0; j<DIMENSION; j++)
		{
			e = fscanf(infile, "%lf", &temp);
			if(e == -1) break;
			objects[i][j] = temp;  
		}

		if(e==-1) break;


		if(i==0)
		{
			for(j=0;j<DIMENSION;j++)
			{
				MINGRIDSIZEglobal[j] = (objects)[0][0];
				MAXGRIDSIZEglobal[j] = (objects)[0][0];    
			}
		}

		for(iDim = 0; iDim < DIMENSION; iDim++) //to find the max and min values along each dimension
		{
			dataPointTemp[iDim] = (objects)[i][iDim];

			if(MINGRIDSIZEglobal[iDim] > dataPointTemp[iDim])
			{
				MINGRIDSIZEglobal[iDim] = dataPointTemp[iDim]; 
			}
			if(MAXGRIDSIZEglobal[iDim] < dataPointTemp[iDim])
			{
				MAXGRIDSIZEglobal[iDim] = dataPointTemp[iDim];
			}
		}
		i++;

	}  

	free(dataPointTemp);

	fclose(infile); 
	return *numObjs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
leaq 0x7ce4(%rip), %rsi      # 0xf168
callq 0x2270
testq %rax, %rax
je 0x767b
movq %rax, %r15
leaq 0x7ce8(%rip), %r13      # 0xf184
movq %r12, %rdx
movq %r12, -0x38(%rbp)
xorl %r12d, %r12d
movq %rax, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2480
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2480
movslq (%rbx), %r13
leaq 0xce67(%rip), %rbx      # 0x14334
movl %r13d, (%rbx)
movq -0x38(%rbp), %rax
movslq (%rax), %rax
movq %rax, -0x30(%rbp)
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x2180
leaq 0xcedb(%rip), %rcx      # 0x143c8
movq %rax, (%rcx)
movq %r13, %rdi
pushq $0x8
popq %rsi
callq 0x2180
leaq 0xcece(%rip), %rcx      # 0x143d0
movq %rax, (%rcx)
movq %r13, %rdi
pushq $0x8
popq %rsi
callq 0x2180
leaq 0xcea1(%rip), %rcx      # 0x143b8
movq %rax, (%rcx)
movq %r13, %rdi
pushq $0x8
popq %rsi
callq 0x2180
leaq 0xce94(%rip), %rcx      # 0x143c0
movq %rax, (%rcx)
movq %r14, %rdi
movq -0x30(%rbp), %r13
movq %r13, %rsi
callq 0x92a6
testl %r13d, %r13d
movl $0x0, %eax
cmovgl %r13d, %eax
imulq $0x18, %rax, %r13
cmpq %r12, %r13
je 0x7567
movq (%r14), %rdi
addq %r12, %rdi
movslq (%rbx), %rsi
callq 0x92e8
addq $0x18, %r12
jmp 0x754e
xorl %r10d, %r10d
movq %r10, -0x30(%rbp)
imulq $0x18, %r10, %r12
xorl %r13d, %r13d
movslq (%rbx), %rcx
cmpq %rcx, %r13
jge 0x75b2
movq %r15, %rdi
leaq 0x7c00(%rip), %rsi      # 0xf187
leaq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x2480
cmpl $-0x1, %eax
je 0x765e
movsd -0x40(%rbp), %xmm0
movq (%r14), %rcx
movq (%rcx,%r12), %rcx
movsd %xmm0, (%rcx,%r13,8)
incq %r13
jmp 0x7575
cmpl $-0x1, %eax
je 0x765e
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
movq (%r14), %rdx
leaq 0xcdf9(%rip), %rsi      # 0x143c8
movq (%rsi), %rsi
leaq 0xcdf7(%rip), %rdi      # 0x143d0
movq (%rdi), %rdi
movq -0x30(%rbp), %r10
testq %r10, %r10
jne 0x761d
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x7606
movq (%rdx), %r9
movsd (%r9), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movsd %xmm0, (%rdi,%r8,8)
incq %r8
jmp 0x75e8
movq (%r14), %rdx
leaq 0xcdb8(%rip), %rsi      # 0x143c8
movq (%rsi), %rsi
leaq 0xcdb6(%rip), %rdi      # 0x143d0
movq (%rdi), %rdi
addq %r12, %rdx
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x7656
movq (%rdx), %r9
movsd (%r9,%r8,8), %xmm0
movsd (%rsi,%r8,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7643
movsd %xmm0, (%rsi,%r8,8)
ucomisd (%rdi,%r8,8), %xmm0
jbe 0x7651
movsd %xmm0, (%rdi,%r8,8)
incq %r8
jmp 0x7623
incq %r10
jmp 0x756a
movq %r15, %rdi
callq 0x2230
movq -0x38(%rbp), %rax
movl (%rax), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc956(%rip), %rax      # 0x13fd8
movq (%rax), %rdi
leaq 0x7ade(%rip), %rsi      # 0xf16a
movq %r13, %rdx
xorl %eax, %eax
callq 0x2390
pushq $-0x1
popq %rax
jmp 0x766c