// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/data.c
// Function: find_mean_with_missing
Instance find_mean_with_missing(Instanceptr myptr)
{
 /*!Last Changed 02.02.2004 Added safemalloc and safecalloc*/
 int i, *counts;
 Instanceptr temp;
 Instance result;
 int** featurevalues;
 featurevalues = (int **)safemalloc(current_dataset->featurecount * sizeof(int*), "find_mean_with_missing", 5);
 counts = (int *)safecalloc(current_dataset->featurecount, sizeof(int), "find_mean_with_missing", 6);
 temp = myptr;
 result.values = (union value *)safemalloc(current_dataset->featurecount * sizeof(union value), "find_mean_with_missing", 7);
 for (i = 0; i < current_dataset->featurecount; i++)
   switch (current_dataset->features[i].type)
    {
     case INTEGER:result.values[i].intvalue = 0;
                  break;
     case    REAL:result.values[i].floatvalue = 0;
                  break;
     case  STRING:featurevalues[i] = (int *)safecalloc(current_dataset->features[i].valuecount, sizeof(int), "find_mean_with_missing", 15);
                  break;
    }
 while (temp)
  {
   for (i = 0; i < current_dataset->featurecount; i++)
     switch (current_dataset->features[i].type)
      {
       case INTEGER:if (temp->values[i].intvalue != ISELL)
                     {
                      result.values[i].intvalue += temp->values[i].intvalue;
                      counts[i]++;
                     }
                    break;
       case    REAL:if (temp->values[i].floatvalue != ISELL)
                     {
                      result.values[i].floatvalue += temp->values[i].floatvalue;
                      counts[i]++;
                     }
                    break;
       case  STRING:if (temp->values[i].stringindex != -1)
                      featurevalues[i][temp->values[i].stringindex]++;
                    break;
      }
   temp = temp->next;
  }
 for (i = 0; i < current_dataset->featurecount; i++)
   switch (current_dataset->features[i].type)
    {
     case INTEGER:if (counts[i] != 0)
                    result.values[i].intvalue /= counts[i];
                  break;
     case    REAL:if (counts[i] != 0)
                    result.values[i].floatvalue /= counts[i];
                  break;
     case  STRING:result.values[i].stringindex = find_max_in_list(featurevalues[i], current_dataset->features[i].valuecount);
                  break;
    }
 for (i = 0; i < current_dataset->featurecount; i++)
   if (current_dataset->features[i].type == STRING)
     safe_free(featurevalues[i]);
 safe_free(featurevalues);
 safe_free(counts);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r13
movq %rdi, %r15
leaq 0xc393f(%rip), %rbx     # 0xd5870
movq (%rbx), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
leaq 0x944b8(%rip), %r12     # 0xa63fe
movq %r12, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, %r14
movq (%rbx), %rax
movslq 0x1bc(%rax), %rdi
movl $0x4, %esi
movq %r12, %rdx
movl $0x6, %ecx
callq 0x3a1fc
movq %rax, 0x8(%rsp)
movq (%rbx), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
movq %r12, %rsi
movl $0x7, %edx
callq 0x3a0e1
movq %rax, %r12
movq %r15, 0x10(%rsp)
movq %rax, (%r15)
movq (%rbx), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x1200b
movl $0x61e4, %ebp           # imm = 0x61E4
xorl %r15d, %r15d
movl -0x18(%rax,%rbp,8), %ecx
cmpl $0x2, %ecx
je 0x11fed
cmpl $0x1, %ecx
je 0x11fcd
testl %ecx, %ecx
jne 0x11ff5
movl $0x0, (%r12,%r15,8)
jmp 0x11ff5
movslq (%rax,%rbp,8), %rdi
movl $0x4, %esi
leaq 0x94421(%rip), %rdx     # 0xa63fe
movl $0xf, %ecx
callq 0x3a1fc
movq %rax, (%r14,%r15,8)
jmp 0x11ff5
movq $0x0, (%r12,%r15,8)
incq %r15
movq (%rbx), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %rbp
cmpq %rcx, %r15
jl 0x11fb1
testq %r13, %r13
je 0x120c5
movsd 0x93cd4(%rip), %xmm0    # 0xa5cf0
movq 0x8(%rsp), %r8
cmpl $0x0, 0x1bc(%rax)
jle 0x120b8
movl $0xc3c2, %ecx           # imm = 0xC3C2
movq %r8, %rdx
xorl %esi, %esi
movl (%rax,%rcx,4), %eax
cmpl $0x2, %eax
je 0x12079
cmpl $0x1, %eax
je 0x12061
testl %eax, %eax
jne 0x1209b
movq (%r13), %rax
movl (%rax,%rsi,8), %eax
cmpl $0x75bcd15, %eax        # imm = 0x75BCD15
je 0x1209b
addl %eax, (%r12,%rsi,8)
leaq (%r8,%rsi,4), %rax
jmp 0x12099
movq (%r13), %rax
movslq (%rax,%rsi,8), %rax
cmpq $-0x1, %rax
je 0x1209b
shlq $0x2, %rax
addq (%r14,%rsi,8), %rax
jmp 0x12099
movq (%r13), %rax
movsd (%rax,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1208a
jnp 0x1209b
addsd (%r12,%rsi,8), %xmm1
movsd %xmm1, (%r12,%rsi,8)
movq %rdx, %rax
incl (%rax)
incq %rsi
movq (%rbx), %rax
movslq 0x1bc(%rax), %rdi
addq $0x4, %rdx
addq $0xd0, %rcx
cmpq %rdi, %rsi
jl 0x12038
movq 0x10(%r13), %r13
testq %r13, %r13
jne 0x12021
cmpl $0x0, 0x1bc(%rax)
jle 0x12181
movl $0xc3c8, %r13d          # imm = 0xC3C8
xorl %ebp, %ebp
movq 0x8(%rsp), %r15
movl -0x18(%rax,%r13,4), %ecx
cmpl $0x2, %ecx
je 0x12116
cmpl $0x1, %ecx
je 0x12103
testl %ecx, %ecx
jne 0x12135
movl (%r15,%rbp,4), %ecx
testl %ecx, %ecx
je 0x12135
movl (%r12,%rbp,8), %eax
cltd
idivl %ecx
jmp 0x12110
movq (%r14,%rbp,8), %rdi
movl (%rax,%r13,4), %esi
callq 0x38002
movl %eax, (%r12,%rbp,8)
jmp 0x12135
movl (%r15,%rbp,4), %eax
testl %eax, %eax
je 0x12135
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd (%r12,%rbp,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r12,%rbp,8)
incq %rbp
movq (%rbx), %rax
movslq 0x1bc(%rax), %rcx
addq $0xd0, %r13
cmpq %rcx, %rbp
jl 0x120df
testl %ecx, %ecx
jle 0x12181
movl $0x61e1, %r15d          # imm = 0x61E1
xorl %r12d, %r12d
cmpl $0x1, (%rax,%r15,8)
jne 0x1216e
movq (%r14,%r12,8), %rdi
callq 0x3a180
movq (%rbx), %rax
incq %r12
movslq 0x1bc(%rax), %rcx
addq $0x68, %r15
cmpq %rcx, %r12
jl 0x1215b
movq %r14, %rdi
callq 0x3a180
movq 0x8(%rsp), %rdi
callq 0x3a180
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq