// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/instance.c
// Function: stratified_partition
int* stratified_partition(int *prior_class_information, int datasize, int classnumber, int* classcounts)
{
	/*!Last Changed 02.02.2004 added safemalloc*/
	/*!Last Changed 23.11.2003*/
 long i,j,tmp;
	int* classes, classno, **indexes, *positions, *result;
	if (classnumber > 0)
	 {
  	positions = (int*)safecalloc(classnumber,sizeof(int), "stratified_partition", 5);
  	classes = (int*)safecalloc(classnumber,sizeof(int), "stratified_partition", 6);
	  indexes = safemalloc(classnumber * sizeof(int *), "stratified_partition", 7);
			for (i = 0; i < classnumber; i++)
				 indexes[i] = safemalloc(classcounts[i] * sizeof(int), "stratified_partition", 9);
   result = (int *)safemalloc(datasize * sizeof(int), "stratified_partition", 10);
   for (i = 0; i < datasize;i++)
			 {
  		 classno = prior_class_information[i];
	  		indexes[classno][positions[classno]] = i;
     result[i] = classes[classno];
			  (classes[classno])++;
			  (positions[classno])++;
			 }
   for (i = 0; i < datasize; i++)
			 {
  		 classno = prior_class_information[i];
     j = myrand() % classcounts[classno];
		  	j = indexes[classno][j];
     tmp = result[i];
     result[i] = result[j];
     result[j] = tmp;
			 }
	  free_2d((void**)indexes, classnumber);
  	safe_free(positions);
  	safe_free(classes);
	 }
	else
		 result = random_array(datasize);
	return result;
}

// Assembly:
testl %edx, %edx
jle 0x2fb2b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movl %esi, 0x8(%rsp)
movq %rdi, 0x20(%rsp)
movl %edx, 0xc(%rsp)
movl %edx, %ebp
leaq 0x79114(%rip), %r15     # 0xa8af4
movl $0x4, %esi
movq %rbp, %rdi
movq %r15, %rdx
movl $0x5, %ecx
callq 0x3a1fc
movq %rax, 0x18(%rsp)
movl $0x4, %esi
movq %rbp, %rdi
movq %r15, %rdx
movl $0x6, %ecx
callq 0x3a1fc
movq %rax, 0x10(%rsp)
leaq (,%rbp,8), %rdi
movq %r15, %rsi
movl $0x7, %edx
callq 0x3a0e1
movq %rax, %rbx
xorl %r12d, %r12d
movslq (%r14,%r12,4), %rdi
shlq $0x2, %rdi
movq %r15, %rsi
movl $0x9, %edx
callq 0x3a0e1
movq %rax, (%rbx,%r12,8)
incq %r12
cmpq %r12, %rbp
jne 0x2fa2f
movl 0x8(%rsp), %r12d
movslq %r12d, %r15
leaq (,%r15,4), %rdi
leaq 0x7908d(%rip), %rsi     # 0xa8af4
movl $0xa, %edx
callq 0x3a0e1
movq %rax, %rbp
testl %r12d, %r12d
movq 0x20(%rsp), %r8
jle 0x2faf9
movq %r14, %r13
xorl %eax, %eax
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %r10
movslq (%r8,%rax,4), %rcx
movq (%rbx,%rcx,8), %rdx
movslq (%r9,%rcx,4), %rsi
movl %eax, (%rdx,%rsi,4)
movl (%r10,%rcx,4), %edx
movl %edx, (%rbp,%rax,4)
incl %edx
movl %edx, (%r10,%rcx,4)
incl (%r9,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0x2fa8d
testl %r12d, %r12d
jle 0x2faf9
xorl %r12d, %r12d
movslq (%r8,%r12,4), %r14
xorl %eax, %eax
callq 0x3af20
movq 0x20(%rsp), %r8
cltd
idivl (%r13,%r14,4)
movslq %edx, %rax
movq (%rbx,%r14,8), %rcx
movslq (%rcx,%rax,4), %rax
movl (%rbp,%r12,4), %ecx
movl (%rbp,%rax,4), %edx
movl %edx, (%rbp,%r12,4)
movl %ecx, (%rbp,%rax,4)
incq %r12
cmpq %r12, %r15
jne 0x2fabe
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x3a14b
movq 0x18(%rsp), %rdi
callq 0x3a180
movq 0x10(%rsp), %rdi
callq 0x3a180
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %edi
jmp 0x3afe4