// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/srm.c
// Function: vc_dimension_of_ruleset
int vc_dimension_of_ruleset(int featurecount, char* values, int randomgenerate, int randomcount)
{
 /*Last Changed 24.02.2008*/
 int i, vcdimension = 1, bound = (int) pow(2, featurecount), conditioncount = 0, notfinished, classcounts[2];
 BOOLEAN successful, classifiedsinglecombination, classifiedallcombinations;
 int *datacombination, *classiterator, *ruleset, *indexlist, *list, *featurelist, valuecount, count = 0;
 valuecount = strlen(values);
 ruleset = safemalloc(valuecount * sizeof(int), "vc_dimension_of_ruleset", 3);
 for (i = 0; i < valuecount; i++)
  {
   ruleset[i] = values[i] - '0';
   conditioncount += ruleset[i];
  }
 list = safemalloc(2 * featurecount * sizeof(int), "vc_dimension_of_ruleset", 9);
 for (i = 0; i < featurecount; i++)
  {
   list[2 * i] = 10 * i;
   list[2 * i + 1] = 10 * i + 1;
  } 
 while (vcdimension <= bound)
  {
   datacombination = first_combination(vcdimension);
   count = 0;
   successful = BOOLEAN_FALSE;
   while (BOOLEAN_TRUE)
    {
     classifiedallcombinations = BOOLEAN_TRUE;
     classiterator = first_iterator(vcdimension);
     do{
        classcounts[0] = classcounts[1] = 0;
        for (i = 0; i < vcdimension; i++)
          classcounts[classiterator[i]]++;
        if (classcounts[0] * classcounts[1] == 0)
          continue;
        featurelist = first_iterator_from_list(conditioncount, list, &indexlist);
        classifiedsinglecombination = BOOLEAN_FALSE;
        notfinished = BOOLEAN_TRUE;
        while (!classifiedsinglecombination && notfinished)
         {
          if (can_ruleset_classify(featurelist, ruleset, valuecount, datacombination, classiterator, vcdimension, 0) ||
              can_ruleset_classify(featurelist, ruleset, valuecount, datacombination, classiterator, vcdimension, 1))
           {
            classifiedsinglecombination = BOOLEAN_TRUE;
            break;
           }
          notfinished = next_iterator_from_list(featurelist, list, indexlist, conditioncount, 2 * featurecount - 1);
         }
        safe_free(indexlist);
        safe_free(featurelist);
        if (!classifiedsinglecombination)
         {
          classifiedallcombinations = BOOLEAN_FALSE;
          break;
         }
     }while(next_iterator(classiterator, vcdimension, 1));
     safe_free(classiterator);
     if (classifiedallcombinations)
      {
       successful = BOOLEAN_TRUE;
       break;
      }
     count++;
     if (randomgenerate)
       if (count < randomcount)
         random_combination(datacombination, vcdimension, bound - 1);
       else
         break;
     else
       if (!next_combination(datacombination, vcdimension, bound - 1))
         break;
   }
   safe_free(datacombination);
   if (successful)
     vcdimension++;
   else
     break;
  }
 safe_free(list);
 safe_free(ruleset);
 return vcdimension - 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, 0x38(%rsp)
movl %edx, 0x3c(%rsp)
movq %rsi, %rbx
movl %edi, %r12d
movsd 0x155fb(%rip), %xmm0    # 0x95520
callq 0x4080
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
callq 0x4190
movq %rax, %r15
movslq %r15d, %r13
leaq (,%r13,4), %rdi
leaq 0x214d8(%rip), %rsi     # 0xa1425
pushq $0x3
popq %rdx
callq 0x34f59
movq %rax, %r14
xorl %eax, %eax
testl %r13d, %r13d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movq $0x0, 0x18(%rsp)
cmpq %rax, %rcx
je 0x7ff93
movsbl (%rbx,%rax), %edx
leal -0x30(%rdx), %esi
movl %esi, (%r14,%rax,4)
movq 0x18(%rsp), %rsi
addl %edx, %esi
addl $-0x30, %esi
movq %rsi, 0x18(%rsp)
incq %rax
jmp 0x7ff6f
leal (%r12,%r12), %eax
movl %eax, 0x14(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x2147c(%rip), %rsi     # 0xa1425
pushq $0x9
popq %rdx
callq 0x34f59
xorl %ecx, %ecx
testl %r12d, %r12d
cmovlel %ecx, %r12d
movq %rax, %rdx
imulq $0xa, %r12, %rax
movq %rdx, 0x28(%rsp)
addq $0x4, %rdx
cmpq %rcx, %rax
je 0x7ffe1
movl %ecx, -0x4(%rdx)
leal 0x1(%rcx), %esi
movl %esi, (%rdx)
addq $0xa, %rcx
addq $0x8, %rdx
jmp 0x7ffca
cvttsd2si 0x20(%rsp), %ecx
decl 0x14(%rsp)
leal -0x1(%rcx), %eax
movl %eax, 0x10(%rsp)
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, 0x48(%rsp)
leal 0x1(%rcx), %eax
movq %rax, 0x50(%rsp)
pushq $0x1
popq %rbp
cmpq 0x50(%rsp), %rbp
je 0x801a1
movl %ebp, %edi
callq 0x34598
movq %rax, %r13
xorl %ebx, %ebx
movl %ebx, 0x20(%rsp)
movl %ebp, %edi
callq 0x3463b
movq %rax, %r12
andq $0x0, 0x40(%rsp)
xorl %eax, %eax
cmpq %rax, %rbp
je 0x80048
movslq (%r12,%rax,4), %rcx
incl 0x40(%rsp,%rcx,4)
incq %rax
jmp 0x80036
movl 0x44(%rsp), %eax
imull 0x40(%rsp), %eax
testl %eax, %eax
je 0x800ec
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x3469f
movq %rax, %rbx
pushq $0x1
popq %rax
testl %eax, %eax
je 0x80103
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %r13, %rcx
movq %r12, %r8
movl %ebp, %r9d
callq 0x7fdc1
testl %eax, %eax
jne 0x800da
movl $0x1, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %r13, %rcx
movq %r12, %r8
movl %ebp, %r9d
callq 0x7fdc1
testl %eax, %eax
jne 0x800da
movq 0x30(%rsp), %rdx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl 0x14(%rsp), %r8d
callq 0x34b38
jmp 0x80073
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq %rbx, %rdi
callq 0x34ff7
movq %r12, %rdi
movl %ebp, %esi
pushq $0x1
popq %rdx
callq 0x34ae8
testl %eax, %eax
jne 0x8002e
jmp 0x8015b
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq %rbx, %rdi
callq 0x34ff7
movq %r12, %rdi
callq 0x34ff7
movl 0x20(%rsp), %ebx
incl %ebx
cmpl $0x0, 0x3c(%rsp)
je 0x80143
cmpl 0x38(%rsp), %ebx
jge 0x80173
movq %r13, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
callq 0x35dec
jmp 0x80020
movq %r13, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
callq 0x349ff
testl %eax, %eax
jne 0x80020
jmp 0x80173
movq %r12, %rdi
callq 0x34ff7
movq %r13, %rdi
callq 0x34ff7
incq %rbp
jmp 0x80009
movq %r13, %rdi
callq 0x34ff7
leal -0x1(%rbp), %ebx
movq 0x28(%rsp), %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x34ff7
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%rsp), %rbx
jmp 0x8017e