// File: sebastienmeyer2[P]mst-clustering/src/kmeans.cpp
// Function: Cloud::init_bounding_box()
void Cloud::init_bounding_box()
{
    /*!
     * @brief Initializes the centers of this cloud by using a bounding box over 
	 * all the points
     */

	double* minBox = new double [this->d] ();
	double* maxBox = new double [this->d] ();
	for (int i = 0; i < this->d; i ++){
		minBox[i] = DBL_MAX;
		maxBox[i] = DBL_MIN;
	}

	for (int i = 0; i < this->n; i ++){
		for (int j = 0; j < this->d; j ++){
			if (points[i].coords[j] < minBox[j]){
				minBox[j] = points[i].coords[j];
			}
			if (points[i].coords[j] > maxBox[j]){
				maxBox[j] = points[i].coords[j];
			}
		}
	}

	Point center;
	for (int i = 0; i < this->k; i ++){
		center.label = i;

		for (int j = 0; j < this->d; j ++){
			double randomValue = (double)rand() / RAND_MAX;
			randomValue = minBox[j] + (randomValue * (maxBox[j] - minBox[j]));
			
			center.coords[j] = randomValue;
		}

		this->set_center(center, i);
	}

	delete[] minBox;
	minBox = NULL;
	delete[] maxBox;
	maxBox = NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movslq (%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x70(%rbp)
callq 0xa030
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x68(%rbp)
xorl %esi, %esi
callq 0xa3a0
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x10(%rbp)
movslq (%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x58(%rbp)
callq 0xa030
movq -0x58(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x50(%rbp)
xorl %esi, %esi
callq 0xa3a0
movq -0x50(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x60(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl (%rcx), %eax
jge 0x333a6
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd 0x4417(%rip), %xmm0     # 0x37798
movsd %xmm0, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd 0x46fa(%rip), %xmm0     # 0x37a90
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x33366
movl $0x0, -0x20(%rbp)
movq -0x60(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x334ab
movl $0x0, -0x24(%rbp)
movq -0x60(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl (%rcx), %eax
jge 0x3349b
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x33431
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x3348b
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x3348d
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x333c4
jmp 0x3349d
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x333ad
leaq -0x38(%rbp), %rdi
callq 0xb520
movl $0x0, -0x3c(%rbp)
movq -0x60(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x33571
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x60(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl (%rcx), %eax
jge 0x33553
callq 0xa1c0
cvtsi2sd %eax, %xmm0
movsd 0x4594(%rip), %xmm1     # 0x37a88
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x48(%rbp), %xmm0
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x334d8
movq -0x60(%rbp), %rdi
movl -0x3c(%rbp), %edx
leaq -0x38(%rbp), %rsi
callq 0x32a30
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x334bb
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x33588
movq -0x78(%rbp), %rdi
callq 0xaa00
movq $0x0, -0x10(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x335a7
movq -0x80(%rbp), %rdi
callq 0xaa00
movq $0x0, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xb590
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)