// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/data.c
// Function: find_mean
Instance find_mean(Instanceptr myptr)
{
 /*!Last Changed 02.02.2004 added safemalloc and safecalloc*/
 /*!Last Changed 19.03.2002*/
 int i,count=0;
 Instanceptr temp=myptr;
 int** feature_counts;
 Instance result;
 if (mustrealize)
  {
   result.values = (union value *)safemalloc(current_dataset->multifeaturecount*sizeof(union value), "find_mean", 7);
   for (i = 0;i < current_dataset->multifeaturecount; i++)
     if (i != current_dataset->classdefno)
       result.values[i].floatvalue = 0;
   while (temp)
    {
     for (i = 0;i < current_dataset->multifeaturecount; i++)
       if (i != current_dataset->classdefno)
         result.values[i].floatvalue += temp->values[i].floatvalue;
     count++;
     temp = temp->next;
    }
   for (i = 0; i < current_dataset->multifeaturecount; i++)
     if (i != current_dataset->classdefno)
       result.values[i].floatvalue /= count;
  }
 else
  {
   feature_counts = (int **)safemalloc(current_dataset->featurecount * sizeof(int *), "find_mean", 25);
   for (i = 0; i < current_dataset->featurecount; i++)
     if (current_dataset->features[i].type == STRING)
       feature_counts[i] = (int *)safecalloc(current_dataset->features[i].valuecount, sizeof(int), "find_mean", 28);
   result.values = (union value *)safemalloc(current_dataset->featurecount * sizeof(union value), "find_mean", 29);
   for (i = 0; i < current_dataset->featurecount; i++)
     switch (current_dataset->features[i].type)
      {
       case INTEGER:result.values[i].floatvalue = 0;
                    break;
       case    REAL:result.values[i].floatvalue = 0;
                    break;
      }
   while (temp)/*Adding values to total*/
    {
     for (i = 0; i < current_dataset->featurecount; i++)
       switch (current_dataset->features[i].type)
        {
         case INTEGER:result.values[i].floatvalue += temp->values[i].intvalue;
                      break;
         case    REAL:result.values[i].floatvalue += temp->values[i].floatvalue;
                      break;
         case  STRING:feature_counts[i][temp->values[i].stringindex]++;
                      break;
        }
     count++;
     temp = temp->next;
    }
   for (i = 0; i < current_dataset->featurecount; i++)
     switch (current_dataset->features[i].type)
      {
       case INTEGER:result.values[i].floatvalue /= count;
                    break;
       case    REAL:result.values[i].floatvalue /= count;
                    break;
       case  STRING:result.values[i].stringindex = find_max_in_list(feature_counts[i], current_dataset->features[i].valuecount);
                    break;
      }
   for (i = 0; i < current_dataset->featurecount; i++)
     if (current_dataset->features[i].type == STRING)     
       safe_free(feature_counts[i]);
   safe_free(feature_counts);
  }
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x3988d3(%rip), %rax    # 0x3a9fa4
cmpl $0x0, (%rax)
leaq 0xbc195(%rip), %rbx     # 0xcd870
movq (%rbx), %rax
je 0x117a7
movslq 0x1c0(%rax), %rdi
shlq $0x3, %rdi
leaq 0x84d1f(%rip), %rsi     # 0x96415
pushq $0x7
popq %rdx
callq 0x34f59
movq %rax, (%r15)
movq (%rbx), %rcx
xorl %edx, %edx
movslq 0x1c0(%rcx), %rsi
cmpq %rsi, %rdx
jge 0x1172a
movl 0x1407128(%rcx), %esi
cmpq %rsi, %rdx
je 0x11725
andq $0x0, (%rax,%rdx,8)
movq (%rbx), %rcx
incq %rdx
jmp 0x11706
xorl %edx, %edx
testq %r14, %r14
je 0x1176c
xorl %esi, %esi
movslq 0x1c0(%rcx), %rdi
cmpq %rdi, %rsi
jge 0x11764
movl 0x1407128(%rcx), %edi
cmpq %rdi, %rsi
je 0x1175f
movq (%r14), %rcx
movsd (%rcx,%rsi,8), %xmm0
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rsi,8)
movq (%rbx), %rcx
incq %rsi
jmp 0x11733
incl %edx
movq 0x10(%r14), %r14
jmp 0x1172c
cvtsi2sd %edx, %xmm0
xorl %edx, %edx
movslq 0x1c0(%rcx), %rsi
cmpq %rsi, %rdx
jge 0x1179f
movl 0x1407128(%rcx), %esi
cmpq %rsi, %rdx
je 0x1179a
movsd (%rax,%rdx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rdx,8)
movq (%rbx), %rcx
incq %rdx
jmp 0x11772
movq %r15, %rax
jmp 0x1196f
movq %r15, 0x8(%rsp)
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
leaq 0x84c57(%rip), %rsi     # 0x96415
pushq $0x19
popq %rdx
callq 0x34f59
movq %rax, %r15
movq (%rbx), %rax
movl $0x61e4, %r12d          # imm = 0x61E4
xorl %r13d, %r13d
pushq $0x1c
popq %rbp
movslq 0x1bc(%rax), %rdi
cmpq %rdi, %r13
jge 0x11811
cmpl $0x1, -0x18(%rax,%r12,8)
jne 0x11808
movslq (%rax,%r12,8), %rdi
pushq $0x4
popq %rsi
leaq 0x84c1b(%rip), %rdx     # 0x96415
movl %ebp, %ecx
callq 0x35067
movq %rax, (%r15,%r13,8)
movq (%rbx), %rax
incq %r13
addq $0x68, %r12
jmp 0x117d8
shlq $0x3, %rdi
leaq 0x84bf9(%rip), %rsi     # 0x96415
pushq $0x1d
popq %rdx
callq 0x34f59
movq %rax, %r12
movq 0x8(%rsp), %rbp
movq %rax, (%rbp)
movl $0x61e1, %ecx           # imm = 0x61E1
xorl %edx, %edx
movq (%rbx), %rax
movslq 0x1bc(%rax), %rsi
cmpq %rsi, %rdx
jge 0x1185d
testl $0xfffffffd, (%rax,%rcx,8) # imm = 0xFFFFFFFD
jne 0x11854
andq $0x0, (%r12,%rdx,8)
incq %rdx
addq $0x68, %rcx
jmp 0x11837
xorl %ecx, %ecx
testq %r14, %r14
je 0x118ca
movl $0x61e1, %edx           # imm = 0x61E1
xorl %esi, %esi
movslq 0x1bc(%rax), %rdi
cmpq %rdi, %rsi
jge 0x118c2
movl (%rax,%rdx,8), %eax
cmpl $0x2, %eax
je 0x118a2
cmpl $0x1, %eax
je 0x11892
testl %eax, %eax
jne 0x118b6
movq (%r14), %rax
cvtsi2sdl (%rax,%rsi,8), %xmm0
jmp 0x118aa
movq (%r15,%rsi,8), %rax
movq (%r14), %rdi
movslq (%rdi,%rsi,8), %rdi
incl (%rax,%rdi,4)
jmp 0x118b6
movq (%r14), %rax
movsd (%rax,%rsi,8), %xmm0
addsd (%r12,%rsi,8), %xmm0
movsd %xmm0, (%r12,%rsi,8)
incq %rsi
movq (%rbx), %rax
addq $0x68, %rdx
jmp 0x1186b
incl %ecx
movq 0x10(%r14), %r14
jmp 0x1185f
cvtsi2sd %ecx, %xmm1
movl $0x61e4, %r14d          # imm = 0x61E4
xorl %r13d, %r13d
movsd %xmm1, 0x10(%rsp)
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r13
jge 0x11931
movl -0x18(%rax,%r14,8), %ecx
cmpl $0x2, %ecx
je 0x118fc
cmpl $0x1, %ecx
je 0x1190e
testl %ecx, %ecx
jne 0x11925
movsd (%r12,%r13,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r12,%r13,8)
jmp 0x11925
movq (%r15,%r13,8), %rdi
movl (%rax,%r14,8), %esi
callq 0x336b5
movsd 0x10(%rsp), %xmm1
movl %eax, (%r12,%r13,8)
incq %r13
movq (%rbx), %rax
addq $0x68, %r14
jmp 0x118dd
movl $0x61e1, %r14d          # imm = 0x61E1
xorl %r12d, %r12d
movslq %ecx, %rdx
cmpq %rdx, %r12
jge 0x11964
cmpl $0x1, (%rax,%r14,8)
jne 0x1195b
movq (%r15,%r12,8), %rdi
callq 0x34ff7
movq (%rbx), %rax
movl 0x1bc(%rax), %ecx
incq %r12
addq $0x68, %r14
jmp 0x1193a
movq %r15, %rdi
callq 0x34ff7
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq