// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movl %ecx, 0x4c(%rsp)
movl %edx, 0x50(%rsp)
movq %rsi, %r12
movl %edi, %ebx
movsd 0x17ca1(%rip), %xmm0    # 0xa5520
callq 0x4080
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
callq 0x4190
movq %rax, %r15
movslq %r15d, %r14
leaq (,%r14,4), %rdi
leaq 0x23c1e(%rip), %rsi     # 0xb14c5
movl $0x3, %edx
callq 0x3a0e1
testl %r14d, %r14d
jle 0x8d8e0
movl %r15d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
xorl %r14d, %r14d
movsbl (%r12,%rcx), %edx
leal -0x30(%rdx), %esi
movl %esi, (%rax,%rcx,4)
addl %edx, %r14d
addl $-0x30, %r14d
incq %rcx
cmpq %rcx, %rdi
jne 0x8d8c4
jmp 0x8d8e3
xorl %r14d, %r14d
movq %rax, 0x60(%rsp)
cvttsd2si 0x10(%rsp), %r12d
leal (%rbx,%rbx), %eax
movl %eax, 0x1c(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x23bc1(%rip), %rsi     # 0xb14c5
movl $0x9, %edx
callq 0x3a0e1
movq %rax, 0x20(%rsp)
testl %ebx, %ebx
jle 0x8d940
movl %ebx, %ecx
movq 0x20(%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 0x8d92b
testl %r12d, %r12d
jle 0x8db43
movq %r15, 0x70(%rsp)
decl 0x1c(%rsp)
leal -0x1(%r12), %eax
movl %eax, 0x18(%rsp)
incl %r12d
movl $0x1, %r15d
movq %r12, 0x68(%rsp)
movl %r15d, %ebx
movl %r15d, %edi
callq 0x391d6
xorl %ebp, %ebp
movq %rbx, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movl %ebp, 0x54(%rsp)
movl %ebx, %edi
callq 0x3930e
movq %rax, %r13
movq $0x0, 0x58(%rsp)
xorl %eax, %eax
movslq (%r13,%rax,4), %rcx
incl 0x58(%rsp,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0x8d99e
cmpl $0x0, 0x58(%rsp)
sete %al
cmpl $0x0, 0x5c(%rsp)
sete %cl
orb %al, %cl
jne 0x8da81
movl %r14d, %edi
movq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x3939a
movq %rax, 0x10(%rsp)
movq %r14, %rbp
movl $0x0, (%rsp)
movq 0x10(%rsp), %rdi
movq 0x60(%rsp), %r15
movq %r15, %rsi
movq 0x70(%rsp), %r14
movl %r14d, %edx
movq 0x28(%rsp), %r12
movq %r12, %rcx
movq %r13, %r8
movq 0x38(%rsp), %rbx
movl %ebx, %r9d
callq 0x8d726
testl %eax, %eax
jne 0x8da65
movl $0x1, (%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r14d, %edx
movq %r12, %rcx
movq %r13, %r8
movl %ebx, %r9d
callq 0x8d726
testl %eax, %eax
jne 0x8da65
movq 0x40(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %r14
movl %ebp, %ecx
movl 0x1c(%rsp), %r8d
callq 0x39985
testl %eax, %eax
jne 0x8d9de
jmp 0x8da9a
movq 0x40(%rsp), %rdi
callq 0x3a180
movq 0x10(%rsp), %rdi
callq 0x3a180
movq %rbp, %r14
movq 0x30(%rsp), %r15
movq %r13, %rdi
movl %ebx, %esi
movl $0x1, %edx
callq 0x3991a
testl %eax, %eax
jne 0x8d993
jmp 0x8db12
movq 0x40(%rsp), %rdi
callq 0x3a180
movq 0x10(%rsp), %rdi
callq 0x3a180
movq %r13, %rdi
callq 0x3a180
movl 0x54(%rsp), %ebp
incl %ebp
cmpl $0x0, 0x50(%rsp)
je 0x8daeb
cmpl 0x4c(%rsp), %ebp
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r12
jge 0x8db37
movq %r12, %rdi
movl %ebx, %esi
movl 0x18(%rsp), %edx
callq 0x3b1fa
jmp 0x8d985
movq 0x28(%rsp), %r12
movq %r12, %rdi
movq 0x38(%rsp), %rbx
movl %ebx, %esi
movl 0x18(%rsp), %edx
callq 0x39814
testl %eax, %eax
movq 0x30(%rsp), %r15
jne 0x8d985
jmp 0x8db37
movq %r13, %rdi
callq 0x3a180
movq 0x28(%rsp), %rdi
callq 0x3a180
incq %r15
movq 0x68(%rsp), %r12
cmpq %r12, %r15
jne 0x8d969
jmp 0x8db45
movq %r12, %rdi
callq 0x3a180
decl %ebx
jmp 0x8db45
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
callq 0x3a180
movq 0x60(%rsp), %rdi
callq 0x3a180
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop