// File: /workspace/github_cpp_makefile_star2_O3/cjlin1[P]liblinear/linear.cpp
// Function: cross_validation
void cross_validation(const problem *prob, const parameter *param, int nr_fold, double *target)
{
	int i;
	int *fold_start;
	int l = prob->l;
	int *perm = Malloc(int,l);
	if (nr_fold > l)
	{
		nr_fold = l;
		fprintf(stderr,"WARNING: # folds > # data. Will use # folds = # data instead (i.e., leave-one-out cross validation)\n");
	}
	fold_start = Malloc(int,nr_fold+1);
	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 $0x78, %rsp
movq %rcx, %r12
movl %edx, %r14d
movq %rsi, 0x60(%rsp)
movq %rdi, %r15
movl (%rdi), %r13d
movslq %r13d, %rbx
leaq (,%rbx,4), %rdi
callq 0x21f0
movq %rax, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
cmpl %r14d, %ebx
jl 0xa438
movq %r14, 0x18(%rsp)
leal 0x1(%r14), %eax
movl %eax, 0xc(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x21f0
movq %rax, 0x28(%rsp)
testl %r13d, %r13d
movq 0x10(%rsp), %rbp
jle 0xa1bd
leal 0x1(%r13), %eax
andl $-0x2, %eax
leaq -0x1(%r13), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x4d45(%rip), %xmm1     # 0xee60
xorl %ecx, %ecx
movdqa 0x4d4b(%rip), %xmm2     # 0xee70
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x4d4b(%rip), %xmm4     # 0xee80
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 0xa16a
movl %ecx, (%rbp,%rcx,4)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0xa17f
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rbp,%rcx,4)
addq $0x2, %rcx
paddq %xmm4, %xmm1
cmpq %rcx, %rax
jne 0xa135
testl %r13d, %r13d
jle 0xa1bd
xorl %ebx, %ebx
movq %r13, %r14
callq 0x2090
cltd
idivl %r14d
movslq %edx, %rax
addq %rbx, %rax
movl (%rbp,%rbx,4), %ecx
movl (%rbp,%rax,4), %edx
movl %edx, (%rbp,%rbx,4)
movl %ecx, (%rbp,%rax,4)
incq %rbx
decq %r14
jne 0xa196
movq 0x18(%rsp), %r10
testl %r10d, %r10d
movq 0x28(%rsp), %rdi
js 0xa41a
movl 0xc(%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 (,%r13,2), %r9d
movdqa 0x4c62(%rip), %xmm1     # 0xee60
xorl %ecx, %ecx
movdqa 0x4c68(%rip), %xmm2     # 0xee70
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x4c68(%rip), %xmm4     # 0xee80
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 0xa255
movl %ecx, %eax
cltd
idivl %r10d
movl %eax, (%rdi,%r8)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %eax
testb $0x1, %al
je 0xa26f
leal (%rcx,%r13), %eax
cltd
idivl %r10d
movl %eax, 0x4(%rdi,%r8)
paddq %xmm4, %xmm1
addq $0x8, %r8
addl %r9d, %ecx
cmpq %r8, %rsi
jne 0xa21b
movl %r10d, %eax
movq %rax, 0x50(%rsp)
movl (%rdi), %ebx
xorl %r14d, %r14d
movq %r13, 0x58(%rsp)
movl 0x4(%rdi,%r14,4), %ecx
movq 0x18(%r15), %xmm0
movq %xmm0, 0x48(%rsp)
movl 0x4(%r15), %eax
movl %eax, 0x34(%rsp)
movl %ebx, %eax
movl %ecx, 0xc(%rsp)
subl %ecx, %eax
addl %r13d, %eax
movl %eax, 0x30(%rsp)
movslq %eax, %rbp
shlq $0x3, %rbp
movq %rbp, %rdi
callq 0x21f0
movq %rax, 0x40(%rsp)
movq %rbp, %rdi
callq 0x21f0
movq %rax, 0x38(%rsp)
testl %ebx, %ebx
jle 0xa31e
movl %ebx, %eax
xorl %ecx, %ecx
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %r9
movq 0x10(%r15), %rdx
movslq (%r8,%rcx,4), %rsi
movq (%rdx,%rsi,8), %rdx
movq 0x40(%rsp), %rdi
movq %rdx, (%rdi,%rcx,8)
movq 0x8(%r15), %rdx
movq (%rdx,%rsi,8), %xmm0
movq 0x38(%rsp), %rdx
movq %xmm0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0xa2ec
jmp 0xa32a
xorl %eax, %eax
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %r9
movq %r14, 0x68(%rsp)
cmpl %r13d, 0xc(%rsp)
jge 0xa36e
movslq 0xc(%rsp), %rcx
movq 0x10(%r15), %rdx
movslq (%r8,%rcx,4), %rsi
movq (%rdx,%rsi,8), %rdx
movq 0x40(%rsp), %rdi
movq %rdx, (%rdi,%rax,8)
movq 0x8(%r15), %rdx
movq (%rdx,%rsi,8), %xmm0
movq 0x38(%rsp), %rdx
movq %xmm0, (%rdx,%rax,8)
incq %rax
incq %rcx
cmpq %rcx, %r9
jne 0xa33b
leaq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x5e06
movq %rax, 0x70(%rsp)
cmpl 0xc(%rsp), %ebx
jge 0xa3db
movq %rax, %r13
movslq %ebx, %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0x18(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %r14d
subl %ebx, %r14d
xorl %ebx, %ebx
movq 0x10(%r15), %rax
movq %r15, %rbp
movq %r12, %r15
movq 0x18(%rsp), %rcx
movslq (%rcx,%rbx,4), %r12
movq (%rax,%r12,8), %rsi
movq %r13, %rdi
callq 0xa445
movq %xmm0, (%r15,%r12,8)
movq %r15, %r12
movq %rbp, %r15
incq %rbx
cmpl %ebx, %r14d
jne 0xa3a8
movq 0x68(%rsp), %r14
incq %r14
leaq 0x70(%rsp), %rdi
callq 0xa490
movq 0x40(%rsp), %rdi
callq 0x21a0
movq 0x38(%rsp), %rdi
callq 0x21a0
movl 0xc(%rsp), %ebx
cmpq 0x50(%rsp), %r14
movq 0x58(%rsp), %r13
movq 0x28(%rsp), %rdi
jne 0xa291
callq 0x21a0
movq 0x10(%rsp), %rdi
callq 0x21a0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x24f2
movl %r13d, %r14d
jmp 0xa0d2