// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/dataset.c
// Function: subsample
void subsample(Datasetptr d, char* outputfile, Instanceptr list, int datacount, double* weights)
{
 /*!Last Changed 21.05.2005*/
 FILE* outfile;
 int i, j, classno, count, **indexes, *currentindex, *listindex;
 double sum = 0;
 Instanceptr tmp;
 outfile = fopen(outputfile, "w");
 if (!outfile)
   return;
 indexes = safemalloc(d->classno * sizeof(int *), "subsample", 6);
 currentindex = safecalloc(d->classno, sizeof(int), "subsample", 7);
 listindex = safecalloc(d->classno, sizeof(int), "subsample", 8);
 for (i = 0; i < d->classno; i++)
  {
   weights[i] *= d->classcounts[i];
   sum += weights[i];
  }
 for (i = 0; i < d->classno; i++)
  {
   count = (int) ((weights[i] * datacount) / sum);
   indexes[i] = safemalloc(count * sizeof(int), "subsample", 19);
   for (j = 0; j < count; j++)
     indexes[i][j] = myrand() % d->classcounts[i];
   qsort(indexes[i], count, sizeof(int), sort_function_int_ascending);
  }
 tmp = list;
 while (tmp)
  {
   classno = give_classno(tmp);
   while (indexes[classno][currentindex[classno]] == listindex[classno])
    {
     print_instance(outfile, d->separator, d, tmp);
     (currentindex[classno])++;
    }
   listindex[classno]++;
   tmp = tmp->next;
  }
 fclose(outfile);
 safe_free(currentindex);
 safe_free(listindex);
 free_2d((void**)indexes, d->classno);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xcd2a0(%rip), %rsi     # 0xe81be
callq 0x40c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1af33
jmp 0x1b189
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0xc8250(%rip), %rsi     # 0xe3196
movl $0x6, %edx
callq 0x52d70
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rdi
movl $0x4, %esi
leaq 0xc822e(%rip), %rdx     # 0xe3196
movl $0x7, %ecx
callq 0x52f40
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rdi
movl $0x4, %esi
leaq 0xc820c(%rip), %rdx     # 0xe3196
movl $0x8, %ecx
callq 0x52f40
movq %rax, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x1aff0
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
cvtsi2sdl 0x1407140(%rax,%rcx,4), %xmm0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1af9f
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x1b0c4
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdl -0x1c(%rbp), %xmm1
mulsd %xmm1, %xmm0
divsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x40(%rbp)
movslq -0x40(%rbp), %rdi
shlq $0x2, %rdi
leaq 0xc815e(%rip), %rsi     # 0xe3196
movl $0x13, %edx
callq 0x52d70
movq %rax, %rdx
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1b095
movb $0x0, %al
callq 0x54550
movq -0x8(%rbp), %rcx
movslq -0x34(%rbp), %rsi
cltd
idivl 0x1407140(%rcx,%rsi,4)
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1b058
movq -0x48(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x40(%rbp), %rsi
movl $0x4, %edx
leaq 0x3838f(%rip), %rcx     # 0x53440
callq 0x41f0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1aff7
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x1b15e
movq -0x68(%rbp), %rdi
callq 0x43530
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %eax
movq -0x58(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x1b13c
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movb 0x1a8(%rax), %al
movq -0x8(%rbp), %rdx
movq -0x68(%rbp), %rcx
movsbl %al, %esi
callq 0x435b0
movq -0x50(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x1b0e3
movq -0x58(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x1b0cc
movq -0x30(%rbp), %rdi
callq 0x4250
movq -0x50(%rbp), %rdi
callq 0x52e80
movq -0x58(%rbp), %rdi
callq 0x52e80
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x52e20
addq $0x70, %rsp
popq %rbp
retq
nop