// File: /workspace/github_c_makefile_star2_O3/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, 0x34(%rsp)
movl %esi, %ecx
movq %rdi, %rbx
movb $0x0, 0xf(%rsp)
movq 0x8(%rdi), %rdx
leaq 0x95960(%rip), %rsi     # 0xaba47
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 0x155f1
movq %rax, %r15
movq 0x1407124(%rbx), %rax
movq %rax, 0x1407124(%r15)
movslq 0x1bc(%rbx), %rdi
movl %edi, 0x1bc(%r15)
shlq $0x3, %rdi
leaq 0x907d3(%rip), %rsi     # 0xa6912
movl $0xc, %edx
callq 0x3a0e1
movq %rax, 0x38(%rsp)
movl 0x1407120(%rbx), %eax
movl %eax, 0x1407120(%r15)
movl 0x10(%rbx), %eax
movl %eax, 0x10(%r15)
testl %eax, %eax
jle 0x16199
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 0x3b494
movq %rax, 0x18(%r15,%r14,8)
incq %r14
movslq 0x10(%rbx), %rax
cmpq %rax, %r14
jl 0x16169
movl 0x1b8(%rbx), %eax
movq %r15, 0x20(%rsp)
movl %eax, 0x1b8(%r15)
cmpl $0x0, 0x1bc(%rbx)
jle 0x162c6
movl $0x30f08, %eax          # imm = 0x30F08
leaq (%rbx,%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %r14
addq %r14, %rax
movq %rax, 0x40(%rsp)
movl 0x10(%rsp), %r15d
movl $0x30f28, %eax          # imm = 0x30F28
leaq (%rbx,%rax), %rbp
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 0x20(%rsp), %rdx
movl %ecx, 0x1c4(%rdx,%r12,4)
movl (%rsi,%rax), %ecx
testl %ecx, %ecx
je 0x1622f
cmpl $0x3, %ecx
je 0x1626b
cmpl $0x2, %ecx
jne 0x162a3
movq 0x10(%rsp), %rax
movl %eax, 0x18(%r13)
movl $0x1, (%r13)
testl %eax, %eax
jle 0x162a3
xorl %r13d, %r13d
leal 0x30(%r13), %eax
movb %al, 0xe(%rsp)
movq (%r14,%r13,8), %rdi
leaq 0xe(%rsp), %rsi
callq 0x3b494
movq %rax, (%r14,%r13,8)
incq %r13
cmpq %r13, %r15
jne 0x16247
jmp 0x162a3
addq 0x18(%rsp), %rax
movl $0x3, (%r13)
movl 0x18(%rax), %eax
movl %eax, 0x18(%r13)
testl %eax, %eax
jle 0x162a3
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movq (%rbp,%rbx,8), %rsi
callq 0x3b494
movq %rax, (%r14,%rbx,8)
incq %rbx
movslq 0x18(%r13), %rax
cmpq %rax, %rbx
jl 0x16285
incq %r12
movq 0x48(%rsp), %rbx
movslq 0x1bc(%rbx), %rax
movl $0x340, %ecx            # imm = 0x340
addq %rcx, %rbp
addq %rcx, %r14
cmpq %rax, %r12
jl 0x161ec
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x5dcbd
movl 0x1bc(%rbx), %eax
testl %eax, %eax
movq 0x38(%rsp), %r12
jle 0x16340
leaq 0x30f08(%rbx), %r14
xorl %r13d, %r13d
movl 0x34(%rsp), %ebp
cmpl $0x3, (%r14)
je 0x1632a
cmpl $0x1, %ebp
je 0x16311
testl %ebp, %ebp
jne 0x1632a
movq %rbx, %rdi
movl %r13d, %esi
movq 0x10(%rsp), %rdx
callq 0x159a0
jmp 0x16326
movq 0x28(%rsp), %rcx
movq %rbx, %rdi
movl %r13d, %esi
movq 0x10(%rsp), %rdx
callq 0x15d1d
movq %rax, (%r12,%r13,8)
incq %r13
movslq 0x1bc(%rbx), %rax
addq $0x340, %r14            # imm = 0x340
cmpq %rax, %r13
jl 0x162f0
movq 0x28(%rsp), %r13
testq %r13, %r13
je 0x16406
leaq 0x30f08(%rbx), %r14
movq 0x10(%rsp), %rcx
leal -0x1(%rcx), %ebp
testl %eax, %eax
jle 0x163f9
xorl %r15d, %r15d
imulq $0x340, %r15, %rax      # imm = 0x340
movl (%r14,%rax), %edi
cmpl $0x2, %edi
je 0x1638b
testl %edi, %edi
jne 0x16395
movq (%r13), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r15,8), %xmm0
jmp 0x16395
movq (%r13), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x2, %esi
xorl %edx, %edx
movl $0x2, %ecx
xorl %eax, %eax
callq 0x3aa8c
testl %eax, %eax
je 0x163e0
xorl %eax, %eax
cmpl $0x2, 0x10(%rsp)
jl 0x163d8
movq (%r12,%r15,8), %rcx
xorl %eax, %eax
movsd 0x18(%rsp), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
jbe 0x163d8
incq %rax
cmpq %rax, %rbp
jne 0x163c7
movl %ebp, %eax
movq (%r13), %rcx
movl %eax, (%rcx,%r15,8)
incq %r15
movslq 0x1bc(%rbx), %rax
cmpq %rax, %r15
movsd 0x18(%rsp), %xmm0
jl 0x16368
movq 0x10(%r13), %r13
testq %r13, %r13
jne 0x1635d
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0x164dc
movq %rax, %r12
leaq 0x90508(%rip), %rsi     # 0xa6925
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x41b0
movq %r12, %rdi
callq 0x3a180
movq %r13, %rdi
callq 0x4100
movq %rbp, %rdi
callq 0x16542
leaq 0x9551f(%rip), %rsi     # 0xab96d
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x164c5
movq %rax, %r12
movq 0x28(%rsp), %rcx
movq %rax, %rdi
movl $0x20, %esi
movq %rbp, %rdx
callq 0x304a2
movq %r12, %rdi
callq 0x42a0
movl 0x1bc(%rbx), %eax
testl %eax, %eax
movq 0x38(%rsp), %r12
jle 0x164bb
leaq 0x30f08(%rbx), %r14
xorl %r15d, %r15d
cmpl $0x3, (%r14)
je 0x164a9
movq (%r12,%r15,8), %rdi
callq 0x3a180
movl 0x1bc(%rbx), %eax
incq %r15
movslq %eax, %rcx
addq $0x340, %r14            # imm = 0x340
cmpq %rcx, %r15
jl 0x16494
movq %r12, %rdi
callq 0x3a180
jmp 0x164c7
xorl %ebp, %ebp
movq %rbp, %rax
addq $0xf4298, %rsp          # imm = 0xF4298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq