// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/dataset.c
// Function: convert_byte_format_to_dataset_format
void convert_byte_format_to_dataset_format(char* inputfile, char separator, char* featuretypes, char* lengths, char* useful, char* outputfile)
{
 /*!Last Changed 20.05.2005*/
 FILE *infile1, *infile2, *outfile;
 char myline[READLINELENGTH], feature[READLINELENGTH], pst[READLINELENGTH];
 int *ftypes, fcount, i, *fsizes, *available, *fstart, tmp;
 double tmpr;
 infile1 = fopen(featuretypes, "r");
 if (!infile1)
   return;
 infile2 = fopen(lengths, "r");
 if (!infile2)
   return;
 fcount = file_length(featuretypes);
 ftypes = safemalloc(fcount * sizeof(int), "convert_byte_format_to_dataset_format", 6);
 fsizes = safemalloc(fcount * sizeof(int), "convert_byte_format_to_dataset_format", 7);
 fstart = safemalloc(fcount * sizeof(int), "convert_byte_format_to_dataset_format", 8);
 available = safecalloc(fcount, sizeof(int), "convert_byte_format_to_dataset_format", 9);
 i = 0;
 fstart[0] = 0;
 while (fgets(myline, READLINELENGTH, infile1))
  {
   tmp = strlen(myline);
   myline[tmp - 1] = '\0';
   ftypes[i] = listindex(myline, ftype, 3);
   fgets(myline, READLINELENGTH, infile2);
   fsizes[i] = atoi(myline);
   if (i > 0)
     fstart[i] = fstart[i - 1] + fsizes[i - 1];
   i++;
  }
 fclose(infile1);
 fclose(infile2);
 infile1 = fopen(useful, "r");
 if (!infile1)
   return;
 while (fgets(myline, READLINELENGTH, infile1))
  {
   i = atoi(myline);
   available[i] = 1;
  }
 fclose(infile1);
 infile1 = fopen(inputfile, "r");
 if (!infile1)
   return;
 outfile = fopen(outputfile, "w");
 if (!outfile)
  {
   printf(m1248, outputfile);
   return;
  }
 while (fgets(myline, READLINELENGTH, infile1))
  {
   for (i = 0; i < fcount; i++)
     if (available[i])
      {
       memcpy(feature, &(myline[fstart[i]]), fsizes[i]);
       feature[fsizes[i]] = '\0';
       switch (ftypes[i])
        {
         case 0 :tmp = atoi(feature);
                 fprintf(outfile, "%d%c", tmp, separator);
                 break;
         case 1 :fprintf(outfile, "%s%c", feature, separator);
                 break;
         case 2 :tmpr = atof(feature);
                 set_precision(pst, NULL, "%c");
                 fprintf(outfile, pst, tmpr, separator);
                 break;
         default:printf(m1236, ftypes[i]);
                 break;
        }
      }
   fprintf(outfile, "\n");
  }
 fclose(infile1);
 fclose(outfile);
 safe_free(ftypes);
 safe_free(fsizes);
 safe_free(available);
 safe_free(fstart);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x16e3a8, %rsp         # imm = 0x16E3A8
movq %r9, 0x18(%rsp)
movq %r8, %r12
movq %rcx, %r15
movq %rdx, %rbx
movl %esi, 0x3c(%rsp)
movq %rdi, 0x8(%rsp)
leaq 0x894fa(%rip), %rsi     # 0x9b87f
movq %rdx, %rdi
callq 0x40f0
testq %rax, %rax
je 0x126d8
movq %rax, %r14
leaq 0x894df(%rip), %rsi     # 0x9b87f
movq %r15, %rdi
callq 0x40f0
testq %rax, %rax
je 0x126d8
movq %rax, %rbp
movq %r12, 0x10(%rsp)
movq %rbx, %rdi
callq 0x33f62
movl %eax, %ebx
movslq %eax, %r12
leaq (,%r12,4), %r13
leaq 0x8418b(%rip), %r15     # 0x96560
pushq $0x6
popq %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x30(%rsp)
pushq $0x7
popq %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x28(%rsp)
pushq $0x8
popq %rdx
movq %r13, %rdi
movq %r15, %rsi
movq %r15, %r13
callq 0x34f59
movq %rax, %r15
pushq $0x4
popq %rsi
pushq $0x9
popq %rcx
movq %r12, %rdi
movq %r13, %rdx
callq 0x35067
movq %rax, %r13
movq %r15, 0x20(%rsp)
andl $0x0, (%r15)
xorl %r15d, %r15d
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x7a120, %esi          # imm = 0x7A120
movq %r14, %rdx
callq 0x4120
testq %rax, %rax
je 0x124b3
movq %r12, %rdi
callq 0x4190
decl %eax
cltq
movb $0x0, 0x40(%rsp,%rax)
movq %r12, %rdi
leaq 0xba67c(%rip), %rsi     # 0xccae0
pushq $0x3
popq %rdx
callq 0x35f17
movq 0x30(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
movq %r12, %rdi
movl $0x7a120, %esi          # imm = 0x7A120
movq %rbp, %rdx
callq 0x4120
movq %r12, %rdi
callq 0x4200
movq 0x28(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
testq %r15, %r15
je 0x124ae
movl -0x4(%rcx,%r15,4), %eax
movq 0x20(%rsp), %rcx
addl -0x4(%rcx,%r15,4), %eax
movl %eax, (%rcx,%r15,4)
incq %r15
jmp 0x12434
movq %r14, %rdi
callq 0x42a0
movq %rbp, %rdi
callq 0x42a0
leaq 0x893b5(%rip), %rsi     # 0x9b87f
movq 0x10(%rsp), %rdi
callq 0x40f0
testq %rax, %rax
je 0x126d8
movq %rax, %r14
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movl $0x7a120, %esi          # imm = 0x7A120
movq %r14, %rdx
callq 0x4120
testq %rax, %rax
je 0x1250f
movq %r12, %rdi
callq 0x4200
cltq
movl $0x1, (%r13,%rax,4)
jmp 0x124e5
movq %r14, %rdi
callq 0x42a0
leaq 0x89361(%rip), %rsi     # 0x9b87f
movq 0x8(%rsp), %rdi
callq 0x40f0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x126d8
leaq 0x89354(%rip), %rsi     # 0x9b891
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x40f0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x126c7
movsbl 0x3c(%rsp), %r14d
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
leaq 0x7a160(%rsp), %r12
leaq 0x40(%rsp), %rdi
movl $0x7a120, %esi          # imm = 0x7A120
movq 0x10(%rsp), %rdx
callq 0x4120
testq %rax, %rax
je 0x1268b
xorl %ebp, %ebp
cmpq %rbp, %rbx
je 0x12679
cmpl $0x0, (%r13,%rbp,4)
je 0x12671
movq 0x20(%rsp), %rax
movslq (%rax,%rbp,4), %rax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movq 0x28(%rsp), %rax
movslq (%rax,%rbp,4), %r15
movq %r12, %rdi
movq %r15, %rdx
callq 0x4310
movb $0x0, 0x7a160(%rsp,%r15)
movq 0x30(%rsp), %rax
movl (%rax,%rbp,4), %esi
cmpl $0x2, %esi
je 0x12622
cmpl $0x1, %esi
je 0x12607
testl %esi, %esi
jne 0x12663
movq %r12, %rdi
callq 0x4200
movq 0x8(%rsp), %rdi
leaq 0x83fb2(%rip), %rsi     # 0x965ab
movl %eax, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x42e0
jmp 0x12671
movq 0x8(%rsp), %rdi
leaq 0x83f9d(%rip), %rsi     # 0x965b0
movq %r12, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x42e0
jmp 0x12671
movq %r12, %rdi
callq 0x4130
movsd %xmm0, 0x18(%rsp)
leaq 0xf4280(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
leaq 0x876b4(%rip), %rdx     # 0x99cf8
callq 0x35305
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movsd 0x18(%rsp), %xmm0
movl %r14d, %edx
movb $0x1, %al
callq 0x42e0
jmp 0x12671
leaq 0x83f4b(%rip), %rdi     # 0x965b5
xorl %eax, %eax
callq 0x4030
incq %rbp
jmp 0x1258c
pushq $0xa
popq %rdi
movq 0x8(%rsp), %rsi
callq 0x4150
jmp 0x1256d
movq 0x10(%rsp), %rdi
callq 0x42a0
movq 0x8(%rsp), %rdi
callq 0x42a0
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq 0x28(%rsp), %rdi
callq 0x34ff7
movq %r13, %rdi
callq 0x34ff7
movq 0x20(%rsp), %rdi
callq 0x34ff7
jmp 0x126d8
leaq 0x83eb8(%rip), %rdi     # 0x96586
movq %r14, %rsi
xorl %eax, %eax
callq 0x4030
addq $0x16e3a8, %rsp         # imm = 0x16E3A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq