// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd0, %rsp
movq %rdi, %rbx
leaq 0x68(%rsp), %r14
movq %r14, %rsi
callq 0x5dcbd
movq (%r14), %rsi
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
callq 0x1247b
movq (%r14), %rsi
leaq 0x70(%rsp), %r12
movq %r12, %rdi
callq 0x127bd
movq (%r14), %rdi
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x50(%rsp)
movups %xmm1, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
movupd (%r15), %xmm0
movupd 0x10(%r15), %xmm1
movupd 0x20(%r15), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x107b2
movslq 0x1bc(%rbx), %rax
testq %rax, %rax
jle 0x1a5a4
imulq $0x340, %rax, %rax      # imm = 0x340
xorl %ecx, %ecx
movl 0x30f08(%rbx,%rcx), %edx
movl %edx, 0x30f0c(%rbx,%rcx)
testl %edx, %edx
jne 0x1a598
movl $0x2, 0x30f08(%rbx,%rcx)
addq $0x340, %rcx            # imm = 0x340
cmpq %rcx, %rax
jne 0x1a57b
movq 0x68(%rsp), %rdi
callq 0x11678
movq %rax, %r14
movq 0x68(%rsp), %rdi
callq 0x10af1
movq %rax, %r15
movq %rdx, %r12
movslq 0x1407120(%rbx), %rdi
leaq 0x8cfb4(%rip), %rdx     # 0xa7583
movl $0x4, %esi
movl $0x15, %ecx
callq 0x3a1fc
movq %rax, %r13
movl $0x1, (%rax)
movl 0x1407120(%rbx), %r8d
xorpd %xmm0, %xmm0
cmpl $0x2, %r8d
jl 0x1a696
xorl %eax, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movsd 0x8b798(%rip), %xmm0    # 0xa5da8
testl %r8d, %r8d
jle 0x1a669
movl %r8d, %r8d
xorl %r9d, %r9d
movapd %xmm0, %xmm1
cmpl $0x0, (%r13,%r9,4)
je 0x1a661
xorl %r10d, %r10d
cmpl $0x0, (%r13,%r10,4)
jne 0x1a659
movq (%r12,%r9,8), %r11
movsd (%r11,%r10,8), %xmm2
ucomisd %xmm0, %xmm1
jne 0x1a644
jnp 0x1a64a
ucomisd %xmm2, %xmm1
jbe 0x1a659
movl (%r14,%r9,4), %esi
movl (%r14,%r10,4), %edi
movapd %xmm2, %xmm1
movl %r10d, %edx
incq %r10
cmpq %r10, %r8
jne 0x1a62a
incq %r9
cmpq %r8, %r9
jne 0x1a61f
movslq %edx, %r8
movl $0x1, (%r13,%r8,4)
incl %ecx
xorl %r8d, %r8d
cmpl %edi, %esi
setne %r8b
addl %r8d, %eax
movl 0x1407120(%rbx), %r8d
cmpl %r8d, %ecx
jl 0x1a610
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x60(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ed51
movq %r13, %rdi
callq 0x3a180
movq %r14, %rdi
callq 0x3a180
movq 0xa0(%rsp), %rdi
callq 0x3a180
movq 0x70(%rsp), %rdi
callq 0x3a180
movl 0x1407120(%rbx), %eax
movslq 0x1bc(%rbx), %rcx
testq %rcx, %rcx
jle 0x1a703
imulq $0x340, %rcx, %rcx      # imm = 0x340
xorl %edx, %edx
movl 0x30f0c(%rbx,%rdx), %esi
movl %esi, 0x30f08(%rbx,%rdx)
addq $0x340, %rdx            # imm = 0x340
cmpq %rdx, %rcx
jne 0x1a6e9
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x60(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
movq 0x68(%rsp), %rdi
callq 0x2ff55
movsd 0x60(%rsp), %xmm0
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq