// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/data.c
// Function: find_class_means
Instanceptr find_class_means(Instanceptr myptr,int *counts)
{
 /*!Last Changed 11.08.2007 added allocate_feature_counts and free_feature_counts*/
 /*!Last Changed 22.03.2005 added empty_instance*/
 /*!Last Changed 02.02.2004 added safemalloc and safecalloc*/
 /*!Last Changed 20.03.2002*/
 int i,j;
 int*** feature_counts = NULL;
 Instanceptr temp, temp1, result;
 if (!mustrealize)
   result = empty_link_list_of_instances(current_dataset->featurecount, current_dataset->classno);
 else
   result = empty_link_list_of_instances(current_dataset->multifeaturecount, current_dataset->classno);
 if (!mustrealize)
   feature_counts = allocate_feature_counts();
 temp1 = result;
 while (temp1)/*Initializing class means*/
  {
   if (mustrealize)
    {
     for (i = 0; i < current_dataset->multifeaturecount; i++)
       if (i != current_dataset->classdefno)
         temp1->values[i].floatvalue = 0;
    }
   else
    {
     for (i = 0; i < current_dataset->featurecount;i++)
       switch (current_dataset->features[i].type)
        {
         case INTEGER:temp1->values[i].floatvalue = 0;
                      break;
         case    REAL:temp1->values[i].floatvalue = 0;
                      break;
        }
    }
   temp1 = temp1->next;
  }
 temp = myptr;
 while (temp)/*Adding values to total*/
  {
   i = give_classno(temp);
   temp1 = data_x(result, i);
   if (mustrealize)
    {
     for (i = 0; i < current_dataset->multifeaturecount; i++)
       if (i != current_dataset->classdefno)
         temp1->values[i].floatvalue += temp->values[i].floatvalue;
    }
   else
    {
     for (j = 0; j < current_dataset->featurecount; j++)
       switch (current_dataset->features[j].type)
        {
         case INTEGER:temp1->values[j].floatvalue += temp->values[j].intvalue;
                      break;
         case    REAL:temp1->values[j].floatvalue += temp->values[j].floatvalue;
                      break;
         case  STRING:feature_counts[i][j][temp->values[j].stringindex]++;
                      break;
        }
    }
   temp = temp->next;
  }
 temp1 = result;
 j = 0;
 while (temp1)
  {
   if (mustrealize)
    {
     for (i = 0; i < current_dataset->multifeaturecount; i++)
       if (i != current_dataset->classdefno)
        {
         if (counts[j] != 0)
           temp1->values[i].floatvalue /= counts[j];
         else
           temp1->values[i].floatvalue = 0;         
        }
    }
   else
    {
     for (i = 0; i < current_dataset->featurecount; i++)
       switch (current_dataset->features[i].type)
        {
         case INTEGER:if (counts[j] != 0)
                        temp1->values[i].floatvalue /= counts[j];
                      else
                        temp1->values[i].floatvalue = 0;
                      break;
         case    REAL:if (counts[j]!=0)
                        temp1->values[i].floatvalue /= counts[j];
                      else
                        temp1->values[i].floatvalue = 0;
                      break;
         case  STRING:temp1->values[i].stringindex = find_max_in_list(feature_counts[j][i], current_dataset->features[i].valuecount);
                      break;
        }
    }
   temp1 = temp1->next;
   j++;
  }
 if (!mustrealize)
   free_feature_counts(feature_counts);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r12
leaq 0x3993d0(%rip), %r15    # 0x3a9fa4
xorl %eax, %eax
cmpl $0x0, (%r15)
setne %al
leaq 0xbcc8c(%rip), %r14     # 0xcd870
movq (%r14), %rcx
movl 0x10(%rcx), %esi
movl 0x1bc(%rcx,%rax,4), %edi
callq 0x109d3
movq %rax, 0x8(%rsp)
cmpl $0x0, (%r15)
je 0x10c0c
movq $0x0, 0x10(%rsp)
jmp 0x10c16
callq 0x10a10
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x10d5a
cmpl $0x0, (%r15)
je 0x10c56
movq (%r14), %rdx
xorl %ecx, %ecx
movslq 0x1c0(%rdx), %rsi
cmpq %rsi, %rcx
jge 0x10c86
movl 0x1407128(%rdx), %esi
cmpq %rsi, %rcx
je 0x10c51
movq (%rax), %rdx
andq $0x0, (%rdx,%rcx,8)
movq (%r14), %rdx
incq %rcx
jmp 0x10c2f
movl $0x61e1, %ecx           # imm = 0x61E1
xorl %edx, %edx
movq (%r14), %rsi
movslq 0x1bc(%rsi), %rdi
cmpq %rdi, %rdx
jge 0x10c86
testl $0xfffffffd, (%rsi,%rcx,8) # imm = 0xFFFFFFFD
jne 0x10c7d
movq (%rax), %rsi
andq $0x0, (%rsi,%rdx,8)
incq %rdx
addq $0x68, %rcx
jmp 0x10c5d
movq 0x10(%rax), %rax
jmp 0x10c1b
movq %r12, %rdi
callq 0x2b47e
movl %eax, %ebp
movq 0x8(%rsp), %rdi
movl %eax, %esi
callq 0x2d761
cmpl $0x0, (%r15)
je 0x10ce6
movq (%r14), %rdx
xorl %ecx, %ecx
movslq 0x1c0(%rdx), %rsi
cmpq %rsi, %rcx
jge 0x10d55
movl 0x1407128(%rdx), %esi
cmpq %rsi, %rcx
je 0x10ce1
movq (%r12), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%rax), %rdx
addsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%rcx,8)
movq (%r14), %rdx
incq %rcx
jmp 0x10cad
movslq %ebp, %rcx
movl $0x61e1, %edx           # imm = 0x61E1
xorl %esi, %esi
movq (%r14), %rdi
movslq 0x1bc(%rdi), %r8
cmpq %r8, %rsi
jge 0x10d55
movl (%rdi,%rdx,8), %edi
cmpl $0x2, %edi
je 0x10d36
cmpl $0x1, %edi
je 0x10d1b
testl %edi, %edi
jne 0x10d4c
movq (%r12), %rdi
cvtsi2sdl (%rdi,%rsi,8), %xmm0
jmp 0x10d3f
movq 0x10(%rsp), %rdi
movq (%rdi,%rcx,8), %rdi
movq (%rdi,%rsi,8), %rdi
movq (%r12), %r8
movslq (%r8,%rsi,8), %r8
incl (%rdi,%r8,4)
jmp 0x10d4c
movq (%r12), %rdi
movsd (%rdi,%rsi,8), %xmm0
movq (%rax), %rdi
addsd (%rdi,%rsi,8), %xmm0
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
addq $0x68, %rdx
jmp 0x10cf0
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x10c8c
xorl %r12d, %r12d
movq 0x8(%rsp), %rbp
movl (%r15), %eax
testq %rbp, %rbp
je 0x10e5b
testl %eax, %eax
je 0x10dc9
xorl %eax, %eax
movq (%r14), %rcx
movslq 0x1c0(%rcx), %rdx
cmpq %rdx, %rax
jge 0x10e48
movl 0x1407128(%rcx), %ecx
cmpq %rcx, %rax
je 0x10dc4
movl (%rbx,%r12,4), %ecx
testl %ecx, %ecx
je 0x10dbb
cvtsi2sd %ecx, %xmm0
movq (%rbp), %rcx
movsd (%rcx,%rax,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
jmp 0x10dc4
movq (%rbp), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x10d7d
movl $0x61e4, %r13d          # imm = 0x61E4
xorl %r15d, %r15d
movq (%r14), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r15
jge 0x10e48
movl -0x18(%rax,%r13,8), %ecx
cmpl $0x2, %ecx
je 0x10df4
cmpl $0x1, %ecx
je 0x10e16
testl %ecx, %ecx
jne 0x10e3f
movl (%rbx,%r12,4), %eax
testl %eax, %eax
je 0x10e36
cvtsi2sd %eax, %xmm0
movq (%rbp), %rax
movsd (%rax,%r15,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r15,8)
jmp 0x10e3f
movq 0x10(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r15,8), %rdi
movl (%rax,%r13,8), %esi
callq 0x336b5
movq (%rbp), %rcx
movl %eax, (%rcx,%r15,8)
jmp 0x10e3f
movq (%rbp), %rax
andq $0x0, (%rax,%r15,8)
incq %r15
addq $0x68, %r13
jmp 0x10dd2
movq 0x10(%rbp), %rbp
incq %r12
leaq 0x39914e(%rip), %r15    # 0x3a9fa4
jmp 0x10d6b
testl %eax, %eax
jne 0x10e69
movq 0x10(%rsp), %rdi
callq 0x10ad2
movq 0x8(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq