// File: /workspace/github_c_makefile_star2_O2/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 0x2bc03
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movq %rdi, %r12
movl %esi, 0x8(%rsp)
movl %edx, 0x14(%rsp)
movl %edx, %ebx
leaq 0x6cfb4(%rip), %r14     # 0x98a74
pushq $0x4
popq %r13
pushq $0x5
popq %rcx
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x35067
movq %rax, 0x20(%rsp)
pushq $0x6
popq %rcx
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %r13
movq %r14, %rdx
callq 0x35067
movq %rax, 0x18(%rsp)
leaq (,%rbx,8), %rdi
pushq $0x7
popq %rdx
movq %r14, %rsi
callq 0x34f59
movq %rax, %rbp
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x2bb2e
movslq (%r15,%r14,4), %rdi
shlq $0x2, %rdi
movq %r13, %rsi
pushq $0x9
popq %rdx
callq 0x34f59
movq %rax, (%rbp,%r14,8)
incq %r14
jmp 0x2bb0c
movslq 0x8(%rsp), %r14
leaq (,%r14,4), %rdi
leaq 0x6cf32(%rip), %rsi     # 0x98a74
pushq $0xa
popq %rdx
callq 0x34f59
movq %rax, %rbx
xorl %eax, %eax
testq %r14, %r14
cmovleq %rax, %r14
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r8
cmpq %rax, %r14
je 0x2bb8a
movslq (%r12,%rax,4), %rcx
movq (%rbp,%rcx,8), %rdx
movslq (%rdi,%rcx,4), %rsi
movl %eax, (%rdx,%rsi,4)
movl (%r8,%rcx,4), %edx
movl %edx, (%rbx,%rax,4)
incl %edx
movl %edx, (%r8,%rcx,4)
incl (%rdi,%rcx,4)
incq %rax
jmp 0x2bb60
movq %r15, 0x8(%rsp)
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x2bbd1
movq %r12, %r13
movslq (%r12,%r15,4), %r12
xorl %eax, %eax
callq 0x35c7f
cltd
movq 0x8(%rsp), %rcx
idivl (%rcx,%r12,4)
movslq %edx, %rax
movq (%rbp,%r12,8), %rcx
movq %r13, %r12
movslq (%rcx,%rax,4), %rax
movl (%rbx,%r15,4), %ecx
movl (%rbx,%rax,4), %edx
movl %edx, (%rbx,%r15,4)
movl %ecx, (%rbx,%rax,4)
incq %r15
jmp 0x2bb92
movq %rbp, %rdi
movl 0x14(%rsp), %esi
callq 0x34fc3
movq 0x20(%rsp), %rdi
callq 0x34ff7
movq 0x18(%rsp), %rdi
callq 0x34ff7
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %edi
jmp 0x35cf7