// File: /workspace/github_c_makefile_star2_O3/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, %rbx
leaq 0x39fb0e(%rip), %rax    # 0x3b1fa4
cmpl $0x0, (%rax)
leaq 0xc33d0(%rip), %r13     # 0xd5870
movq (%r13), %rax
je 0x1255b
movslq 0x1c0(%rax), %rdi
shlq $0x3, %rdi
leaq 0x93f59(%rip), %rsi     # 0xa6415
movl $0x7, %edx
callq 0x3a0e1
movq %rax, (%rbx)
movq (%r13), %rcx
cmpl $0x0, 0x1c0(%rcx)
jle 0x124fe
xorl %edx, %edx
movl 0x1407128(%rcx), %esi
cmpq %rsi, %rdx
je 0x124ef
movq $0x0, (%rax,%rdx,8)
movq (%r13), %rcx
incq %rdx
movslq 0x1c0(%rcx), %rsi
cmpq %rsi, %rdx
jl 0x124d8
testq %r14, %r14
je 0x126b7
xorl %edx, %edx
cmpl $0x0, 0x1c0(%rcx)
jle 0x12544
xorl %esi, %esi
movl 0x1407128(%rcx), %edi
cmpq %rdi, %rsi
je 0x12535
movq (%r14), %rcx
movsd (%rcx,%rsi,8), %xmm0
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rsi,8)
movq (%r13), %rcx
incq %rsi
movslq 0x1c0(%rcx), %rdi
cmpq %rdi, %rsi
jl 0x12514
incl %edx
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x12509
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x126bb
movq %rbx, 0x8(%rsp)
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
leaq 0x93ea3(%rip), %rsi     # 0xa6415
movl $0x19, %edx
callq 0x3a0e1
movq %rax, %r15
movq (%r13), %rax
movslq 0x1bc(%rax), %rdi
testq %rdi, %rdi
jle 0x125d5
movl $0x61e4, %ebp           # imm = 0x61E4
xorl %ebx, %ebx
leaq 0x93e78(%rip), %r12     # 0xa6415
cmpl $0x1, -0x18(%rax,%rbp,8)
jne 0x125c2
movslq (%rax,%rbp,8), %rdi
movl $0x4, %esi
movq %r12, %rdx
movl $0x1c, %ecx
callq 0x3a1fc
movq %rax, (%r15,%rbx,8)
movq (%r13), %rax
incq %rbx
movslq 0x1bc(%rax), %rdi
addq $0x68, %rbp
cmpq %rdi, %rbx
jl 0x1259d
shlq $0x3, %rdi
leaq 0x93e35(%rip), %rsi     # 0xa6415
movl $0x1d, %edx
callq 0x3a0e1
movq %rax, %r12
movq 0x8(%rsp), %rbp
movq %rax, (%rbp)
movq (%r13), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x12632
movl $0x61e1, %ecx           # imm = 0x61E1
xorl %edx, %edx
testl $0xfffffffd, (%rax,%rcx,8) # imm = 0xFFFFFFFD
jne 0x1261b
movq $0x0, (%r12,%rdx,8)
incq %rdx
movq (%r13), %rax
movslq 0x1bc(%rax), %rsi
addq $0x68, %rcx
cmpq %rsi, %rdx
jl 0x1260a
testq %r14, %r14
je 0x126fa
xorl %ecx, %ecx
cmpl $0x0, 0x1bc(%rax)
jle 0x126a6
movl $0x61e1, %edx           # imm = 0x61E1
xorl %esi, %esi
movl (%rax,%rdx,8), %eax
cmpl $0x2, %eax
je 0x1267b
cmpl $0x1, %eax
je 0x1266b
testl %eax, %eax
jne 0x1268f
movq (%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rsi,8), %xmm0
jmp 0x12683
movq (%r15,%rsi,8), %rax
movq (%r14), %rdi
movslq (%rdi,%rsi,8), %rdi
incl (%rax,%rdi,4)
jmp 0x1268f
movq (%r14), %rax
movsd (%rax,%rsi,8), %xmm0
addsd (%r12,%rsi,8), %xmm0
movsd %xmm0, (%r12,%rsi,8)
incq %rsi
movq (%r13), %rax
movslq 0x1bc(%rax), %rdi
addq $0x68, %rdx
cmpq %rdi, %rsi
jl 0x1264d
incl %ecx
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x1263d
cvtsi2sd %ecx, %xmm1
jmp 0x126fe
xorpd %xmm0, %xmm0
cmpl $0x0, 0x1c0(%rcx)
jle 0x126f2
xorl %edx, %edx
movl 0x1407128(%rcx), %esi
cmpq %rsi, %rdx
je 0x126e3
movsd (%rax,%rdx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rdx,8)
movq (%r13), %rcx
incq %rdx
movslq 0x1c0(%rcx), %rsi
cmpq %rsi, %rdx
jl 0x126c6
movq %rbx, %rax
jmp 0x127ae
xorpd %xmm1, %xmm1
cmpl $0x0, 0x1bc(%rax)
jle 0x127a3
movl $0x61e4, %r14d          # imm = 0x61E4
xorl %ebp, %ebp
movsd %xmm1, 0x10(%rsp)
movl -0x18(%rax,%r14,8), %ecx
cmpl $0x2, %ecx
je 0x1272c
cmpl $0x1, %ecx
je 0x1273e
testl %ecx, %ecx
jne 0x12755
movsd (%r12,%rbp,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r12,%rbp,8)
jmp 0x12755
movq (%r15,%rbp,8), %rdi
movl (%rax,%r14,8), %esi
callq 0x38002
movsd 0x10(%rsp), %xmm1
movl %eax, (%r12,%rbp,8)
incq %rbp
movq (%r13), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %r14
cmpq %rcx, %rbp
jl 0x12719
testl %ecx, %ecx
movq 0x8(%rsp), %rbp
jle 0x127a3
movl $0x61e1, %ebx           # imm = 0x61E1
xorl %r14d, %r14d
cmpl $0x1, (%rax,%rbx,8)
jne 0x12790
movq (%r15,%r14,8), %rdi
callq 0x3a180
movq (%r13), %rax
incq %r14
movslq 0x1bc(%rax), %rcx
addq $0x68, %rbx
cmpq %rcx, %r14
jl 0x1277d
movq %r15, %rdi
callq 0x3a180
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq