// File: /workspace/github_c_makefile_star2_O1/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, %r12d
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x957aa(%rip), %rsi     # 0xa88a1
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x131aa
movq %rax, %rbp
movl %r12d, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movslq 0x10(%rbx), %rdi
shlq $0x3, %rdi
leaq 0x9044e(%rip), %r15     # 0xa3572
movq %r15, %rsi
movl $0x6, %edx
callq 0x390f5
movq %rax, %r12
movslq 0x10(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movl $0x7, %ecx
callq 0x39210
movq %rax, %r13
movslq 0x10(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movl $0x8, %ecx
callq 0x39210
movq %rax, 0x18(%rsp)
movslq 0x10(%rbx), %rax
testq %rax, %rax
movq %r14, 0x28(%rsp)
movq %rbp, 0x20(%rsp)
xorpd %xmm1, %xmm1
jle 0x131b9
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
xorps %xmm0, %xmm0
cvtsi2sdl 0x1407140(%rbx,%rcx,4), %xmm0
mulsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%rcx,8)
addsd %xmm0, %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x13186
jmp 0x131be
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdx
cmpl $0x0, 0x10(%rbx)
jle 0x1326c
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebp, %ebp
movsd %xmm1, 0x30(%rsp)
movsd (%rdx,%rbp,8), %xmm0
mulsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movslq %eax, %r15
leaq (,%r15,4), %rdi
leaq 0x9036e(%rip), %rsi     # 0xa3572
movl $0x13, %edx
callq 0x390f5
movq %rax, (%r12,%rbp,8)
testl %r15d, %r15d
jle 0x13239
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x39f18
cltd
idivl 0x1407140(%rbx,%rbp,4)
movq (%r12,%rbp,8), %rax
movl %edx, (%rax,%r14,4)
incq %r14
cmpq %r14, %r15
jne 0x1321a
movq (%r12,%rbp,8), %rdi
movl $0x4, %edx
movq %r15, %rsi
leaq 0x26371(%rip), %rcx     # 0x395bd
callq 0x4240
incq %rbp
movslq 0x10(%rbx), %rax
cmpq %rax, %rbp
movq 0x10(%rsp), %rdx
movsd 0x30(%rsp), %xmm1
jl 0x131df
movq 0x28(%rsp), %r14
testq %r14, %r14
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %r15
je 0x132e8
movq %r14, %rdi
callq 0x2eaca
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 0x132d6
movsbl 0x1a8(%rbx), %esi
movq %rbp, %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x2eb08
movq 0x18(%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 0x132a0
incl %eax
movl %eax, (%rsi,%r15,4)
movq 0x10(%r14), %r14
testq %r14, %r14
movq %rsi, %r15
jne 0x13280
movq %rbp, %rdi
callq 0x42a0
movq %r13, %rdi
callq 0x39194
movq %r15, %rdi
callq 0x39194
movl 0x10(%rbx), %esi
movq %r12, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3915f