// File: /workspace/github_c_makefile_star2_O1/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 0x39d671(%rip), %r15    # 0x3aefa4
xorl %eax, %eax
cmpl $0x0, (%r15)
setne %al
leaq 0xc0f2d(%rip), %r14     # 0xd2870
movq (%r14), %rcx
movl 0x10(%rcx), %esi
movl 0x1bc(%rcx,%rax,4), %edi
callq 0x11704
movq %rax, %r13
cmpl $0x0, (%r15)
je 0x11969
movq $0x0, 0x8(%rsp)
jmp 0x11973
callq 0x11741
movq %rax, 0x8(%rsp)
testq %r13, %r13
je 0x11ae8
movq %r13, %rax
cmpl $0x0, (%r15)
movq (%r14), %rcx
je 0x119bd
cmpl $0x0, 0x1c0(%rcx)
jle 0x119f7
xorl %edx, %edx
movl 0x1407128(%rcx), %ecx
cmpq %rcx, %rdx
je 0x119a9
movq (%rax), %rcx
movq $0x0, (%rcx,%rdx,8)
incq %rdx
movq (%r14), %rcx
movslq 0x1c0(%rcx), %rsi
cmpq %rsi, %rdx
jl 0x11993
jmp 0x119f7
cmpl $0x0, 0x1bc(%rcx)
jle 0x119f7
movl $0x61e1, %edx           # imm = 0x61E1
xorl %esi, %esi
testl $0xfffffffd, (%rcx,%rdx,8) # imm = 0xFFFFFFFD
jne 0x119e1
movq (%rax), %rcx
movq $0x0, (%rcx,%rsi,8)
incq %rsi
movq (%r14), %rcx
movslq 0x1bc(%rcx), %rdi
addq $0x68, %rdx
cmpq %rdi, %rsi
jl 0x119cd
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x1197f
jmp 0x11ae8
movq %r12, %rdi
callq 0x2eaca
movl %eax, %ebp
movq %r13, %rdi
movl %eax, %esi
callq 0x30fe5
cmpl $0x0, (%r15)
movq (%r14), %rdi
je 0x11a6a
cmpl $0x0, 0x1c0(%rdi)
jle 0x11ae3
xorl %ecx, %ecx
movl 0x1407128(%rdi), %edx
cmpq %rdx, %rcx
je 0x11a56
movq (%r12), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%rax), %rdx
addsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
movq (%r14), %rdi
movslq 0x1c0(%rdi), %rdx
cmpq %rdx, %rcx
jl 0x11a35
jmp 0x11ae3
cmpl $0x0, 0x1bc(%rdi)
jle 0x11ae3
movslq %ebp, %rcx
movl $0x61e1, %edx           # imm = 0x61E1
xorl %esi, %esi
movl (%rdi,%rdx,8), %edi
cmpl $0x2, %edi
je 0x11ab7
cmpl $0x1, %edi
je 0x11a9c
testl %edi, %edi
jne 0x11acd
movq (%r12), %rdi
xorps %xmm0, %xmm0
cvtsi2sdl (%rdi,%rsi,8), %xmm0
jmp 0x11ac0
movq 0x8(%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 0x11acd
movq (%r12), %rdi
movsd (%rdi,%rsi,8), %xmm0
movq (%rax), %rdi
addsd (%rdi,%rsi,8), %xmm0
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
movq (%r14), %rdi
movslq 0x1bc(%rdi), %r8
addq $0x68, %rdx
cmpq %r8, %rsi
jl 0x11a7d
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x11a09
movq %r13, 0x10(%rsp)
testq %r13, %r13
je 0x11c17
xorl %r12d, %r12d
movq 0x10(%rsp), %rbp
cmpl $0x0, (%r15)
movq (%r14), %rax
je 0x11b70
cmpl $0x0, 0x1c0(%rax)
jle 0x11c00
xorl %ecx, %ecx
movl 0x1407128(%rax), %eax
cmpq %rax, %rcx
je 0x11b59
movl (%rbx,%r12,4), %eax
testl %eax, %eax
je 0x11b4d
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq (%rbp), %rax
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
jmp 0x11b59
movq (%rbp), %rax
movq $0x0, (%rax,%rcx,8)
incq %rcx
movq (%r14), %rax
movslq 0x1c0(%rax), %rdx
cmpq %rdx, %rcx
jl 0x11b1f
jmp 0x11c00
cmpl $0x0, 0x1bc(%rax)
jle 0x11c00
movl $0x61e4, %r13d          # imm = 0x61E4
xorl %r15d, %r15d
movl -0x18(%rax,%r13,8), %ecx
cmpl $0x2, %ecx
je 0x11b99
cmpl $0x1, %ecx
je 0x11bbe
testl %ecx, %ecx
jne 0x11bea
movl (%rbx,%r12,4), %eax
testl %eax, %eax
je 0x11bde
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq (%rbp), %rax
movsd (%rax,%r15,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r15,8)
jmp 0x11bea
movq 0x8(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r15,8), %rdi
movl (%rax,%r13,8), %esi
callq 0x37504
movq (%rbp), %rcx
movl %eax, (%rcx,%r15,8)
jmp 0x11bea
movq (%rbp), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
movq (%r14), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %r13
cmpq %rcx, %r15
jl 0x11b86
movq 0x10(%rbp), %rbp
incq %r12
testq %rbp, %rbp
leaq 0x39d393(%rip), %r15    # 0x3aefa4
jne 0x11b07
cmpl $0x0, (%r15)
jne 0x11c27
movq 0x8(%rsp), %rdi
callq 0x11816
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq