// File: /workspace/github_c_makefile_star2_O3/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 0x3a06af(%rip), %r15    # 0x3b1fa4
xorl %eax, %eax
cmpl $0x0, (%r15)
setne %al
leaq 0xc3f6b(%rip), %r14     # 0xd5870
movq (%r14), %rcx
movl 0x10(%rcx), %esi
movl 0x1bc(%rcx,%rax,4), %edi
callq 0x116c9
movq %rax, %r13
cmpl $0x0, (%r15)
je 0x1192b
movq $0x0, 0x8(%rsp)
jmp 0x11935
callq 0x11706
movq %rax, 0x8(%rsp)
testq %r13, %r13
je 0x11aaa
movq %r13, %rax
cmpl $0x0, (%r15)
movq (%r14), %rcx
je 0x1197f
cmpl $0x0, 0x1c0(%rcx)
jle 0x119b9
xorl %edx, %edx
movl 0x1407128(%rcx), %esi
cmpq %rsi, %rdx
je 0x1196e
movq (%rax), %rcx
movq $0x0, (%rcx,%rdx,8)
movq (%r14), %rcx
incq %rdx
movslq 0x1c0(%rcx), %rsi
cmpq %rsi, %rdx
jl 0x11955
jmp 0x119b9
cmpl $0x0, 0x1bc(%rcx)
jle 0x119b9
movl $0x61e1, %edx           # imm = 0x61E1
xorl %esi, %esi
testl $0xfffffffd, (%rcx,%rdx,8) # imm = 0xFFFFFFFD
jne 0x119a3
movq (%rax), %rcx
movq $0x0, (%rcx,%rsi,8)
incq %rsi
movq (%r14), %rcx
movslq 0x1bc(%rcx), %rdi
addq $0x68, %rdx
cmpq %rdi, %rsi
jl 0x1198f
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x11941
jmp 0x11aaa
movq %r12, %rdi
callq 0x2f33a
movl %eax, %ebp
movq %r13, %rdi
movl %eax, %esi
callq 0x31851
cmpl $0x0, (%r15)
movq (%r14), %rcx
je 0x11a2c
cmpl $0x0, 0x1c0(%rcx)
jle 0x11aa5
xorl %edx, %edx
movl 0x1407128(%rcx), %esi
cmpq %rsi, %rdx
je 0x11a1b
movq (%r12), %rcx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rcx
addsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
movq (%r14), %rcx
incq %rdx
movslq 0x1c0(%rcx), %rsi
cmpq %rsi, %rdx
jl 0x119f7
jmp 0x11aa5
cmpl $0x0, 0x1bc(%rcx)
jle 0x11aa5
movslq %ebp, %rdx
movl $0x61e1, %esi           # imm = 0x61E1
xorl %edi, %edi
movl (%rcx,%rsi,8), %ecx
cmpl $0x2, %ecx
je 0x11a79
cmpl $0x1, %ecx
je 0x11a5e
testl %ecx, %ecx
jne 0x11a8f
movq (%r12), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx,%rdi,8), %xmm0
jmp 0x11a82
movq 0x8(%rsp), %rcx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rdi,8), %rcx
movq (%r12), %r8
movslq (%r8,%rdi,8), %r8
incl (%rcx,%r8,4)
jmp 0x11a8f
movq (%r12), %rcx
movsd (%rcx,%rdi,8), %xmm0
movq (%rax), %rcx
addsd (%rcx,%rdi,8), %xmm0
movsd %xmm0, (%rcx,%rdi,8)
incq %rdi
movq (%r14), %rcx
movslq 0x1bc(%rcx), %r8
addq $0x68, %rsi
cmpq %r8, %rdi
jl 0x11a3f
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x119cb
movq %r13, 0x10(%rsp)
testq %r13, %r13
je 0x11bd9
xorl %r12d, %r12d
movq 0x10(%rsp), %rbp
cmpl $0x0, (%r15)
movq (%r14), %rax
je 0x11b32
cmpl $0x0, 0x1c0(%rax)
jle 0x11bc2
xorl %ecx, %ecx
movl 0x1407128(%rax), %eax
cmpq %rax, %rcx
je 0x11b1b
movl (%rbx,%r12,4), %eax
testl %eax, %eax
je 0x11b0f
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq (%rbp), %rax
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
jmp 0x11b1b
movq (%rbp), %rax
movq $0x0, (%rax,%rcx,8)
incq %rcx
movq (%r14), %rax
movslq 0x1c0(%rax), %rdx
cmpq %rdx, %rcx
jl 0x11ae1
jmp 0x11bc2
cmpl $0x0, 0x1bc(%rax)
jle 0x11bc2
movl $0x61e4, %r13d          # imm = 0x61E4
xorl %r15d, %r15d
movl -0x18(%rax,%r13,8), %ecx
cmpl $0x2, %ecx
je 0x11b5b
cmpl $0x1, %ecx
je 0x11b80
testl %ecx, %ecx
jne 0x11bac
movl (%rbx,%r12,4), %eax
testl %eax, %eax
je 0x11ba0
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq (%rbp), %rax
movsd (%rax,%r15,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r15,8)
jmp 0x11bac
movq 0x8(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r15,8), %rdi
movl (%rax,%r13,8), %esi
callq 0x38002
movq (%rbp), %rcx
movl %eax, (%rcx,%r15,8)
jmp 0x11bac
movq (%rbp), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
movq (%r14), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %r13
cmpq %rcx, %r15
jl 0x11b48
movq 0x10(%rbp), %rbp
incq %r12
testq %rbp, %rbp
leaq 0x3a03d1(%rip), %r15    # 0x3b1fa4
jne 0x11ac9
cmpl $0x0, (%r15)
jne 0x11be9
movq 0x8(%rsp), %rdi
callq 0x117d8
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq