// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/srm.c
// Function: vc_dimension_for_a_design
double vc_dimension_for_a_design(Vcestimateptr estimates, DESIGN_TYPE experimenttype, int n)
{
 /*!Last Changed 01.04.2006*/
 Vcestimateptr tmpvc = estimates, nextvc;
 Epsilonestimateptr tmpepsilon;
 int count = 0, i;
 double sumvcdimension = 0, sumepsilon, vcdimension, difference, before, after;
 switch (experimenttype)
  {
   case UNIFORM_DESIGN  :while (tmpvc)
                          {
                           tmpepsilon = tmpvc->epsilonestimates;
                           sumepsilon = 0.0;
                           while (tmpepsilon)
                            {
                             sumepsilon += tmpepsilon->epsilon;
                             tmpepsilon = tmpepsilon->next;
                            }
                           vcdimension = tmpvc->n / solve_vc_bound_equation(sumepsilon / tmpvc->count);
                           nextvc = tmpvc->next;
                           tmpvc->next = NULL;
                           for (i = 0; i < 6; i++)
                            {
                             difference = pow(10, -i);
                             before = mse_fitting_for_vc_dimension(tmpvc, vcdimension - difference, -1);
                             after = mse_fitting_for_vc_dimension(tmpvc, vcdimension + difference, -1);
                             if (before < after)
                               while (mse_fitting_for_vc_dimension(tmpvc, vcdimension - difference, -1) < mse_fitting_for_vc_dimension(tmpvc, vcdimension, -1))
                                 vcdimension -= difference;
                             else
                               while (mse_fitting_for_vc_dimension(tmpvc, vcdimension + difference, -1) < mse_fitting_for_vc_dimension(tmpvc, vcdimension, -1))
                                 vcdimension += difference;
                            }
                           tmpvc->next = nextvc;
                           sumvcdimension += vcdimension;
                           count++;
                           tmpvc = tmpvc->next;
                          }                         
                         vcdimension = sumvcdimension / count;
                         break;
   case OPTIMIZED_DESIGN:while (tmpvc)
                          {
                           if (tmpvc->n != n)
                            {
                             tmpepsilon = tmpvc->epsilonestimates;
                             while (tmpepsilon)
                              {
                               sumvcdimension += tmpvc->n / solve_vc_bound_equation(tmpepsilon->epsilon);
                               count++;
                               tmpepsilon = tmpepsilon->next;
                              }
                            }
                           tmpvc = tmpvc->next;
                          }
                         vcdimension = sumvcdimension / count;
                         for (i = 0; i < 6; i++)
                          {
                           difference = pow(10, -i);
                           before = mse_fitting_for_vc_dimension(estimates, vcdimension - difference, n);
                           after = mse_fitting_for_vc_dimension(estimates, vcdimension + difference, n);
                           if (before < after)
                             while (mse_fitting_for_vc_dimension(estimates, vcdimension - difference, n) < mse_fitting_for_vc_dimension(tmpvc, vcdimension, n))
                               vcdimension -= difference;
                           else
                             while (mse_fitting_for_vc_dimension(estimates, vcdimension + difference, n) < mse_fitting_for_vc_dimension(tmpvc, vcdimension, n))
                               vcdimension += difference;
                          }
                         break;
  }
 return vcdimension;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movl %esi, %r14d
movq %rdi, %rbx
testl %esi, %esi
je 0x7f43b
cmpl $0x1, %r14d
jne 0x7f5d1
movl %edx, %ebp
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movq %rbx, %r15
testq %r15, %r15
je 0x7f31f
cmpl %ebp, (%r15)
je 0x7f319
movsd %xmm1, 0x10(%rsp)
leaq 0x18(%r15), %r12
movq (%r12), %r12
testq %r12, %r12
je 0x7f313
cvtsi2sdl (%r15), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%r12), %xmm0
callq 0x7f09b
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
incl %r14d
addq $0x8, %r12
jmp 0x7f2d1
movsd 0x10(%rsp), %xmm1
movq 0x20(%r15), %r15
jmp 0x7f2bd
cvtsi2sd %r14d, %xmm0
divsd %xmm0, %xmm1
xorl %r14d, %r14d
cmpl $0x6, %r14d
je 0x7f5d1
movl %r14d, %eax
negl %eax
movsd %xmm1, 0x10(%rsp)
cvtsi2sd %eax, %xmm1
movsd 0x189ec(%rip), %xmm0    # 0x97d38
callq 0x42f0
movapd %xmm0, %xmm1
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7f5e2
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7f5e2
ucomisd 0x8(%rsp), %xmm0
jbe 0x7f3e0
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
subsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movl %ebp, %esi
callq 0x7f5e2
movsd %xmm0, 0x20(%rsp)
xorl %edi, %edi
movsd 0x8(%rsp), %xmm0
movl %ebp, %esi
callq 0x7f5e2
ucomisd 0x20(%rsp), %xmm0
movsd 0x10(%rsp), %xmm0
ja 0x7f399
jmp 0x7f42d
movsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
movsd %xmm0, 0x8(%rsp)
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7f5e2
movsd %xmm0, 0x20(%rsp)
xorl %edi, %edi
movsd 0x8(%rsp), %xmm0
movl %ebp, %esi
callq 0x7f5e2
ucomisd 0x20(%rsp), %xmm0
movsd 0x10(%rsp), %xmm0
ja 0x7f3e6
incl %r14d
movsd 0x8(%rsp), %xmm1
jmp 0x7f32b
xorpd %xmm1, %xmm1
pushq $-0x1
popq %rbp
testq %rbx, %rbx
je 0x7f5c8
leaq 0x18(%rbx), %rax
xorpd %xmm0, %xmm0
movq (%rax), %rax
testq %rax, %rax
je 0x7f465
addsd (%rax), %xmm0
addq $0x8, %rax
jmp 0x7f453
movsd %xmm1, 0x10(%rsp)
cvtsi2sdl (%rbx), %xmm1
movsd %xmm1, 0x8(%rsp)
cvtsi2sdl 0x4(%rbx), %xmm1
divsd %xmm1, %xmm0
callq 0x7f09b
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movq 0x20(%rbx), %r15
andq $0x0, 0x20(%rbx)
xorl %r12d, %r12d
cmpl $0x6, %r12d
je 0x7f5af
movl %r12d, %eax
negl %eax
cvtsi2sd %eax, %xmm1
movsd %xmm0, 0x8(%rsp)
movsd 0x1887a(%rip), %xmm0    # 0x97d38
callq 0x42f0
movapd %xmm0, %xmm1
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7f5e2
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7f5e2
ucomisd 0x18(%rsp), %xmm0
jbe 0x7f553
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
subsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
movl %ebp, %esi
callq 0x7f5e2
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movsd 0x18(%rsp), %xmm0
movl %ebp, %esi
callq 0x7f5e2
ucomisd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm0
ja 0x7f50b
jmp 0x7f5a1
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
movsd %xmm0, 0x18(%rsp)
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7f5e2
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movsd 0x18(%rsp), %xmm0
movl %ebp, %esi
callq 0x7f5e2
ucomisd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm0
ja 0x7f559
incl %r12d
movsd 0x18(%rsp), %xmm0
jmp 0x7f49d
movq %r15, 0x20(%rbx)
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
incl %r14d
movq %r15, %rbx
jmp 0x7f442
cvtsi2sd %r14d, %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq