// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r15
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x98847(%rip), %rsi     # 0xab96d
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x1332c
movq %rax, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movslq 0x10(%rbx), %rdi
shlq $0x3, %rdi
movq %r15, 0x8(%rsp)
leaq 0x93461(%rip), %r15     # 0xa65b6
movq %r15, %rsi
movl $0x6, %edx
callq 0x3a0e1
movq %rax, %r12
movslq 0x10(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movl $0x7, %ecx
callq 0x3a1fc
movq %rax, %r13
movslq 0x10(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movq 0x8(%rsp), %r14
movl $0x8, %ecx
callq 0x3a1fc
movq %rax, 0x10(%rsp)
movslq 0x10(%rbx), %rax
testq %rax, %rax
jle 0x1327f
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
xorps %xmm0, %xmm0
cvtsi2sdl 0x1407140(%rbx,%rcx,4), %xmm0
mulsd (%r14,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
addsd %xmm0, %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x131b1
testl %eax, %eax
jle 0x1327f
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebp, %ebp
movsd (%r14,%rbp,8), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm1, 0x30(%rsp)
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movslq %eax, %r15
leaq (,%r15,4), %rdi
leaq 0x9339e(%rip), %rsi     # 0xa65b6
movl $0x13, %edx
callq 0x3a0e1
movq %rax, (%r12,%rbp,8)
testl %r15d, %r15d
jle 0x1324d
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x3af20
cltd
idivl 0x1407140(%rbx,%rbp,4)
movq (%r12,%rbp,8), %rax
movl %edx, (%rax,%r14,4)
incq %r14
cmpq %r14, %r15
jne 0x1322e
movl $0x4, %edx
movq %rax, %rdi
movq %r15, %rsi
leaq 0x2736a(%rip), %rcx     # 0x3a5c9
callq 0x4240
incq %rbp
movslq 0x10(%rbx), %rax
cmpq %rax, %rbp
movq 0x8(%rsp), %r14
movsd 0x30(%rsp), %xmm1
jl 0x131ec
movq 0x20(%rsp), %r14
testq %r14, %r14
movq 0x18(%rsp), %rbp
movq 0x10(%rsp), %r15
je 0x132fb
movq %r14, %rdi
callq 0x2f33a
movq %r15, %rsi
movslq %eax, %r15
movq (%r12,%r15,8), %rcx
movslq (%r13,%r15,4), %rdx
movl (%rsi,%r15,4), %eax
cmpl %eax, (%rcx,%rdx,4)
jne 0x132e9
movsbl 0x1a8(%rbx), %esi
movq %rbp, %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x2f378
movq 0x10(%rsp), %rsi
movslq (%r13,%r15,4), %rcx
leaq 0x1(%rcx), %rax
movl %eax, (%r13,%r15,4)
movq (%r12,%r15,8), %rdx
movl (%rsi,%r15,4), %eax
cmpl %eax, 0x4(%rdx,%rcx,4)
je 0x132b3
incl %eax
movl %eax, (%rsi,%r15,4)
movq 0x10(%r14), %r14
testq %r14, %r14
movq %rsi, %r15
jne 0x13293
movq %rbp, %rdi
callq 0x42a0
movq %r13, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
movl 0x10(%rbx), %esi
movq %r12, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a14b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq