// File: /workspace/github_c_makefile_star2_O3/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 $0x50, %rsp
movq %rdi, %rbx
testl %esi, %esi
je 0x8cbda
cmpl $0x1, %esi
jne 0x8ce3b
movl %edx, %ebp
testq %rbx, %rbx
je 0x8cd89
xorl %r14d, %r14d
xorpd %xmm1, %xmm1
movq %rbx, %r15
cmpl %ebp, (%r15)
jne 0x8cb96
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x8cb83
jmp 0x8cd7b
movq 0x18(%r15), %r12
testq %r12, %r12
je 0x8cb88
movsd %xmm1, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
movsd %xmm0, (%rsp)
movsd (%r12), %xmm0
callq 0x8c8cf
movsd 0x18(%rsp), %xmm1
movsd (%rsp), %xmm2
divsd %xmm0, %xmm2
addsd %xmm2, %xmm1
incl %r14d
movq 0x8(%r12), %r12
jmp 0x8cb9a
testq %rbx, %rbx
je 0x8ce33
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x18(%rbx), %rax
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x8cc06
addsd (%rax), %xmm0
movq 0x8(%rax), %rax
jmp 0x8cbf7
xorps %xmm1, %xmm1
cvtsi2sdl (%rbx), %xmm1
movsd %xmm1, (%rsp)
xorps %xmm1, %xmm1
cvtsi2sdl 0x4(%rbx), %xmm1
divsd %xmm1, %xmm0
callq 0x8c8cf
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x20(%rbx), %r14
movq $0x0, 0x20(%rbx)
xorl %r15d, %r15d
movl %r15d, %eax
negl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x1b164(%rip), %xmm0    # 0xa7db8
callq 0x42f0
movapd %xmm0, %xmm1
movsd %xmm0, 0x40(%rsp)
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8ce48
movsd %xmm0, 0x20(%rsp)
movsd (%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8ce48
ucomisd 0x20(%rsp), %xmm0
jbe 0x8ccf0
movsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
subsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movsd 0x20(%rsp), %xmm0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8ce48
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movsd (%rsp), %xmm0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8ce48
ucomisd 0x38(%rsp), %xmm0
movsd 0x20(%rsp), %xmm0
ja 0x8cca4
jmp 0x8cd41
movsd (%rsp), %xmm0
movapd %xmm0, %xmm1
movsd %xmm0, (%rsp)
movsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8ce48
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movsd (%rsp), %xmm0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x8ce48
ucomisd 0x38(%rsp), %xmm0
movsd 0x20(%rsp), %xmm0
ja 0x8ccf5
incl %r15d
cmpl $0x6, %r15d
jne 0x8cc40
movq %r14, 0x20(%rbx)
movsd 0x18(%rsp), %xmm0
addsd (%rsp), %xmm0
incl %ebp
movq %r14, %rbx
testq %r14, %r14
jne 0x8cbe9
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
jmp 0x8ce3b
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm0, %xmm1
jmp 0x8cd91
movsd 0x18f7f(%rip), %xmm1    # 0xa5d10
movsd %xmm1, 0x18(%rsp)
xorl %r14d, %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x1b00e(%rip), %xmm0    # 0xa7db8
callq 0x42f0
movapd %xmm0, %xmm1
movapd %xmm0, (%rsp)
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8ce48
movapd %xmm0, 0x40(%rsp)
movapd (%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movapd %xmm0, (%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8ce48
movapd 0x40(%rsp), %xmm1
cmpltsd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm0
andpd %xmm1, %xmm0
andnpd (%rsp), %xmm1
orpd %xmm0, %xmm1
movapd %xmm1, %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8ce48
decl %r14d
cmpl $-0x6, %r14d
jne 0x8cd9a
movsd 0x18(%rsp), %xmm0
jmp 0x8ce3b
movsd 0x18ed5(%rip), %xmm0    # 0xa5d10
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq