// File: /workspace/github_c_makefile_star2_O1/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 0x2f2de
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rdi, %r13
movl %esi, 0x8(%rsp)
movl %edx, 0xc(%rsp)
movl %edx, %ebp
leaq 0x76902(%rip), %rbx     # 0xa5a7c
movl $0x4, %esi
movq %rbp, %rdi
movq %rbx, %rdx
movl $0x5, %ecx
callq 0x39210
movq %rax, %r12
movl $0x4, %esi
movq %rbp, %rdi
movq %rbx, %rdx
movl $0x6, %ecx
callq 0x39210
movq %rax, 0x10(%rsp)
leaq (,%rbp,8), %rdi
movq %rbx, %rsi
movl $0x7, %edx
callq 0x390f5
movq %rax, %rbx
xorl %r15d, %r15d
movslq (%r14,%r15,4), %rdi
shlq $0x2, %rdi
leaq 0x768a6(%rip), %rsi     # 0xa5a7c
movl $0x9, %edx
callq 0x390f5
movq %rax, (%rbx,%r15,8)
incq %r15
cmpq %r15, %rbp
jne 0x2f1c7
movl 0x8(%rsp), %ebp
movslq %ebp, %r15
leaq (,%r15,4), %rdi
leaq 0x7687a(%rip), %rsi     # 0xa5a7c
movl $0xa, %edx
callq 0x390f5
movl %ebp, %r8d
movq %rax, %rbp
testl %r8d, %r8d
movq 0x10(%rsp), %rdi
jle 0x2f244
xorl %eax, %eax
movslq (%r13,%rax,4), %rcx
movq (%rbx,%rcx,8), %rdx
movslq (%r12,%rcx,4), %rsi
movl %eax, (%rdx,%rsi,4)
movl (%rdi,%rcx,4), %edx
movl %edx, (%rbp,%rax,4)
incl (%rdi,%rcx,4)
incl (%r12,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0x2f21e
movq %r12, 0x18(%rsp)
testl %r8d, %r8d
jle 0x2f2ac
movq %r14, %rsi
xorl %r12d, %r12d
movq %rbp, 0x20(%rsp)
movq %r13, %r14
movslq (%r13,%r12,4), %r13
xorl %eax, %eax
movq %rbx, %rbp
movq %r15, %rbx
movq %rsi, %r15
callq 0x39f18
movq %r15, %rsi
movq %rbx, %r15
movq %rbp, %rbx
movq 0x20(%rsp), %rbp
cltd
idivl (%rsi,%r13,4)
movslq %edx, %rax
movq (%rbx,%r13,8), %rcx
movq %r14, %r13
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 0x2f259
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x3915f
movq 0x18(%rsp), %rdi
callq 0x39194
movq 0x10(%rsp), %rdi
callq 0x39194
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %edi
jmp 0x39fdc