// File: /workspace/github_c_makefile_star2_O2/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, %rbx
leaq 0xbc6e3(%rip), %rbp     # 0xcd870
movq (%rbp), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
leaq 0x8525b(%rip), %r15     # 0x963fe
pushq $0x5
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %r14
movq (%rbp), %rax
movslq 0x1bc(%rax), %rdi
pushq $0x4
popq %rsi
pushq $0x6
popq %rcx
movq %r15, %rdx
callq 0x35067
movq %rax, 0x8(%rsp)
movq (%rbp), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
pushq $0x7
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %r12
movq %rbx, 0x10(%rsp)
movq %rax, (%rbx)
movl $0x61e4, %ebx           # imm = 0x61E4
xorl %r15d, %r15d
movq (%rbp), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r15
jge 0x1124f
movl -0x18(%rax,%rbx,8), %ecx
cmpl $0x2, %ecx
je 0x11241
cmpl $0x1, %ecx
je 0x11225
testl %ecx, %ecx
jne 0x11246
andl $0x0, (%r12,%r15,8)
jmp 0x11246
movslq (%rax,%rbx,8), %rdi
pushq $0x4
popq %rsi
leaq 0x851cb(%rip), %rdx     # 0x963fe
pushq $0xf
popq %rcx
callq 0x35067
movq %rax, (%r14,%r15,8)
jmp 0x11246
andq $0x0, (%r12,%r15,8)
incq %r15
addq $0x68, %rbx
jmp 0x111fc
movsd 0x84aa1(%rip), %xmm0    # 0x95cf8
movq 0x8(%rsp), %r15
testq %r13, %r13
je 0x112fe
movl $0xc3c2, %ecx           # imm = 0xC3C2
movq %r15, %rdx
xorl %esi, %esi
movslq 0x1bc(%rax), %rdi
cmpq %rdi, %rsi
jge 0x112f5
movl (%rax,%rcx,4), %eax
cmpl $0x2, %eax
je 0x112bc
cmpl $0x1, %eax
je 0x112a4
testl %eax, %eax
jne 0x112de
movq (%r13), %rax
movl (%rax,%rsi,8), %eax
cmpl $0x75bcd15, %eax        # imm = 0x75BCD15
je 0x112de
addl %eax, (%r12,%rsi,8)
leaq (%r15,%rsi,4), %rax
jmp 0x112dc
movq (%r13), %rax
movslq (%rax,%rsi,8), %rax
cmpq $-0x1, %rax
je 0x112de
shlq $0x2, %rax
addq (%r14,%rsi,8), %rax
jmp 0x112dc
movq (%r13), %rax
movsd (%rax,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x112cd
jnp 0x112de
addsd (%r12,%rsi,8), %xmm1
movsd %xmm1, (%r12,%rsi,8)
movq %rdx, %rax
incl (%rax)
incq %rsi
movq (%rbp), %rax
addq $0x4, %rdx
addq $0xd0, %rcx
jmp 0x1126f
movq 0x10(%r13), %r13
jmp 0x1125c
movl $0xc3c8, %ebx           # imm = 0xC3C8
xorl %r13d, %r13d
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r13
jge 0x11373
movl -0x18(%rax,%rbx,4), %ecx
cmpl $0x2, %ecx
je 0x11347
cmpl $0x1, %ecx
je 0x11335
testl %ecx, %ecx
jne 0x11363
movl (%r15,%r13,4), %ecx
testl %ecx, %ecx
je 0x11363
movl (%r12,%r13,8), %eax
cltd
idivl %ecx
jmp 0x11341
movq (%r14,%r13,8), %rdi
movl (%rax,%rbx,4), %esi
callq 0x336b5
movl %eax, (%r12,%r13,8)
jmp 0x11363
movl (%r15,%r13,4), %eax
testl %eax, %eax
je 0x11363
cvtsi2sd %eax, %xmm0
movsd (%r12,%r13,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r12,%r13,8)
incq %r13
movq (%rbp), %rax
addq $0xd0, %rbx
jmp 0x11306
movl $0x61e1, %ebx           # imm = 0x61E1
xorl %r15d, %r15d
movslq %ecx, %rdx
cmpq %rdx, %r15
jge 0x113a5
cmpl $0x1, (%rax,%rbx,8)
jne 0x1139c
movq (%r14,%r15,8), %rdi
callq 0x34ff7
movq (%rbp), %rax
movl 0x1bc(%rax), %ecx
incq %r15
addq $0x68, %rbx
jmp 0x1137b
movq %r14, %rdi
callq 0x34ff7
movq 0x8(%rsp), %rdi
callq 0x34ff7
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq