// File: /workspace/github_c_makefile_star2_O1/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, 0x3c(%rsp)
movl %esi, %ecx
movq %rdi, %rbx
movb $0x0, 0xf(%rsp)
movq 0x8(%rdi), %rdx
leaq 0x92b6d(%rip), %rsi     # 0xa897b
leaq 0x7a170(%rsp), %r14
movq %r14, %rdi
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
callq 0x41b0
movq 0x1b0(%rbx), %rdx
movq %r14, %rdi
movq %r14, %rsi
movl $0x20, %ecx
callq 0x15559
movq %rax, %r15
movl 0x1407124(%rbx), %eax
movl %eax, 0x1407124(%r15)
movl 0x1407128(%rbx), %eax
movl %eax, 0x1407128(%r15)
movl 0x1bc(%rbx), %eax
movl %eax, 0x1bc(%r15)
movslq 0x1bc(%rbx), %rdi
shlq $0x3, %rdi
leaq 0x8da56(%rip), %rsi     # 0xa38ce
movl $0xc, %edx
callq 0x390f5
movq %rax, 0x20(%rsp)
movl 0x1407120(%rbx), %eax
movl %eax, 0x1407120(%r15)
movl 0x10(%rbx), %eax
movl %eax, 0x10(%r15)
cmpl $0x0, 0x10(%rbx)
jle 0x15ed4
xorl %r14d, %r14d
movl 0x1407140(%rbx,%r14,4), %eax
movl %eax, 0x1407140(%r15,%r14,4)
movq 0x18(%r15,%r14,8), %rdi
movq 0x18(%rbx,%r14,8), %rsi
callq 0x3a404
movq %rax, 0x18(%r15,%r14,8)
incq %r14
movslq 0x10(%rbx), %rax
cmpq %rax, %r14
jl 0x15ea4
movl 0x1b8(%rbx), %eax
movq %r15, 0x28(%rsp)
movl %eax, 0x1b8(%r15)
cmpl $0x0, 0x1bc(%rbx)
jle 0x15fff
movl $0x30f08, %eax          # imm = 0x30F08
leaq (%rbx,%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x28(%rsp), %r14
addq %r14, %rax
movq %rax, 0x40(%rsp)
movl 0x10(%rsp), %ebp
movl $0x30f28, %eax          # imm = 0x30F28
leaq (%rbx,%rax), %r15
addq %rax, %r14
xorl %r12d, %r12d
movq %rbx, 0x48(%rsp)
imulq $0x340, %r12, %rax      # imm = 0x340
movq 0x18(%rsp), %rsi
movl 0x1c(%rsi,%rax), %ecx
movq 0x40(%rsp), %rdx
leaq (%rdx,%rax), %r13
movl %ecx, 0x1c(%rdx,%rax)
movl 0x1c4(%rbx,%r12,4), %ecx
movq 0x28(%rsp), %rdx
movl %ecx, 0x1c4(%rdx,%r12,4)
movl (%rsi,%rax), %ecx
testl %ecx, %ecx
je 0x15f69
cmpl $0x3, %ecx
je 0x15fa5
cmpl $0x2, %ecx
jne 0x15fdc
movq 0x10(%rsp), %rax
movl %eax, 0x18(%r13)
movl $0x1, (%r13)
testl %eax, %eax
jle 0x15fdc
xorl %r13d, %r13d
leal 0x30(%r13), %eax
movb %al, 0xe(%rsp)
movq (%r14,%r13,8), %rdi
leaq 0xe(%rsp), %rsi
callq 0x3a404
movq %rax, (%r14,%r13,8)
incq %r13
cmpq %r13, %rbp
jne 0x15f81
jmp 0x15fdc
addq 0x18(%rsp), %rax
movl $0x3, (%r13)
movl 0x18(%rax), %eax
movl %eax, 0x18(%r13)
testl %eax, %eax
jle 0x15fdc
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movq (%r15,%rbx,8), %rsi
callq 0x3a404
movq %rax, (%r14,%rbx,8)
incq %rbx
movslq 0x18(%r13), %rax
cmpq %rax, %rbx
jl 0x15fbf
incq %r12
movq 0x48(%rsp), %rbx
movslq 0x1bc(%rbx), %rax
movl $0x340, %ecx            # imm = 0x340
addq %rcx, %r15
addq %rcx, %r14
cmpq %rax, %r12
jl 0x15f26
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x5c7af
cmpl $0x0, 0x1bc(%rbx)
movq 0x28(%rsp), %rbp
movl 0x3c(%rsp), %r15d
jle 0x16080
leaq 0x30f08(%rbx), %r14
xorl %r13d, %r13d
cmpl $0x3, (%r14)
je 0x1606a
cmpl $0x1, %r15d
je 0x1604c
testl %r15d, %r15d
jne 0x1606a
movq %rbx, %rdi
movl %r13d, %esi
movq 0x10(%rsp), %rdx
callq 0x1581e
jmp 0x16061
movq 0x30(%rsp), %rcx
movq %rbx, %rdi
movl %r13d, %esi
movq 0x10(%rsp), %rdx
callq 0x15ad7
movq 0x20(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
movslq 0x1bc(%rbx), %rax
addq $0x340, %r14            # imm = 0x340
cmpq %rax, %r13
jl 0x16029
movq 0x30(%rsp), %r14
testq %r14, %r14
je 0x1614f
leaq 0x30f08(%rbx), %r15
movq 0x10(%rsp), %rax
leal -0x1(%rax), %r13d
cmpl $0x0, 0x1bc(%rbx)
jle 0x16142
xorl %r12d, %r12d
imulq $0x340, %r12, %rax      # imm = 0x340
movl (%r15,%rax), %edi
cmpl $0x2, %edi
je 0x160d0
testl %edi, %edi
jne 0x160d9
movq (%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r12,8), %xmm0
jmp 0x160d9
movq (%r14), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x2, %esi
xorl %edx, %edx
movl $0x2, %ecx
xorl %eax, %eax
callq 0x39a80
testl %eax, %eax
je 0x16129
xorl %eax, %eax
cmpl $0x2, 0x10(%rsp)
jl 0x16122
movq 0x20(%rsp), %rax
movq (%rax,%r12,8), %rcx
xorl %eax, %eax
movsd 0x18(%rsp), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
jbe 0x16122
incq %rax
cmpq %rax, %r13
jne 0x16110
movl %r13d, %eax
movq (%r14), %rcx
movl %eax, (%rcx,%r12,8)
incq %r12
movslq 0x1bc(%rbx), %rax
cmpq %rax, %r12
movsd 0x18(%rsp), %xmm0
jl 0x160ae
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x1609e
movq %rbp, %rdi
callq 0x1621f
movq %rax, %r12
leaq 0x8d780(%rip), %rsi     # 0xa38e1
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x41b0
movq %r12, %rdi
callq 0x39194
movq %r13, %rdi
callq 0x4100
movq %rbp, %rdi
callq 0x16285
leaq 0x9270f(%rip), %rsi     # 0xa88a1
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x16208
movq %rax, %r12
movq 0x30(%rsp), %rcx
movq %rax, %rdi
movl $0x20, %esi
movq %rbp, %rdx
callq 0x2fbad
movq %r12, %rdi
callq 0x42a0
cmpl $0x0, 0x1bc(%rbx)
jle 0x161fc
leaq 0x30f08(%rbx), %r14
xorl %r15d, %r15d
cmpl $0x3, (%r14)
je 0x161e6
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rdi
callq 0x39194
incq %r15
movslq 0x1bc(%rbx), %rax
addq $0x340, %r14            # imm = 0x340
cmpq %rax, %r15
jl 0x161d2
movq 0x20(%rsp), %rdi
callq 0x39194
jmp 0x1620a
xorl %ebp, %ebp
movq %rbp, %rax
addq $0xf4298, %rsp          # imm = 0xF4298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq