// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/dataset.c
// Function: adherentsubsets
double adherentsubsets(Datasetptr d)
{
 /*!Last Changed 09.05.2006 Oya*/
 Instance mean, variance;
 Instanceptr temp, traindata, *nearestneighbors;
 int count = 0, cno1, cno2;
 double result = 0, *order;
 int j, i, sumdifferent, different, *selected, *dataindex;
 matrix allsubsets;
 allsubsets = matrix_alloc(d->datacount, d->datacount);
 initialize_matrix(&allsubsets, 0);
 dataindex = (int *) safecalloc(d->datacount, sizeof(int), "adherentsubsets", 9);
 order = (double *) safecalloc(d->datacount, sizeof(double), "adherentsubsets", 10);
 selected = (int *) safecalloc(d->datacount, sizeof(int), "adherentsubsets", 11);
 read_from_train_file(d, &traindata);
 mean = find_mean(traindata);
 variance = find_variance(traindata);
 normalize(traindata, mean, variance);
 type_change(d);
 temp = traindata;
 j = 0;
 while (temp)
  {
   dataindex[j] = j; 
   cno2 = give_classno(temp);
   allsubsets.values[j][j] = 1;
   nearestneighbors = find_nearest_neighbors(traindata, temp, d->classcounts[cno2] + 1);
   for (i = 1; i < d->classcounts[cno2] + 1; i++)
    {   
     cno1 = give_classno(nearestneighbors[i]);
     if (cno1 == cno2)
      {
       allsubsets.values[j][nearestneighbors[i]->index] = 1;
       order[j] = order[j] + 1; 
      }
     else
      {
       break;
      }
    }
   temp = temp->next;
   j++;
   safe_free(nearestneighbors);
  }
 sort_two_arrays(order, dataindex, d->datacount);
 sumdifferent = 0;
 count = 0;
 for (i = d->datacount - 1; i >= 0; i--)
  {
   different = 0;
   for (j = 0; j < d->datacount; j++)
    {
     if (allsubsets.values[i][j] == 1)
       if (selected[j] == 0)
        {
         selected[j] = 1;
         different++;
        }
     }
   if (different != 0)
     count++;
   sumdifferent += different;
   if (sumdifferent == d->datacount)
     break;
  }
 safe_free(selected);
 safe_free(dataindex);
 safe_free(order);
 safe_free(mean.values);
 safe_free(variance.values);
 matrix_free(allsubsets);
 result = (double) count / d->datacount;
 deallocate(traindata);
 type_restore(d);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %r15
movl 0x1407120(%rdi), %edi
movl %edi, %esi
callq 0x3d79d
leaq 0x78(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
xorps %xmm0, %xmm0
callq 0x3f41d
movslq 0x1407120(%r15), %rdi
leaq 0x8ca81(%rip), %r14     # 0xa75a4
movl $0x4, %esi
movq %r14, %rdx
movl $0x9, %ecx
callq 0x3a1fc
movq %rax, 0x60(%rsp)
movslq 0x1407120(%r15), %rdi
movl $0x8, %esi
movq %r14, %rdx
movl $0xa, %ecx
callq 0x3a1fc
movq %rax, 0x68(%rsp)
movslq 0x1407120(%r15), %rdi
movl $0x4, %esi
movq %r14, %rdx
movl $0xb, %ecx
callq 0x3a1fc
movq %rax, 0x88(%rsp)
leaq 0x70(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x5dcbd
movq (%r14), %rsi
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
callq 0x1247b
movq (%r14), %rsi
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
callq 0x127bd
movq (%r14), %rdi
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm2, 0x50(%rsp)
movups %xmm1, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
movupd (%r13), %xmm0
movupd 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x107b2
movslq 0x1bc(%r15), %rax
testq %rax, %rax
jle 0x1ac34
imulq $0x340, %rax, %rax      # imm = 0x340
xorl %ecx, %ecx
movl 0x30f08(%r15,%rcx), %edx
movl %edx, 0x30f0c(%r15,%rcx)
testl %edx, %edx
jne 0x1ac28
movl $0x2, 0x30f08(%r15,%rcx)
addq $0x340, %rcx            # imm = 0x340
cmpq %rcx, %rax
jne 0x1ac08
movq 0x70(%rsp), %rbx
testq %rbx, %rbx
je 0x1ad25
xorl %r12d, %r12d
movq 0x60(%rsp), %rax
movl %r12d, (%rax,%r12,4)
movq %rbx, %rdi
callq 0x2f33a
movl %eax, %ebp
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax,%r12,8)
movq 0x70(%rsp), %rdi
movq %rbx, %rsi
movslq %ebp, %rbx
movl 0x1407140(%r15,%rbx,4), %edx
incl %edx
movq %rsi, 0x90(%rsp)
callq 0x3151c
movq %rax, %r14
movq %r15, %r13
cmpl $0x0, 0x1407140(%r15,%rbx,4)
jle 0x1ad02
xorl %r15d, %r15d
movq 0x8(%r14,%r15,8), %rdi
callq 0x2f33a
cmpl %ebp, %eax
jne 0x1ad02
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %rax
movq 0x8(%r14,%r15,8), %rcx
movslq 0x18(%rcx), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rax,%rcx,8)
movq 0x68(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
addsd 0x8a834(%rip), %xmm0    # 0xa5520
movsd %xmm0, (%rax,%r12,8)
movslq 0x1407140(%r13,%rbx,4), %rax
incq %r15
cmpq %rax, %r15
jl 0x1aca8
movq 0x90(%rsp), %rbx
movq 0x10(%rbx), %rbx
incq %r12
movq %r14, %rdi
callq 0x3a180
testq %rbx, %rbx
movq %r13, %r15
jne 0x1ac45
movl 0x1407120(%r15), %edx
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x3a870
movl 0x1407120(%r15), %edx
movq 0x80(%rsp), %rax
xorl %ecx, %ecx
movsd 0x8a7cc(%rip), %xmm0    # 0xa5520
movq %rdx, %rsi
xorl %ebp, %ebp
movq 0x88(%rsp), %rdi
testl %esi, %esi
jle 0x1adbb
decq %rsi
testl %edx, %edx
jle 0x1adaa
movq (%rax,%rsi,8), %r8
xorl %r9d, %r9d
xorl %r11d, %r11d
movsd (%r8,%r9,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1ad9d
jp 0x1ad9d
cmpl $0x0, (%rdi,%r9,4)
jne 0x1ad9d
movl $0x1, (%rdi,%r9,4)
incl %r11d
movl 0x1407120(%r15), %edx
incq %r9
movslq %edx, %r10
cmpq %r10, %r9
jl 0x1ad76
jmp 0x1adad
xorl %r11d, %r11d
cmpl $0x1, %r11d
sbbl $-0x1, %ebp
addl %r11d, %ecx
cmpl %edx, %ecx
jne 0x1ad61
callq 0x3a180
movq 0x60(%rsp), %rdi
callq 0x3a180
movq 0x68(%rsp), %rdi
callq 0x3a180
movq 0xc8(%rsp), %rdi
callq 0x3a180
movq 0x98(%rsp), %rdi
callq 0x3a180
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x3ed51
movl 0x1407120(%r15), %ebx
movq 0x70(%rsp), %rdi
callq 0x2ff55
movslq 0x1bc(%r15), %rax
testq %rax, %rax
jle 0x1ae42
imulq $0x340, %rax, %rax      # imm = 0x340
xorl %ecx, %ecx
movl 0x30f0c(%r15,%rcx), %edx
movl %edx, 0x30f08(%r15,%rcx)
addq $0x340, %rcx            # imm = 0x340
cmpq %rcx, %rax
jne 0x1ae26
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
divsd %xmm1, %xmm0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq