// File: /workspace/github_c_makefile_star2_O1/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 0x39ca70(%rip), %rax    # 0x3aefa4
cmpl $0x0, (%rax)
leaq 0xc0332(%rip), %r13     # 0xd2870
movq (%r13), %rax
je 0x125fd
movslq 0x1c0(%rax), %rdi
shlq $0x3, %rdi
leaq 0x90ebb(%rip), %rsi     # 0xa3415
movl $0x7, %edx
callq 0x390f5
movq %rax, (%rbx)
movq (%r13), %rdx
cmpl $0x0, 0x1c0(%rdx)
jle 0x1259c
xorl %ecx, %ecx
movl 0x1407128(%rdx), %edx
cmpq %rdx, %rcx
je 0x12589
movq $0x0, (%rax,%rcx,8)
incq %rcx
movq (%r13), %rdx
movslq 0x1c0(%rdx), %rsi
cmpq %rsi, %rcx
jl 0x12576
testq %r14, %r14
je 0x1275d
xorl %ecx, %ecx
movq (%r13), %rsi
cmpl $0x0, 0x1c0(%rsi)
jle 0x125e6
xorl %edx, %edx
movl 0x1407128(%rsi), %esi
cmpq %rsi, %rdx
je 0x125d3
movq (%r14), %rsi
movsd (%rsi,%rdx,8), %xmm0
addsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
movq (%r13), %rsi
movslq 0x1c0(%rsi), %rdi
cmpq %rdi, %rdx
jl 0x125b6
incl %ecx
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x125a7
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
jmp 0x12761
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
leaq 0x90e06(%rip), %rsi     # 0xa3415
movl $0x19, %edx
callq 0x390f5
movq %rax, %r15
movq (%r13), %rax
movl 0x1bc(%rax), %ecx
testl %ecx, %ecx
movq %rbx, 0x8(%rsp)
jle 0x1267a
movl $0x61e4, %ebp           # imm = 0x61E4
xorl %ebx, %ebx
leaq 0x90dd8(%rip), %r12     # 0xa3415
cmpl $0x1, -0x18(%rax,%rbp,8)
jne 0x1265e
movslq (%rax,%rbp,8), %rdi
movl $0x4, %esi
movq %r12, %rdx
movl $0x1c, %ecx
callq 0x39210
movq %rax, (%r15,%rbx,8)
incq %rbx
movq (%r13), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %rbp
cmpq %rcx, %rbx
jl 0x1263d
movq 0x8(%rsp), %rbx
movslq %ecx, %rdi
shlq $0x3, %rdi
leaq 0x90d8d(%rip), %rsi     # 0xa3415
movl $0x1d, %edx
callq 0x390f5
movq %rax, %r12
movq %rax, (%rbx)
movq (%r13), %rdx
cmpl $0x0, 0x1bc(%rdx)
jle 0x126d4
movl $0x61e1, %eax           # imm = 0x61E1
xorl %ecx, %ecx
testl $0xfffffffd, (%rdx,%rax,8) # imm = 0xFFFFFFFD
jne 0x126bd
movq $0x0, (%r12,%rcx,8)
incq %rcx
movq (%r13), %rdx
movslq 0x1bc(%rdx), %rsi
addq $0x68, %rax
cmpq %rsi, %rcx
jl 0x126ac
testq %r14, %r14
je 0x127a4
xorl %eax, %eax
movq (%r13), %rsi
cmpl $0x0, 0x1bc(%rsi)
jle 0x1274c
movl $0x61e1, %ecx           # imm = 0x61E1
xorl %edx, %edx
movl (%rsi,%rcx,8), %esi
cmpl $0x2, %esi
je 0x12721
cmpl $0x1, %esi
je 0x12711
testl %esi, %esi
jne 0x12735
movq (%r14), %rsi
xorps %xmm0, %xmm0
cvtsi2sdl (%rsi,%rdx,8), %xmm0
jmp 0x12729
movq (%r15,%rdx,8), %rsi
movq (%r14), %rdi
movslq (%rdi,%rdx,8), %rdi
incl (%rsi,%rdi,4)
jmp 0x12735
movq (%r14), %rsi
movsd (%rsi,%rdx,8), %xmm0
addsd (%r12,%rdx,8), %xmm0
movsd %xmm0, (%r12,%rdx,8)
incq %rdx
movq (%r13), %rsi
movslq 0x1bc(%rsi), %rdi
addq $0x68, %rcx
cmpq %rdi, %rdx
jl 0x126f3
incl %eax
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x126df
cvtsi2sd %eax, %xmm1
jmp 0x127a8
xorpd %xmm0, %xmm0
movq (%r13), %rdx
cmpl $0x0, 0x1c0(%rdx)
jle 0x1279c
xorl %ecx, %ecx
movl 0x1407128(%rdx), %edx
cmpq %rdx, %rcx
je 0x12789
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incq %rcx
movq (%r13), %rdx
movslq 0x1c0(%rdx), %rsi
cmpq %rsi, %rcx
jl 0x12770
movq %rbx, %rax
jmp 0x1285e
xorpd %xmm1, %xmm1
movq (%r13), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x12816
movl $0x61e4, %r14d          # imm = 0x61E4
xorl %ebp, %ebp
movsd %xmm1, 0x10(%rsp)
movl -0x18(%rax,%r14,8), %ecx
cmpl $0x2, %ecx
je 0x127d6
cmpl $0x1, %ecx
je 0x127e8
testl %ecx, %ecx
jne 0x127ff
movsd (%r12,%rbp,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r12,%rbp,8)
jmp 0x127ff
movq (%r15,%rbp,8), %rdi
movl (%rax,%r14,8), %esi
callq 0x37504
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 0x127c3
movq (%r13), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x12851
movl $0x61e1, %ebx           # imm = 0x61E1
xorl %r14d, %r14d
cmpl $0x1, (%rax,%rbx,8)
jne 0x1283a
movq (%r15,%r14,8), %rdi
callq 0x39194
incq %r14
movq (%r13), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %rbx
cmpq %rcx, %r14
jl 0x1282b
movq %r15, %rdi
callq 0x39194
movq 0x8(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq