// File: /workspace/github_c_makefile_star2_O1/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 0x3c6e5
leaq 0x78(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
xorps %xmm0, %xmm0
callq 0x3e1f9
movslq 0x1407120(%rbx), %rdi
leaq 0x89f67(%rip), %r14     # 0xa4562
movl $0x4, %esi
movq %r14, %rdx
movl $0x9, %ecx
callq 0x39210
movq %rax, 0x60(%rsp)
movslq 0x1407120(%rbx), %rdi
movl $0x8, %esi
movq %r14, %rdx
movl $0xa, %ecx
callq 0x39210
movq %rax, 0x68(%rsp)
movslq 0x1407120(%rbx), %rdi
movl $0x4, %esi
movq %r14, %rdx
movl $0xb, %ecx
callq 0x39210
movq %rax, 0x88(%rsp)
leaq 0x70(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5c7af
movq (%r14), %rsi
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
callq 0x12519
movq (%r14), %rsi
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
callq 0x1286d
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 0x107bc
movslq 0x1bc(%rbx), %rax
testq %rax, %rax
jle 0x1a709
imulq $0x340, %rax, %rax      # imm = 0x340
xorl %ecx, %ecx
movl 0x30f08(%rbx,%rcx), %edx
movl %edx, 0x30f0c(%rbx,%rcx)
testl %edx, %edx
jne 0x1a6fd
movl $0x2, 0x30f08(%rbx,%rcx)
addq $0x340, %rcx            # imm = 0x340
cmpq %rcx, %rax
jne 0x1a6e0
movq 0x70(%rsp), %r13
testq %r13, %r13
je 0x1a7f4
xorl %r12d, %r12d
movq 0x60(%rsp), %rax
movl %r12d, (%rax,%r12,4)
movq %r13, %rdi
callq 0x2eaca
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
movslq %ebp, %r15
movl 0x1407140(%rbx,%r15,4), %edx
incl %edx
movq %r13, 0x90(%rsp)
movq %r13, %rsi
callq 0x30ca9
movq %rax, %r14
cmpl $0x0, 0x1407140(%rbx,%r15,4)
jle 0x1a7d4
xorl %r13d, %r13d
movq 0x8(%r14,%r13,8), %rdi
callq 0x2eaca
cmpl %ebp, %eax
jne 0x1a7d4
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %rax
movq 0x8(%r14,%r13,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 0x87d62(%rip), %xmm0    # 0xa2520
movsd %xmm0, (%rax,%r12,8)
movslq 0x1407140(%rbx,%r15,4), %rax
incq %r13
cmpq %rax, %r13
jl 0x1a77a
movq 0x90(%rsp), %r13
movq 0x10(%r13), %r13
incq %r12
movq %r14, %rdi
callq 0x39194
testq %r13, %r13
jne 0x1a71a
movl 0x1407120(%rbx), %edx
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x39864
movl 0x1407120(%rbx), %eax
movq 0x80(%rsp), %rcx
xorl %edx, %edx
movsd 0x87cff(%rip), %xmm0    # 0xa2520
xorl %ebp, %ebp
movq 0x88(%rsp), %rdi
testl %eax, %eax
jle 0x1a887
movl 0x1407120(%rbx), %r9d
testl %r9d, %r9d
jle 0x1a875
movq -0x8(%rcx,%rax,8), %r10
xorl %r8d, %r8d
xorl %esi, %esi
movsd (%r10,%r8,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1a864
jp 0x1a864
cmpl $0x0, (%rdi,%r8,4)
jne 0x1a864
movl $0x1, (%rdi,%r8,4)
incl %esi
incq %r8
movslq 0x1407120(%rbx), %r9
cmpq %r9, %r8
jl 0x1a845
jmp 0x1a877
xorl %esi, %esi
decq %rax
cmpl $0x1, %esi
sbbl $-0x1, %ebp
addl %esi, %edx
cmpl %r9d, %edx
jne 0x1a82b
callq 0x39194
movq 0x60(%rsp), %rdi
callq 0x39194
movq 0x68(%rsp), %rdi
callq 0x39194
movq 0xc8(%rsp), %rdi
callq 0x39194
movq 0x98(%rsp), %rdi
callq 0x39194
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x3dbad
movl 0x1407120(%rbx), %r14d
movq 0x70(%rsp), %rdi
callq 0x2f616
movslq 0x1bc(%rbx), %rax
testq %rax, %rax
jle 0x1a90c
imulq $0x340, %rax, %rax      # imm = 0x340
xorl %ecx, %ecx
movl 0x30f0c(%rbx,%rcx), %edx
movl %edx, 0x30f08(%rbx,%rcx)
addq $0x340, %rcx            # imm = 0x340
cmpq %rcx, %rax
jne 0x1a8f2
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq