// File: /workspace/github_c_makefile_star2_O1/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 $0x40, %rsp
movq %rdi, %rbx
testl %esi, %esi
je 0x8a464
cmpl $0x1, %esi
jne 0x8a6d9
movl %edx, %ebp
testq %rbx, %rbx
je 0x8a61f
xorl %r14d, %r14d
xorpd %xmm1, %xmm1
movq %rbx, %r15
cmpl %ebp, (%r15)
jne 0x8a41e
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x8a40b
jmp 0x8a611
movq 0x18(%r15), %r12
testq %r12, %r12
je 0x8a410
movsd %xmm1, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd (%r12), %xmm0
callq 0x8a157
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
divsd %xmm0, %xmm2
addsd %xmm2, %xmm1
incl %r14d
movq 0x8(%r12), %r12
jmp 0x8a422
testq %rbx, %rbx
je 0x8a6d1
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rbx), %rax
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x8a490
addsd (%rax), %xmm0
movq 0x8(%rax), %rax
jmp 0x8a481
xorps %xmm1, %xmm1
cvtsi2sdl (%rbx), %xmm1
movsd %xmm1, 0x10(%rsp)
xorps %xmm1, %xmm1
cvtsi2sdl 0x4(%rbx), %xmm1
divsd %xmm1, %xmm0
callq 0x8a157
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq 0x20(%rbx), %r14
movq $0x0, 0x20(%rbx)
xorl %r15d, %r15d
movl %r15d, %eax
negl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x1a84f(%rip), %xmm0    # 0xa4d30
callq 0x42f0
movapd %xmm0, %xmm1
movsd %xmm0, 0x38(%rsp)
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8a6e6
movsd %xmm0, 0x20(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8a6e6
ucomisd 0x20(%rsp), %xmm0
jbe 0x8a582
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
subsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movsd 0x20(%rsp), %xmm0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8a6e6
movsd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8a6e6
ucomisd 0x30(%rsp), %xmm0
movsd 0x20(%rsp), %xmm0
ja 0x8a534
jmp 0x8a5d6
movsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
movsd %xmm0, 0x10(%rsp)
movsd 0x38(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8a6e6
movsd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8a6e6
ucomisd 0x30(%rsp), %xmm0
movsd 0x20(%rsp), %xmm0
ja 0x8a588
incl %r15d
cmpl $0x6, %r15d
jne 0x8a4cd
movq %r14, 0x20(%rbx)
movsd 0x8(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
incl %ebp
movq %r14, %rbx
testq %r14, %r14
jne 0x8a473
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
jmp 0x8a6d9
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm0, %xmm1
jmp 0x8a627
movsd 0x186e9(%rip), %xmm1    # 0xa2d10
movsd %xmm1, 0x8(%rsp)
xorl %r14d, %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x1a6f0(%rip), %xmm0    # 0xa4d30
callq 0x42f0
movapd %xmm0, %xmm1
movapd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8a6e6
movapd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8a6e6
movapd 0x10(%rsp), %xmm3
movapd %xmm3, %xmm1
xorpd 0x18b3f(%rip), %xmm1    # 0xa31d0
movapd 0x20(%rsp), %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
addsd 0x8(%rsp), %xmm2
movapd %xmm2, %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8a6e6
decl %r14d
cmpl $-0x6, %r14d
jne 0x8a630
movsd 0x8(%rsp), %xmm0
jmp 0x8a6d9
movsd 0x18637(%rip), %xmm0    # 0xa2d10
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq