// File: /workspace/github_c_makefile_star2_O2/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 0x89735(%rip), %rsi     # 0x9b891
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x12347
movq %rax, 0x8(%rsp)
movslq 0x10(%rbx), %rdi
shlq $0x3, %rdi
movq %r14, 0x10(%rsp)
movl %ebp, %r14d
leaq 0x843cd(%rip), %rbp     # 0x96556
pushq $0x6
popq %rdx
movq %rbp, %rsi
callq 0x34f59
movq %rax, %r12
movslq 0x10(%rbx), %rdi
pushq $0x4
popq %rsi
pushq $0x7
popq %rcx
movq %rbp, %rdx
callq 0x35067
movq %rax, %r13
movslq 0x10(%rbx), %rdi
pushq $0x8
popq %rcx
pushq $0x4
popq %rsi
movq %rbp, %rdx
callq 0x35067
movq %rax, (%rsp)
movl 0x10(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
xorpd %xmm1, %xmm1
cmpq %rcx, %rdx
je 0x121f8
cvtsi2sdl 0x1407140(%rbx,%rcx,4), %xmm0
mulsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%r15,%rcx,8)
addsd %xmm0, %xmm1
incq %rcx
jmp 0x121d5
movq %r15, 0x28(%rsp)
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r15d, %r15d
movsd %xmm1, 0x20(%rsp)
cltq
cmpq %rax, %r15
jge 0x122af
movq 0x28(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
mulsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movslq %eax, %rbp
leaq (,%rbp,4), %rdi
leaq 0x8430f(%rip), %rsi     # 0x96556
pushq $0x13
popq %rdx
callq 0x34f59
movq %rax, (%r12,%r15,8)
testl %ebp, %ebp
movl $0x0, %r14d
movq %rbp, 0x30(%rsp)
cmovgl %ebp, %r14d
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x12287
xorl %eax, %eax
callq 0x35c7f
cltd
idivl 0x1407140(%rbx,%r15,4)
movq (%r12,%r15,8), %rax
movl %edx, (%rax,%rbp,4)
incq %rbp
jmp 0x12266
movq %rax, %rdi
movq 0x30(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0x23100(%rip), %rcx     # 0x35399
callq 0x4240
incq %r15
movl 0x10(%rbx), %eax
movsd 0x20(%rsp), %xmm1
jmp 0x12211
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %rbp
testq %r15, %r15
je 0x12315
movq %r15, %rdi
callq 0x2b47e
movslq %eax, %r14
movl (%r13,%r14,4), %eax
movq (%r12,%r14,8), %rcx
movslq %eax, %rdx
movq (%rsp), %rax
movl (%rax,%r14,4), %eax
cmpl %eax, (%rcx,%rdx,4)
jne 0x12305
movsbl 0x1a8(%rbx), %esi
movq %rbp, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x2b4ba
movl (%r13,%r14,4), %eax
incl %eax
movl %eax, (%r13,%r14,4)
jmp 0x122ce
incl %eax
movq (%rsp), %rcx
movl %eax, (%rcx,%r14,4)
movq 0x10(%r15), %r15
jmp 0x122b9
movq %rbp, %rdi
callq 0x42a0
movq %r13, %rdi
callq 0x34ff7
movq (%rsp), %rdi
callq 0x34ff7
movl 0x10(%rbx), %esi
movq %r12, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34fc3
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq