// File: /workspace/github_c_makefile_star2_O1/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 0xc08ea(%rip), %rbx     # 0xd2870
movq (%rbx), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
leaq 0x91463(%rip), %r12     # 0xa33fe
movq %r12, %rsi
movl $0x5, %edx
callq 0x390f5
movq %rax, %r14
movq (%rbx), %rax
movslq 0x1bc(%rax), %rdi
movl $0x4, %esi
movq %r12, %rdx
movl $0x6, %ecx
callq 0x39210
movq %rax, 0x8(%rsp)
movq (%rbx), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
movq %r12, %rsi
movl $0x7, %edx
callq 0x390f5
movq %rax, %r12
movq %r15, 0x10(%rsp)
movq %rax, (%r15)
movq (%rbx), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x12060
movl $0x61e4, %ebp           # imm = 0x61E4
xorl %r15d, %r15d
movl -0x18(%rax,%rbp,8), %ecx
cmpl $0x2, %ecx
je 0x12042
cmpl $0x1, %ecx
je 0x12022
testl %ecx, %ecx
jne 0x1204a
movl $0x0, (%r12,%r15,8)
jmp 0x1204a
movslq (%rax,%rbp,8), %rdi
movl $0x4, %esi
leaq 0x913cc(%rip), %rdx     # 0xa33fe
movl $0xf, %ecx
callq 0x39210
movq %rax, (%r14,%r15,8)
jmp 0x1204a
movq $0x0, (%r12,%r15,8)
incq %r15
movq (%rbx), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %rbp
cmpq %rcx, %r15
jl 0x12006
testq %r13, %r13
movq 0x8(%rsp), %r15
je 0x1211d
movsd 0x90c7a(%rip), %xmm0    # 0xa2cf0
movq (%rbx), %rsi
cmpl $0x0, 0x1bc(%rsi)
jle 0x12110
movl $0xc3c2, %eax           # imm = 0xC3C2
movq %r15, %rcx
xorl %edx, %edx
movl (%rsi,%rax,4), %esi
cmpl $0x2, %esi
je 0x120d2
cmpl $0x1, %esi
je 0x120ba
testl %esi, %esi
jne 0x120f4
movq (%r13), %rsi
movl (%rsi,%rdx,8), %esi
cmpl $0x75bcd15, %esi        # imm = 0x75BCD15
je 0x120f4
addl %esi, (%r12,%rdx,8)
leaq (%r15,%rdx,4), %rsi
jmp 0x120f2
movq (%r13), %rsi
movslq (%rsi,%rdx,8), %rsi
cmpq $-0x1, %rsi
je 0x120f4
shlq $0x2, %rsi
addq (%r14,%rdx,8), %rsi
jmp 0x120f2
movq (%r13), %rsi
movsd (%rsi,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x120e3
jnp 0x120f4
addsd (%r12,%rdx,8), %xmm1
movsd %xmm1, (%r12,%rdx,8)
movq %rcx, %rsi
incl (%rsi)
incq %rdx
movq (%rbx), %rsi
movslq 0x1bc(%rsi), %rdi
addq $0x4, %rcx
addq $0xd0, %rax
cmpq %rdi, %rdx
jl 0x12090
movq 0x10(%r13), %r13
testq %r13, %r13
jne 0x12076
movq (%rbx), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x121a0
movl $0xc3c8, %r13d          # imm = 0xC3C8
xorl %ebp, %ebp
movl -0x18(%rax,%r13,4), %ecx
cmpl $0x2, %ecx
je 0x12168
cmpl $0x1, %ecx
je 0x12155
testl %ecx, %ecx
jne 0x12187
movl (%r15,%rbp,4), %ecx
testl %ecx, %ecx
je 0x12187
movl (%r12,%rbp,8), %eax
cltd
idivl %ecx
jmp 0x12162
movq (%r14,%rbp,8), %rdi
movl (%rax,%r13,4), %esi
callq 0x37504
movl %eax, (%r12,%rbp,8)
jmp 0x12187
movl (%r15,%rbp,4), %eax
testl %eax, %eax
je 0x12187
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 0x12131
movq (%rbx), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x121db
movl $0x61e1, %r15d          # imm = 0x61E1
xorl %r12d, %r12d
cmpl $0x1, (%rax,%r15,8)
jne 0x121c5
movq (%r14,%r12,8), %rdi
callq 0x39194
incq %r12
movq (%rbx), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %r15
cmpq %rcx, %r12
jl 0x121b5
movq %r14, %rdi
callq 0x39194
movq 0x8(%rsp), %rdi
callq 0x39194
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq