// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/dataset.c
// Function: nn_ratio
double nn_ratio(Datasetptr d, double *estimate)
{
 /* multiclass is handled by one vs one */
 Instance mean, variance;
 Instanceptr temp, traindata, *nearestneighbors;
 int count, cno1, cno2;
 double result = 0;
 double intraclass = 0, interclass = 0, dist;
 int intranum = 0, internum = 0;
 read_from_train_file(d, &traindata);
 mean = find_mean(traindata);
 variance = find_variance(traindata);
 normalize(traindata, mean, variance);
 type_change(d);
 temp = traindata;
 count = 2;
 while(temp)
  {
   nearestneighbors = find_nearest_neighbors(traindata, temp, count);
   dist = distance_between_instances(nearestneighbors[1], temp);
   cno1 = give_classno(nearestneighbors[1]);
   cno2 = give_classno(temp);
   if (cno1 == cno2)
    {
     intraclass += dist;
     intranum++;
    }
   else
    {
     interclass += dist;
     internum++;
    }
   temp = temp->next;
   safe_free(nearestneighbors);
  }
 result = intraclass / interclass;
 *estimate = (double) internum / (internum + intranum); 
 safe_free(mean.values);
 safe_free(variance.values);
 type_restore(d);
 deallocate(traindata);
 traindata = NULL;
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, 0x80(%rsp)
movq %rdi, %rbx
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x5c7af
movq (%r15), %rsi
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
callq 0x12519
movq (%r15), %rsi
leaq 0x88(%rsp), %r13
movq %r13, %rdi
callq 0x1286d
movq (%r15), %rdi
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x50(%rsp)
movups %xmm1, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
movupd (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x107bc
movslq 0x1bc(%rbx), %rax
testq %rax, %rax
jle 0x19e52
imulq $0x340, %rax, %rax      # imm = 0x340
xorl %ecx, %ecx
movl 0x30f08(%rbx,%rcx), %edx
movl %edx, 0x30f0c(%rbx,%rcx)
testl %edx, %edx
jne 0x19e46
movl $0x2, 0x30f08(%rbx,%rcx)
addq $0x340, %rcx            # imm = 0x340
cmpq %rcx, %rax
jne 0x19e29
movq 0x70(%rsp), %r15
testq %r15, %r15
je 0x19ef4
xorpd %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movsd %xmm0, 0x60(%rsp)
movq 0x70(%rsp), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x30ca9
movq %rax, %r12
movq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x2f4ea
movsd %xmm0, 0x78(%rsp)
movq 0x8(%r12), %rdi
callq 0x2eaca
movl %eax, %ebp
movq %r15, %rdi
callq 0x2eaca
cmpl %eax, %ebp
jne 0x19ecc
movsd 0x60(%rsp), %xmm0
addsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
incl %r13d
jmp 0x19ee1
movsd 0x68(%rsp), %xmm0
addsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
incl %r14d
movq 0x10(%r15), %r15
movq %r12, %rdi
callq 0x39194
testq %r15, %r15
jne 0x19e76
jmp 0x19f0a
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movsd %xmm0, 0x68(%rsp)
xorl %r14d, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
addl %r14d, %r13d
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
divsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, (%rax)
movq 0xb8(%rsp), %rdi
callq 0x39194
movq 0x88(%rsp), %rdi
callq 0x39194
movslq 0x1bc(%rbx), %rax
testq %rax, %rax
jle 0x19f76
imulq $0x340, %rax, %rax      # imm = 0x340
xorl %ecx, %ecx
movl 0x30f0c(%rbx,%rcx), %edx
movl %edx, 0x30f08(%rbx,%rcx)
addq $0x340, %rcx            # imm = 0x340
cmpq %rcx, %rax
jne 0x19f5c
movsd 0x60(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x70(%rsp), %rdi
callq 0x2f616
movsd 0x60(%rsp), %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq