// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/dataset.c
// Function: discretize_dataset
Datasetptr discretize_dataset(Datasetptr original, int valuecount, DISCRETIZATION_TYPE discretization)
{
 Instanceptr data, inst;
 Datasetptr tmp;
 int i, j;
 char name[READLINELENGTH], tmpcommand[READLINELENGTH];
 char value[2];
 char* dname;
 char* fname;
 double **discretization_scheme, current;
 FILE* datafile;
 value[1] = '\0';
 sprintf(name, "%s%d", original->name, valuecount);
 tmp = empty_dataset(name, name, original->file, ' ');
 tmp->traincount = original->traincount;
 tmp->classdefno = original->classdefno;
 tmp->featurecount = original->featurecount;
 discretization_scheme = safemalloc(original->featurecount * sizeof(double *), "discretize_dataset", 12);
 tmp->datacount = original->datacount;
 tmp->classno = original->classno;
 for (i = 0; i < original->classno; i++)
  {
   tmp->classcounts[i] = original->classcounts[i];
   tmp->classes[i] = strcopy(tmp->classes[i], original->classes[i]);
  }
 tmp->allfeatures = original->allfeatures;
 for (i = 0; i < original->featurecount; i++)
  {
   tmp->features[i].selected = original->features[i].selected;
   tmp->availability[i] = original->availability[i];
   switch (original->features[i].type)
    {
     case  INTEGER:
     case     REAL:tmp->features[i].valuecount = valuecount;
                   tmp->features[i].type = STRING;
                   for (j = 0; j < valuecount; j++)
                    {
                     value[0] = '0' + j;
                     tmp->features[i].strings[j] = strcopy(tmp->features[i].strings[j], value);
                    }
                   break;
     case CLASSDEF:tmp->features[i].type = original->features[i].type;
                   tmp->features[i].valuecount = original->features[i].valuecount;
                   for (j = 0; j < tmp->features[i].valuecount; j++)
                     tmp->features[i].strings[j] = strcopy(tmp->features[i].strings[j], original->features[i].strings[j]);
                   break;
    }
  }
 read_from_train_file(original, &data);
 for (i = 0; i < original->featurecount; i++)
   if (original->features[i].type != CLASSDEF) 
     switch (discretization)
      {
       case EQUALWIDTH:discretization_scheme[i] = discretization_equalwidth(original, i, valuecount);
                       break;
       case    ENTROPY:discretization_scheme[i] = discretization_entropy(original, i, valuecount, data);
                       break; 
      }   
 inst = data;
 while (inst != NULL)
  {
   for (i = 0; i < original->featurecount; i++)
    {
     switch (original->features[i].type)
      {
       case INTEGER:current = inst->values[i].intvalue;
                    break;
       case    REAL:current = inst->values[i].floatvalue;
                    break;
      }
     if (in_list(original->features[i].type, 2, INTEGER, REAL))
      {
       j = 0;
       while (j < valuecount - 1 && current > discretization_scheme[i][j])
         j++;
       inst->values[i].stringindex = j;
      }
    }
   inst = inst->next;
  }
 dname = dataset_directory_name(tmp);
 sprintf(tmpcommand, "mkdir %s", dname);
 safe_free(dname);
 system(tmpcommand);
 fname = dataset_file_name(tmp);
 datafile = fopen(fname, "w");
 if (!datafile)
   return NULL;
 print_instance_list(datafile, ' ', tmp, data);
 fclose(datafile);
 for (i = 0; i < original->featurecount; i++)
   if (original->features[i].type != CLASSDEF) 
     safe_free(discretization_scheme[i]);
 safe_free(discretization_scheme);
 return tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf4298, %rsp          # imm = 0xF4298
movl %edx, 0x1c(%rsp)
movl %esi, %r12d
movq %rdi, %r15
movb $0x0, 0xf(%rsp)
movq 0x8(%rdi), %rdx
leaq 0x86e0c(%rip), %rsi     # 0x9b96b
xorl %ebx, %ebx
leaq 0x7a170(%rsp), %r14
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x41b0
movq 0x1b0(%r15), %rdx
pushq $0x20
popq %rcx
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %r14
callq 0x1434b
movq %rax, %r13
movq 0x1407124(%r15), %rax
movq %rax, 0x1407124(%r13)
movslq 0x1bc(%r15), %rdi
movl %edi, 0x1bc(%r13)
shlq $0x3, %rdi
leaq 0x81cfa(%rip), %rsi     # 0x968b2
pushq $0xc
popq %rdx
callq 0x34f59
movq %rax, %r15
movl 0x1407120(%r14), %eax
movl %eax, 0x1407120(%r13)
movl 0x10(%r14), %eax
movl %eax, 0x10(%r13)
cltq
cmpq %rax, %rbx
jge 0x14c0d
movl 0x1407140(%r14,%rbx,4), %eax
movl %eax, 0x1407140(%r13,%rbx,4)
movq 0x18(%r13,%rbx,8), %rdi
movq 0x18(%r14,%rbx,8), %rsi
callq 0x3604c
movq %rax, 0x18(%r13,%rbx,8)
incq %rbx
movl 0x10(%r14), %eax
jmp 0x14bd9
movl 0x1b8(%r14), %eax
movl %eax, 0x1b8(%r13)
movl $0x30f08, %ecx          # imm = 0x30F08
leaq (%r14,%rcx), %rax
movq %rax, 0x10(%rsp)
addq %r13, %rcx
movq %rcx, 0x38(%rsp)
xorl %ecx, %ecx
testl %r12d, %r12d
movl $0x0, %ebp
cmovgl %r12d, %ebp
movl $0x30f28, %eax          # imm = 0x30F28
leaq (%r14,%rax), %rdx
movq %rdx, 0x20(%rsp)
movq %r13, 0x28(%rsp)
addq %rax, %r13
movq %r14, 0x40(%rsp)
movslq 0x1bc(%r14), %rax
cmpq %rax, %rcx
jge 0x14d3f
imulq $0x340, %rcx, %rax      # imm = 0x340
movq 0x10(%rsp), %rsi
movq %rcx, %rdi
movl 0x1c(%rsi,%rax), %ecx
movq 0x38(%rsp), %rdx
leaq (%rdx,%rax), %rbx
movl %ecx, 0x1c(%rdx,%rax)
movl 0x1c4(%r14,%rdi,4), %ecx
movq 0x28(%rsp), %rdx
movq %rdi, 0x48(%rsp)
movl %ecx, 0x1c4(%rdx,%rdi,4)
movl (%rsi,%rax), %ecx
testl %ecx, %ecx
je 0x14cb4
cmpl $0x3, %ecx
je 0x14ce5
cmpl $0x2, %ecx
jne 0x14d20
movl %r12d, 0x18(%rbx)
movl $0x1, (%rbx)
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0x14d20
leal 0x30(%rbx), %eax
movb %al, 0xe(%rsp)
movq (%r13,%rbx,8), %rdi
leaq 0xe(%rsp), %rsi
callq 0x3604c
movq %rax, (%r13,%rbx,8)
incq %rbx
jmp 0x14cc0
addq 0x10(%rsp), %rax
movl $0x3, (%rbx)
movl 0x18(%rax), %eax
movl %eax, 0x18(%rbx)
xorl %r14d, %r14d
cltq
cmpq %rax, %r14
jge 0x14d20
movq (%r13,%r14,8), %rdi
movq 0x20(%rsp), %rax
movq (%rax,%r14,8), %rsi
callq 0x3604c
movq %rax, (%r13,%r14,8)
incq %r14
movl 0x18(%rbx), %eax
jmp 0x14cf9
movq 0x48(%rsp), %rcx
incq %rcx
movl $0x340, %eax            # imm = 0x340
addq %rax, 0x20(%rsp)
addq %rax, %r13
movq 0x40(%rsp), %r14
jmp 0x14c5a
leaq 0x30(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x5577a
xorl %ebp, %ebp
movq 0x10(%rsp), %rbx
movl 0x1c(%rsp), %ecx
movslq 0x1bc(%r14), %rax
cmpq %rax, %rbp
jge 0x14da9
cmpl $0x3, (%rbx)
je 0x14d9d
cmpl $0x1, %ecx
je 0x14d83
testl %ecx, %ecx
jne 0x14d9d
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x145f7
jmp 0x14d95
movq 0x30(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x14874
movq %rax, (%r15,%rbp,8)
movl 0x1c(%rsp), %ecx
incq %rbp
addq $0x340, %rbx            # imm = 0x340
jmp 0x14d5a
decl %r12d
xorl %ecx, %ecx
testl %r12d, %r12d
cmovlel %ecx, %r12d
pushq $0x2
popq %rbp
movq (%r13), %r13
testq %r13, %r13
je 0x14e4e
xorl %ebx, %ebx
movslq %eax, %rcx
cmpq %rcx, %rbx
jge 0x14e45
imulq $0x340, %rbx, %rax      # imm = 0x340
movq 0x10(%rsp), %rcx
movl (%rcx,%rax), %edi
cmpl $0x2, %edi
je 0x14df2
testl %edi, %edi
jne 0x14dfb
movq (%r13), %rax
cvtsi2sdl (%rax,%rbx,8), %xmm0
jmp 0x14dfb
movq (%r13), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movl %ebp, %esi
xorl %edx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x35812
movsd 0x20(%rsp), %xmm0
testl %eax, %eax
je 0x14e39
xorl %eax, %eax
cmpq %rax, %r12
je 0x14e2f
movq (%r15,%rbx,8), %rcx
ucomisd (%rcx,%rax,8), %xmm0
jbe 0x14e32
incq %rax
jmp 0x14e1a
movl %r12d, %eax
movq (%r13), %rcx
movl %eax, (%rcx,%rbx,8)
incq %rbx
movl 0x1bc(%r14), %eax
jmp 0x14dc7
addq $0x10, %r13
jmp 0x14db8
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0x14f11
movq %rax, %r12
leaq 0x81a60(%rip), %rsi     # 0x968c5
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x41b0
movq %r12, %rdi
callq 0x34ff7
movq %r13, %rdi
callq 0x4100
movq %rbp, %rdi
callq 0x14f75
leaq 0x869fb(%rip), %rsi     # 0x9b891
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x14efa
movq %rax, %r12
movq 0x30(%rsp), %rcx
pushq $0x20
popq %rsi
movq %rax, %rdi
movq %rbp, %rdx
callq 0x2c563
movq %r12, %rdi
callq 0x42a0
xorl %ebx, %ebx
movslq 0x1bc(%r14), %rax
cmpq %rax, %rbx
jge 0x14ef0
movq 0x10(%rsp), %rax
cmpl $0x3, (%rax)
je 0x14ee2
movq (%r15,%rbx,8), %rdi
callq 0x34ff7
incq %rbx
addq $0x340, 0x10(%rsp)      # imm = 0x340
jmp 0x14ec3
movq %r15, %rdi
callq 0x34ff7
jmp 0x14efc
xorl %ebp, %ebp
movq %rbp, %rax
addq $0xf4298, %rsp          # imm = 0xF4298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq