// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x90d8(%rip), %rsi      # 0x12188
callq 0x3300
testq %rax, %rax
je 0x92cc
movq %rax, %r15
leaq 0x90dc(%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
leaq 0xe271(%rip), %rax      # 0x17364
movl %r13d, (%rax)
movq %rbx, -0x38(%rbp)
movslq (%rbx), %r12
movl $0x8, %esi
movq %r13, %rdi
callq 0x31b0
leaq 0xe2e7(%rip), %rcx      # 0x173f8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r13, %rdi
callq 0x31b0
leaq 0xe2d8(%rip), %rcx      # 0x17400
movq %rax, (%rcx)
movl $0x8, %esi
movq %r13, %rdi
callq 0x31b0
leaq 0xe2a9(%rip), %rcx      # 0x173e8
movq %rax, (%rcx)
movl $0x8, %esi
movq %r13, %rdi
leaq 0xe213(%rip), %r13      # 0x17364
callq 0x31b0
leaq 0xe293(%rip), %rcx      # 0x173f0
movq %rax, (%rcx)
movq %r14, %rdi
movq %r12, %rsi
callq 0xb3ae
testq %r12, %r12
jle 0x9193
shlq $0x3, %r12
leaq (%r12,%r12,2), %rbx
xorl %r12d, %r12d
movq (%r14), %rdi
addq %r12, %rdi
movslq (%r13), %rsi
callq 0xb42c
addq $0x18, %r12
cmpq %r12, %rbx
jne 0x917b
xorl %r10d, %r10d
movq -0x38(%rbp), %rbx
cmpl $0x0, (%r13)
movslq %r10d, %r11
jle 0x91fe
movl %r10d, -0x2c(%rbp)
movq %r11, -0x40(%rbp)
leaq (%r11,%r11,2), %rbx
xorl %r12d, %r12d
movq %r15, %rdi
leaq 0x8fea(%rip), %rsi      # 0x121a7
leaq -0x48(%rbp), %rdx
xorl %eax, %eax
callq 0x34f0
cmpl $-0x1, %eax
je 0x91ed
movsd -0x48(%rbp), %xmm0
movq (%r14), %rcx
movq (%rcx,%rbx,8), %rcx
movsd %xmm0, (%rcx,%r12,8)
incq %r12
movslq (%r13), %rcx
cmpq %rcx, %r12
jl 0x91b3
jmp 0x91f2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rbx
movl -0x2c(%rbp), %r10d
movq -0x40(%rbp), %r11
cmpl $-0x1, %eax
je 0x92aa
testl %r10d, %r10d
jne 0x924e
movslq (%r13), %rcx
testq %rcx, %rcx
jle 0x924e
movq (%r14), %rdx
movq (%rdx), %rdx
leaq 0xe1d6(%rip), %rsi      # 0x173f8
movq (%rsi), %rsi
leaq 0xe1d4(%rip), %rdi      # 0x17400
movq (%rdi), %rdi
xorl %r8d, %r8d
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movsd (%rdx), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rcx
jne 0x9232
movslq (%r13), %rcx
testq %rcx, %rcx
jle 0x92a7
movq (%r14), %rdx
leaq (%r11,%r11,2), %rsi
movq (%rdx,%rsi,8), %rdx
leaq 0xe18f(%rip), %rsi      # 0x173f8
movq (%rsi), %rsi
leaq 0xe18d(%rip), %rdi      # 0x17400
movq (%rdi), %rdi
xorl %r8d, %r8d
movsd (%rdx,%r8,8), %xmm0
movsd (%rsi,%r8,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x9291
movsd %xmm0, (%rsi,%r8,8)
ucomisd (%rdi,%r8,8), %xmm0
jbe 0x929f
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rcx
jne 0x9279
incl %r10d
cmpl $-0x1, %eax
jne 0x919a
movq %r15, %rdi
callq 0x32a0
movl (%rbx), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xdd05(%rip), %rax      # 0x16fd8
movq (%rax), %rdi
leaq 0x8ead(%rip), %rsi      # 0x1218a
movq %r13, %rdx
xorl %eax, %eax
callq 0x3400
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x92bd