// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/regression.c
// Function: train_gprocessreg
void* train_gprocessreg(Instanceptr* trdata, Instanceptr *cvdata, void* parameters)
{
 /*!Last Changed 15.01.2009*/
 int i, j;
 matrix kernel_matrix, t;
 Svm_nodeptr* nodelist;
 Svm_parameter param;
 Gprocess_parameterptr gp = (Gprocess_parameterptr) parameters;
 Model_gprocessregressionptr m = safemalloc(sizeof(Model_gprocessregression), "train_gprocessreg", 3);
 Instanceptr tmp = *trdata;
 m->size = data_size(*trdata);
 m->data = *trdata;
 kernel_matrix = matrix_alloc(m->size, m->size);
 t = matrix_alloc(m->size, 1);
 nodelist = safemalloc(m->size * sizeof(Svm_nodeptr), "train_gprocessreg", 10);
 i = 0;
 while (tmp)
  {
   nodelist[i] = instance_to_svmnode(tmp);
   t.values[i][0] = give_regressionvalue(tmp);
   tmp = tmp->next;
   i++;
  }
 param.kernel_type = gp->kernel_type;
 param.coef0 = gp->coef0;
 param.gamma = gp->gamma;
 param.degree = gp->degree;
 for (i = 0; i < m->size; i++)
   for (j = 0; j < m->size; j++)
     kernel_matrix.values[i][j] = k_function(nodelist[i], nodelist[j], param);
 for (i = 0; i < m->size; i++)
   kernel_matrix.values[i][i] += gp->sigma;
 matrix_inverse(&kernel_matrix);
 matrix_product(&kernel_matrix, t);
 m->weights = safemalloc(m->size * sizeof(double), "train_gprocessreg", 25);
 for (i = 0; i < m->size; i++)
   m->weights[i] = kernel_matrix.values[i][0];
 for (i = 0; i < m->size; i++)
   safe_free(nodelist[i]);
 safe_free(nodelist);
 matrix_free(kernel_matrix);
 matrix_free(t);
 return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdx, 0x58(%rsp)
movq %rdi, %r15
leaq 0x3ceaf(%rip), %r12     # 0xafae5
movl $0x18, %edi
movq %r12, %rsi
movl $0x3, %edx
callq 0x3a0e1
movq %rax, %rbx
movq (%r15), %r14
movq %r14, %rdi
callq 0x30309
movl %eax, (%rbx)
movq (%r15), %rcx
movq %rcx, 0x8(%rbx)
movl %eax, %edi
movl %eax, %esi
callq 0x3d79d
movq %rdx, %rbp
movq %rax, 0x68(%rsp)
movq %rdx, 0x70(%rsp)
movl (%rbx), %edi
movl $0x1, %esi
callq 0x3d79d
movq %rax, 0x60(%rsp)
movq %rdx, %r13
movslq (%rbx), %rdi
shlq $0x3, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x3a0e1
movq %rax, %r12
testq %r14, %r14
je 0x72cd2
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x2ec9f
movq %rax, (%r12,%r15)
movq %r14, %rdi
callq 0x2f35e
movq (%r13,%r15), %rax
movsd %xmm0, (%rax)
movq 0x10(%r14), %r14
addq $0x8, %r15
testq %r14, %r14
jne 0x72ca8
movq %r13, 0x78(%rsp)
movq 0x58(%rsp), %rcx
movl 0x8(%rcx), %eax
movl %eax, 0x84(%rsp)
movsd 0x10(%rcx), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x20(%rcx), %xmm0
movsd %xmm0, 0x90(%rsp)
movl 0x18(%rcx), %eax
movl %eax, 0x88(%rsp)
movl (%rbx), %eax
testl %eax, %eax
movq 0x60(%rsp), %r13
jle 0x72da0
xorl %r13d, %r13d
leaq 0x80(%rsp), %r14
testl %eax, %eax
jle 0x72d68
xorl %r15d, %r15d
movq (%r12,%r13,8), %rax
movq (%r12,%r15,8), %rdx
movl $0xb, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq %rdx, %rsi
callq 0x93d00
movq (%rbp,%r13,8), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movl (%rbx), %eax
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x72d2d
jmp 0x72d6b
movslq %eax, %rcx
incq %r13
cmpq %rcx, %r13
jl 0x72d26
testl %eax, %eax
movq 0x60(%rsp), %r13
movq 0x58(%rsp), %rsi
jle 0x72da0
movl %eax, %eax
xorl %ecx, %ecx
movsd (%rsi), %xmm0
movq (%rbp,%rcx,8), %rdx
addsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x72d85
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x409b7
movq %r14, %rdi
movq %r13, %rsi
movq 0x78(%rsp), %r15
movq %r15, %rdx
callq 0x3fb95
movslq (%rbx), %rdi
shlq $0x3, %rdi
leaq 0x3cd17(%rip), %rsi     # 0xafae5
movl $0x19, %edx
callq 0x3a0e1
movq %rax, 0x10(%rbx)
movslq (%rbx), %rcx
testq %rcx, %rcx
jle 0x72e1b
movq 0x70(%rsp), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movsd (%rdi), %xmm0
movsd %xmm0, (%rax,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x72deb
testl %ecx, %ecx
jle 0x72e1b
xorl %r14d, %r14d
movq (%r12,%r14,8), %rdi
callq 0x3a180
incq %r14
movslq (%rbx), %rax
cmpq %rax, %r14
jl 0x72e07
movq %r12, %rdi
callq 0x3a180
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x3ed51
movq %r13, %rdi
movq %r15, %rsi
callq 0x3ed51
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq