// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/dataset.c
// Function: find_opposite_class_ratio_in_mst
double find_opposite_class_ratio_in_mst(Datasetptr d)
{
 /* usedp=>how many points already used 
    p->array of structures, consisting x,y,& used/not used
    this problem is to get the MST of graph with n vertices
    where weight of an edge is the distance between 2 points */
 int usedp, smallp = -1, opposite_class = 0, i, j, ci, cj;
 matrix lengths;
 int *classes, *used;
 Instanceptr traindata;
 double small, length, minLength=0, result;
 Instance mean, variance;
 read_from_train_file(d, &traindata);
 mean = find_mean(traindata);
 variance = find_variance(traindata);
 normalize(traindata, mean, variance);
 type_change(d);
 classes = find_classes(traindata);
 lengths = distance_matrix(traindata);
 used = safecalloc(d->datacount, sizeof(int), "find_opposite_class_ratio_in_mst", 21);
 used[0] = 1;  /* select arbitrary point as starting point */
 usedp = 1;
 while (usedp < d->datacount) 
  {
   small = -1.0;   
   for (i = 0; i < d->datacount; i++)
    {
     if (used[i])
      {
       for (j = 0; j < d->datacount; j++)
        {
         if (!used[j]) 
          {
           length = lengths.values[i][j];
           if (small == -1.0 || length < small) 
            {
             small = length;
             smallp = j;
             ci = classes[i];
             cj = classes[j];
            }
          }    
        }
      }
    }
   minLength += small;
   used[smallp] = 1;
   usedp++;
   if (ci != cj)
     opposite_class++;
  }
 matrix_free(lengths);
 safe_free(used);
 safe_free(classes);
 safe_free(mean.values);
 safe_free(variance.values);
 result = (double) opposite_class / d->datacount;
 type_restore(d);
 deallocate(traindata);
 traindata = NULL;
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x5577a
movq (%r15), %rsi
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
callq 0x116b6
movq (%r15), %rsi
leaq 0x78(%rsp), %r12
movq %r12, %rdi
callq 0x1197e
movq (%r15), %rdi
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x50(%rsp)
movups %xmm1, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
movups (%r14), %xmm0
movupd 0x10(%r14), %xmm1
movupd 0x20(%r14), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0xfad8
movq %rbx, %rdi
callq 0x16c95
movq (%r15), %rdi
callq 0x10987
movq %rax, %r14
movq (%r15), %rdi
callq 0xfdf0
movq %rax, %r15
movq %rdx, %r12
movslq 0x1407120(%rbx), %rdi
leaq 0x7ed8f(%rip), %rdx     # 0x97523
pushq $0x4
popq %rsi
pushq $0x15
popq %rcx
callq 0x35067
movq %rax, %r13
movl $0x1, (%rax)
pushq $0x1
popq %rax
pushq $-0x1
popq %rsi
xorl %ebp, %ebp
movsd 0x7d5f8(%rip), %xmm0    # 0x95db0
movl 0x1407120(%rbx), %edi
cmpl %edi, %eax
jge 0x18831
xorl %r8d, %r8d
movapd %xmm0, %xmm1
cmpq %rdi, %r8
je 0x18817
cmpl $0x0, (%r13,%r8,4)
je 0x18812
xorl %r9d, %r9d
cmpq %r9, %rdi
je 0x18812
cmpl $0x0, (%r13,%r9,4)
jne 0x1880d
movq (%r12,%r8,8), %r10
movsd (%r10,%r9,8), %xmm2
ucomisd %xmm0, %xmm1
jne 0x187f8
jnp 0x187fe
ucomisd %xmm2, %xmm1
jbe 0x1880d
movl (%r14,%r8,4), %edx
movl (%r14,%r9,4), %ecx
movapd %xmm2, %xmm1
movl %r9d, %esi
incq %r9
jmp 0x187d9
incq %r8
jmp 0x187c9
movslq %esi, %rdi
movl $0x1, (%r13,%rdi,4)
incl %eax
xorl %edi, %edi
cmpl %ecx, %edx
setne %dil
addl %edi, %ebp
jmp 0x187b8
movq %r15, %rdi
movq %r12, %rsi
callq 0x3929f
movq %r13, %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x34ff7
movq 0xa8(%rsp), %rdi
callq 0x34ff7
movq 0x78(%rsp), %rdi
callq 0x34ff7
cvtsi2sd %ebp, %xmm1
cvtsi2sdl 0x1407120(%rbx), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x68(%rsp)
movq %rbx, %rdi
callq 0x16cc6
movq 0x70(%rsp), %rdi
callq 0x2c010
movsd 0x68(%rsp), %xmm0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq