// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movl 0x1407120(%rdi), %edi
movl %edi, %esi
callq 0x380d3
leaq 0x78(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
xorps %xmm0, %xmm0
callq 0x397a4
movslq 0x1407120(%rbx), %rdi
leaq 0x7e939(%rip), %r14     # 0x97544
pushq $0x4
popq %r12
pushq $0x9
popq %rcx
movq %r12, %rsi
movq %r14, %rdx
callq 0x35067
movq %rax, 0x68(%rsp)
movslq 0x1407120(%rbx), %rdi
pushq $0x8
popq %rsi
pushq $0xa
popq %rcx
movq %r14, %rdx
callq 0x35067
movq %rax, %r15
movslq 0x1407120(%rbx), %rdi
pushq $0xb
popq %rcx
movq %r12, %rsi
movq %r14, %rdx
callq 0x35067
movq %rax, 0x90(%rsp)
leaq 0x88(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5577a
movq (%r12), %rsi
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
callq 0x116b6
movq (%r12), %rsi
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
callq 0x1197e
movq (%r12), %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 (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0xfad8
movq %rbx, 0x60(%rsp)
movq %rbx, %rdi
callq 0x16c95
xorl %r13d, %r13d
movq (%r12), %r12
testq %r12, %r12
je 0x18dbf
movq 0x68(%rsp), %rax
movl %r13d, (%rax,%r13,4)
movq %r12, %rdi
callq 0x2b47e
movl %eax, %ebp
movq 0x80(%rsp), %rax
movq (%rax,%r13,8), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax,%r13,8)
movq 0x88(%rsp), %rdi
movslq %ebp, %rbx
movq 0x60(%rsp), %rax
movl 0x1407140(%rax,%rbx,4), %edx
incl %edx
movq %r12, 0x70(%rsp)
movq %r12, %rsi
callq 0x2d47a
movq %rax, %r14
pushq $0x1
popq %r12
movq 0x60(%rsp), %rax
movslq 0x1407140(%rax,%rbx,4), %rax
cmpq %rax, %r12
jg 0x18da5
movq (%r14,%r12,8), %rdi
callq 0x2b47e
cmpl %ebp, %eax
jne 0x18da5
movq 0x80(%rsp), %rax
movq (%rax,%r13,8), %rax
movq (%r14,%r12,8), %rcx
movslq 0x18(%rcx), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rax,%rcx,8)
movsd (%r15,%r13,8), %xmm0
addsd 0x7c786(%rip), %xmm0    # 0x95520
movsd %xmm0, (%r15,%r13,8)
incq %r12
jmp 0x18d4b
movq 0x70(%rsp), %r12
movq 0x10(%r12), %r12
incq %r13
movq %r14, %rdi
callq 0x34ff7
jmp 0x18ce8
movq 0x60(%rsp), %rbx
movl 0x1407120(%rbx), %edx
movq %r15, %rdi
movq 0x68(%rsp), %rsi
callq 0x35617
movl 0x1407120(%rbx), %ecx
xorl %eax, %eax
movq %rcx, %rdx
xorl %ebp, %ebp
movq 0x90(%rsp), %rdi
movsd 0x7c72c(%rip), %xmm1    # 0x95520
testl %edx, %edx
jle 0x18e50
decq %rdx
xorl %esi, %esi
movq 0x80(%rsp), %r8
xorl %r10d, %r10d
movslq %ecx, %r9
cmpq %r9, %rsi
jge 0x18e42
movq (%r8,%rdx,8), %r9
movsd (%r9,%rsi,8), %xmm0
ucomisd %xmm1, %xmm0
jne 0x18e3d
jp 0x18e3d
cmpl $0x0, (%rdi,%rsi,4)
jne 0x18e3d
movl $0x1, (%rdi,%rsi,4)
incl %r10d
movq 0x60(%rsp), %rcx
movl 0x1407120(%rcx), %ecx
incq %rsi
jmp 0x18e08
cmpl $0x1, %r10d
sbbl $-0x1, %ebp
addl %r10d, %eax
cmpl %ecx, %eax
jne 0x18df4
callq 0x34ff7
movq 0x68(%rsp), %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
movq 0xc8(%rsp), %rdi
callq 0x34ff7
movq 0x98(%rsp), %rdi
callq 0x34ff7
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x3929f
cvtsi2sd %ebp, %xmm1
movq 0x60(%rsp), %rbx
cvtsi2sdl 0x1407120(%rbx), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movq 0x88(%rsp), %rdi
callq 0x2c010
movq %rbx, %rdi
callq 0x16cc6
movsd 0x70(%rsp), %xmm0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq