// File: /workspace/github_cpp_makefile_star2_O3/qmmlib[P]QmmLibrary/linear.cpp
// Function: cross_validation
void cross_validation(const problem *prob, const parameter *param, int nr_fold, double *target)
{
	int i;
	int *fold_start = Malloc(int,nr_fold+1);
	int l = prob->l;
	int *perm = Malloc(int,l);

	for(i=0;i<l;i++) perm[i]=i;
	for(i=0;i<l;i++)
	{
		int j = i+rand()%(l-i);
		swap(perm[i],perm[j]);
	}
	for(i=0;i<=nr_fold;i++)
		fold_start[i]=i*l/nr_fold;

	for(i=0;i<nr_fold;i++)
	{
		int begin = fold_start[i];
		int end = fold_start[i+1];
		int j,k;
		struct problem subprob;

		subprob.bias = prob->bias;
		subprob.n = prob->n;
		subprob.l = l-(end-begin);
		subprob.x = Malloc(struct feature_node*,subprob.l);
		subprob.y = Malloc(double,subprob.l);

		k=0;
		for(j=0;j<begin;j++)
		{
			subprob.x[k] = prob->x[perm[j]];
			subprob.y[k] = prob->y[perm[j]];
			++k;
		}
		for(j=end;j<l;j++)
		{
			subprob.x[k] = prob->x[perm[j]];
			subprob.y[k] = prob->y[perm[j]];
			++k;
		}
		struct model *submodel = train(&subprob,param);
		for(j=begin;j<end;j++)
			target[perm[j]] = predict(submodel,prob->x[perm[j]]);
		free_and_destroy_model(&submodel);
		free(subprob.x);
		free(subprob.y);
	}
	free(fold_start);
	free(perm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r13
movl %edx, %r14d
movq %rsi, 0x58(%rsp)
movq %rdi, %r15
leal 0x1(%r14), %eax
movl %eax, 0x20(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x32f0
movq %rax, %r12
movslq (%r15), %rbx
leaq (,%rbx,4), %rdi
callq 0x32f0
movq %rbx, 0x18(%rsp)
testq %rbx, %rbx
movq %rax, 0x10(%rsp)
jle 0x1424f
movq 0x18(%rsp), %rdi
leal 0x1(%rdi), %esi
andl $-0x2, %esi
leaq -0x1(%rdi), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x5143(%rip), %xmm1     # 0x192f0
xorl %ecx, %ecx
movdqa 0x5149(%rip), %xmm2     # 0x19300
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x5149(%rip), %xmm4     # 0x19310
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x141fb
movl %ecx, (%rax,%rcx,4)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x14210
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rax,%rcx,4)
addq $0x2, %rcx
paddq %xmm4, %xmm1
cmpq %rcx, %rsi
jne 0x141c7
testl %edi, %edi
jle 0x1424f
xorl %ebx, %ebx
movq 0x18(%rsp), %rbp
callq 0x30a0
movq 0x10(%rsp), %rsi
cltd
idivl %ebp
movslq %edx, %rax
addq %rbx, %rax
movl (%rsi,%rbx,4), %ecx
movl (%rsi,%rax,4), %edx
movl %edx, (%rsi,%rbx,4)
movl %ecx, (%rsi,%rax,4)
incq %rbx
decq %rbp
jne 0x14228
testl %r14d, %r14d
movq 0x18(%rsp), %rbp
js 0x144a0
movl 0x20(%rsp), %eax
leaq -0x1(%rax), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0x4(,%rax,4), %rsi
andq $-0x8, %rsi
leal (,%rbp,2), %edi
movdqa 0x5066(%rip), %xmm1     # 0x192f0
xorl %ecx, %ecx
movdqa 0x506c(%rip), %xmm2     # 0x19300
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x506c(%rip), %xmm4     # 0x19310
xorl %r8d, %r8d
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %eax
notl %eax
testb $0x1, %al
je 0x142e1
movl %ecx, %eax
cltd
idivl %r14d
movl %eax, (%r12,%r8)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %eax
testb $0x1, %al
je 0x142fa
leal (%rcx,%rbp), %eax
cltd
idivl %r14d
movl %eax, 0x4(%r12,%r8)
paddq %xmm4, %xmm1
addq $0x8, %r8
addl %edi, %ecx
cmpq %r8, %rsi
jne 0x142a7
movl %r14d, %eax
movq %rax, 0x48(%rsp)
movl (%r12), %ebx
xorl %r14d, %r14d
movq %r12, 0x50(%rsp)
movq %r14, 0x60(%rsp)
movl 0x4(%r12,%r14,4), %ecx
movq 0x18(%r15), %xmm0
movq %xmm0, 0x40(%rsp)
movl 0x4(%r15), %eax
movl %eax, 0x2c(%rsp)
movl %ebx, %eax
movl %ecx, 0xc(%rsp)
subl %ecx, %eax
addl %ebp, %eax
movl %eax, 0x28(%rsp)
movslq %eax, %r14
shlq $0x3, %r14
movq %r14, %rdi
callq 0x32f0
movq %rax, 0x38(%rsp)
movq %r14, %rdi
callq 0x32f0
movq %rax, 0x30(%rsp)
testl %ebx, %ebx
jle 0x143a9
movl %ebx, %eax
xorl %ecx, %ecx
movq 0x10(%rsp), %r8
movq 0x10(%r15), %rdx
movslq (%r8,%rcx,4), %rsi
movq (%rdx,%rsi,8), %rdx
movq 0x38(%rsp), %rdi
movq %rdx, (%rdi,%rcx,8)
movq 0x8(%r15), %rdx
movq (%rdx,%rsi,8), %xmm0
movq 0x30(%rsp), %rdx
movq %xmm0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x14377
jmp 0x143b0
xorl %eax, %eax
movq 0x10(%rsp), %r8
cmpl %ebp, 0xc(%rsp)
jge 0x143ee
movslq 0xc(%rsp), %rcx
movq 0x10(%r15), %rdx
movslq (%r8,%rcx,4), %rsi
movq (%rdx,%rsi,8), %rdx
movq 0x38(%rsp), %rdi
movq %rdx, (%rdi,%rax,8)
movq 0x8(%r15), %rdx
movq (%rdx,%rsi,8), %xmm0
movq 0x30(%rsp), %rdx
movq %xmm0, (%rdx,%rax,8)
incq %rax
incq %rcx
cmpq %rcx, %rbp
jne 0x143bb
leaq 0x28(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x7bfc
movq %rax, %rbp
cmpl 0xc(%rsp), %ebx
jge 0x14456
movslq %ebx, %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %r12d
subl %ebx, %r12d
xorl %ebx, %ebx
movq 0x10(%r15), %rax
movq %r15, %r14
movq %r13, %r15
movq 0x20(%rsp), %rcx
movslq (%rcx,%rbx,4), %r13
movq (%rax,%r13,8), %rsi
movq %rbp, %rdi
callq 0x144c1
movq %xmm0, (%r15,%r13,8)
movq %r15, %r13
movq %r14, %r15
incq %rbx
cmpl %ebx, %r12d
jne 0x14423
testq %rbp, %rbp
je 0x1446b
movq %rbp, %rdi
callq 0x1502a
movq %rbp, %rdi
callq 0x3290
movq 0x60(%rsp), %r14
incq %r14
movq 0x38(%rsp), %rdi
callq 0x3290
movq 0x30(%rsp), %rdi
callq 0x3290
movl 0xc(%rsp), %ebx
cmpq 0x48(%rsp), %r14
movq 0x50(%rsp), %r12
movq 0x18(%rsp), %rbp
jne 0x1431d
movq %r12, %rdi
callq 0x3290
movq 0x10(%rsp), %rdi
callq 0x3290
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq