// File: 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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x13725(%rip), %rsi     # 0x2c248
callq 0x97b0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x18b5a
movq 0x1f49f(%rip), %rax     # 0x37fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x13703(%rip), %rsi     # 0x2c24a
movb $0x0, %al
callq 0x9a30
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x18ea4
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x136f3(%rip), %rsi     # 0x2c264
movb $0x0, %al
callq 0x9d00
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x136dd(%rip), %rsi     # 0x2c264
movb $0x0, %al
callq 0x9d00
movq -0x20(%rbp), %rax
movl (%rax), %ecx
leaq 0x1fc39(%rip), %rax     # 0x387d4
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
leaq 0x1fc27(%rip), %rax     # 0x387d4
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x9400
movq %rax, %rcx
leaq 0x1fca4(%rip), %rax     # 0x38868
movq %rcx, (%rax)
leaq 0x1fc06(%rip), %rax     # 0x387d4
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x9400
movq %rax, %rcx
leaq 0x1fc8b(%rip), %rax     # 0x38870
movq %rcx, (%rax)
leaq 0x1fbe5(%rip), %rax     # 0x387d4
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x9400
movq %rax, %rcx
leaq 0x1fc52(%rip), %rax     # 0x38858
movq %rcx, (%rax)
leaq 0x1fbc4(%rip), %rax     # 0x387d4
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x9400
movq %rax, %rcx
leaq 0x1fc39(%rip), %rax     # 0x38860
movq %rcx, (%rax)
movl $0x0, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x1bcb0
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x18c7d
movq -0x28(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0xf850
movq %rax, %rdi
leaq 0x1fb6a(%rip), %rax     # 0x387d4
movslq (%rax), %rsi
callq 0x1bd40
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x18c4b
leaq 0x1fb50(%rip), %rax     # 0x387d4
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x9400
movq %rax, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
leaq 0x1fb27(%rip), %rcx     # 0x387d4
cmpl (%rcx), %eax
jge 0x18d09
movq -0x30(%rbp), %rdi
leaq 0x135ab(%rip), %rsi     # 0x2c267
leaq -0x60(%rbp), %rdx
movb $0x0, %al
callq 0x9d00
movl %eax, -0x58(%rbp)
cmpl $-0x1, -0x58(%rbp)
jne 0x18cd2
jmp 0x18d09
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x48(%rbp), %rsi
callq 0xf850
movq %rax, %rdi
movslq -0x4c(%rbp), %rsi
callq 0xf870
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x18ca3
cmpl $-0x1, -0x58(%rbp)
jne 0x18d14
jmp 0x18e89
cmpl $0x0, -0x48(%rbp)
jne 0x18da0
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
leaq 0x1faa5(%rip), %rcx     # 0x387d4
cmpl (%rcx), %eax
jge 0x18d9e
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xf850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xf870
movsd (%rax), %xmm0
leaq 0x1fb11(%rip), %rax     # 0x38868
movq (%rax), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xf850
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xf870
movsd (%rax), %xmm0
leaq 0x1fae9(%rip), %rax     # 0x38870
movq (%rax), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x18d25
jmp 0x18da0
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
leaq 0x1fa23(%rip), %rcx     # 0x387d4
cmpl (%rcx), %eax
jge 0x18e7b
movq -0x28(%rbp), %rdi
movslq -0x48(%rbp), %rsi
callq 0xf850
movq %rax, %rdi
movslq -0x50(%rbp), %rsi
callq 0xf870
movsd (%rax), %xmm0
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0x1fa7e(%rip), %rax     # 0x38868
movq (%rax), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x18e25
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0x1fa4f(%rip), %rax     # 0x38868
movq (%rax), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0x1fa44(%rip), %rax     # 0x38870
movq (%rax), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x18e6b
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0x1fa11(%rip), %rax     # 0x38870
movq (%rax), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x18e6d
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x18da7
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x18c9c
movq -0x38(%rbp), %rdi
callq 0x97c0
movq -0x30(%rbp), %rdi
callq 0x9680
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)