// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %ecx, 0x24(%rsp)
movl %edx, 0x28(%rsp)
movq %rsi, %r12
movl %edi, %ebx
movsd 0x173e8(%rip), %xmm0    # 0xa2520
callq 0x4080
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
callq 0x4190
movq %rax, %r15
movslq %r15d, %r13
leaq (,%r13,4), %rdi
leaq 0x232cd(%rip), %rsi     # 0xae42d
movl $0x3, %edx
callq 0x390f5
movq %rax, %r14
testl %r13d, %r13d
jle 0x8b19c
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
xorl %r13d, %r13d
movsbl (%r12,%rcx), %edx
leal -0x30(%rdx), %esi
movl %esi, (%r14,%rcx,4)
addl %edx, %r13d
addl $-0x30, %r13d
incq %rcx
cmpq %rcx, %rax
jne 0x8b17f
jmp 0x8b19f
xorl %r13d, %r13d
cvttsd2si 0x8(%rsp), %r12d
leal (%rbx,%rbx), %eax
movl %eax, 0x14(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x23272(%rip), %rsi     # 0xae42d
movl $0x9, %edx
callq 0x390f5
movq %rax, 0x8(%rsp)
testl %ebx, %ebx
jle 0x8b1f7
movl %ebx, %ecx
movq 0x8(%rsp), %rax
addq $0x4, %rax
addq %rcx, %rcx
leaq (%rcx,%rcx,4), %rcx
xorl %edx, %edx
movl %edx, -0x4(%rax)
leal 0x1(%rdx), %esi
movl %esi, (%rax)
addq $0xa, %rdx
addq $0x8, %rax
cmpq %rdx, %rcx
jne 0x8b1e2
testl %r12d, %r12d
jle 0x8b3a6
movq %r13, 0x40(%rsp)
decl 0x14(%rsp)
leal -0x1(%r12), %eax
movl %eax, 0x10(%rsp)
incl %r12d
movq %r12, 0x38(%rsp)
movl $0x1, %ebp
movl %ebp, %edi
callq 0x3857b
movq %rax, %rbx
xorl %r12d, %r12d
movl %r12d, 0x2c(%rsp)
movl %ebp, %edi
callq 0x38632
movq %rax, %r12
movq $0x0, 0x30(%rsp)
xorl %eax, %eax
movslq (%r12,%rax,4), %rcx
incl 0x30(%rsp,%rcx,4)
incq %rax
cmpq %rax, %rbp
jne 0x8b246
cmpl $0x0, 0x30(%rsp)
sete %al
cmpl $0x0, 0x34(%rsp)
sete %cl
orb %al, %cl
jne 0x8b2fd
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x386be
movq %rax, %r13
movl $0x0, (%rsp)
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %rbx, %rcx
movq %r12, %r8
movl %ebp, %r9d
callq 0x8afce
testl %eax, %eax
jne 0x8b2eb
movl $0x1, (%rsp)
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %rbx, %rcx
movq %r12, %r8
movl %ebp, %r9d
callq 0x8afce
testl %eax, %eax
jne 0x8b2eb
movq 0x18(%rsp), %rdx
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq 0x40(%rsp), %rcx
movl 0x14(%rsp), %r8d
callq 0x38c21
testl %eax, %eax
jne 0x8b285
jmp 0x8b319
movq 0x18(%rsp), %rdi
callq 0x39194
movq %r13, %rdi
callq 0x39194
movq %r12, %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x38bb6
testl %eax, %eax
jne 0x8b23b
xorl %r13d, %r13d
jmp 0x8b32e
movq 0x18(%rsp), %rdi
callq 0x39194
movq %r13, %rdi
callq 0x39194
movb $0x1, %r13b
movq %r12, %rdi
callq 0x39194
testb %r13b, %r13b
je 0x8b389
movl 0x2c(%rsp), %r12d
incl %r12d
cmpl $0x0, 0x28(%rsp)
je 0x8b364
cmpl 0x24(%rsp), %r12d
jge 0x8b37a
movq %rbx, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
callq 0x3a16d
jmp 0x8b22c
movq %rbx, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
callq 0x38aaf
testl %eax, %eax
jne 0x8b22c
movq %rbx, %rdi
callq 0x39194
testb %r13b, %r13b
je 0x8b391
jmp 0x8b3aa
movq %rbx, %rdi
callq 0x39194
incq %rbp
cmpq 0x38(%rsp), %rbp
jne 0x8b21f
movq 0x38(%rsp), %rbp
jmp 0x8b3aa
xorl %ebp, %ebp
jmp 0x8b3ac
decl %ebp
movq 0x8(%rsp), %rdi
callq 0x39194
movq %r14, %rdi
callq 0x39194
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop