// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x9104(%rip), %rsi      # 0x12188
callq 0x3300
testq %rax, %rax
je 0x9285
movq %rax, %r15
leaq 0x9108(%rip), %r13      # 0x121a4
movq %rax, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x34f0
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x34f0
movslq (%r12), %r13
movq %rbx, %rax
leaq 0xe29a(%rip), %rbx      # 0x17364
movl %r13d, (%rbx)
movq %rax, -0x30(%rbp)
movslq (%rax), %r12
movl $0x8, %esi
movq %r13, %rdi
callq 0x31b0
leaq 0xe310(%rip), %rcx      # 0x173f8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r13, %rdi
callq 0x31b0
leaq 0xe301(%rip), %rcx      # 0x17400
movq %rax, (%rcx)
movl $0x8, %esi
movq %r13, %rdi
callq 0x31b0
leaq 0xe2d2(%rip), %rcx      # 0x173e8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r13, %rdi
callq 0x31b0
leaq 0xe2c3(%rip), %rcx      # 0x173f0
movq %rax, (%rcx)
movq %r14, %rdi
movq %r12, %rsi
callq 0xb342
testq %r12, %r12
jle 0x9162
shlq $0x3, %r12
leaq (%r12,%r12,2), %r12
xorl %r13d, %r13d
movq (%r14), %rdi
addq %r13, %rdi
movslq (%rbx), %rsi
callq 0xb3c0
addq $0x18, %r13
cmpq %r13, %r12
jne 0x914b
movl (%rbx), %ecx
xorl %r10d, %r10d
testl %ecx, %ecx
movq %r10, -0x38(%rbp)
jle 0x91b3
leaq (%r10,%r10,2), %r12
xorl %r13d, %r13d
movq %r15, %rdi
leaq 0x9027(%rip), %rsi      # 0x121a7
leaq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x34f0
cmpl $-0x1, %eax
je 0x9268
movsd -0x40(%rbp), %xmm0
movq (%r14), %rcx
movq (%rcx,%r12,8), %rcx
movsd %xmm0, (%rcx,%r13,8)
incq %r13
movslq (%rbx), %rcx
cmpq %rcx, %r13
jl 0x9176
jmp 0x91bc
cmpl $-0x1, %eax
je 0x9268
movq -0x38(%rbp), %r10
testq %r10, %r10
jne 0x9209
testl %ecx, %ecx
jle 0x9260
movq (%r14), %rdx
movq (%rdx), %rdx
leaq 0xe21e(%rip), %rsi      # 0x173f8
movq (%rsi), %rsi
leaq 0xe21c(%rip), %rdi      # 0x17400
movq (%rdi), %rdi
movl %ecx, %r8d
movsd (%rdx), %xmm0
xorl %r9d, %r9d
movsd %xmm0, (%rsi,%r9,8)
movsd (%rdx), %xmm0
movsd %xmm0, (%rdi,%r9,8)
incq %r9
cmpq %r9, %r8
jne 0x91f1
testl %ecx, %ecx
jle 0x9260
movq (%r14), %rdx
leaq (%r10,%r10,2), %rsi
movq (%rdx,%rsi,8), %rdx
leaq 0xe1d9(%rip), %rsi      # 0x173f8
movq (%rsi), %rsi
leaq 0xe1d7(%rip), %rdi      # 0x17400
movq (%rdi), %rdi
movl %ecx, %r8d
xorl %r9d, %r9d
movsd (%rdx,%r9,8), %xmm0
movsd (%rsi,%r9,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x924a
movsd %xmm0, (%rsi,%r9,8)
ucomisd (%rdi,%r9,8), %xmm0
jbe 0x9258
movsd %xmm0, (%rdi,%r9,8)
incq %r9
cmpq %r9, %r8
jne 0x9232
incq %r10
jmp 0x9167
movq %r15, %rdi
callq 0x32a0
movq -0x30(%rbp), %rax
movl (%rax), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xdd4c(%rip), %rax      # 0x16fd8
movq (%rax), %rdi
leaq 0x8ef4(%rip), %rsi      # 0x1218a
movq %r13, %rdx
xorl %eax, %eax
callq 0x3400
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x9276