// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/poly.c
// Function: polyfit
Polynomptr polyfit(double** data, int datasize, int degree)
{
	/*!Last Changed 21.01.2005*/
 double pow1, pow2;
 int i, j, k;
 matrix A, w, y;
 Polynomptr p;
 A = matrix_alloc(degree + 1, degree + 1);
 y = matrix_alloc(degree + 1, 1);
 for (k = 0; k < datasize; k++)
  {
   pow1 = 1;
   for (i = 0; i < degree + 1; i++)
    {
     pow2 = pow1;
     for (j = 0; j < degree + 1; j++)
      {
       A.values[i][j] += pow2;                              /*fpow(inp[count-1],i+j);*/
       pow2 *= data[k][0];
      }
     y.values[i][0] += data[k][1] * pow1;                  /*out[count-1]*fpow(inp[count-1],i);*/
     pow1 *= data[k][0];
    }
  }
 p = create_polynom();
 matrix_inverse(&A);
 w = matrix_multiply(A,y);
 for (i = 0; i < degree + 1; i++)
   add_polynode_to_polynom(p, i, w.values[i][0]);
 matrix_free(A);
 matrix_free(w);
 matrix_free(y);
 return p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl -0x10(%rbp), %esi
addl $0x1, %esi
callq 0x57fc0
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl $0x1, %esi
callq 0x57fc0
movq %rax, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x82b00
movsd 0x5f601(%rip), %xmm0    # 0xe2018
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x82af0
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x82a96
movsd -0x20(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
mulsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x82a45
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x8(%rax), %xmm0
movsd -0x18(%rbp), %xmm2
movq -0x58(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x82a23
jmp 0x82af2
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x82a03
callq 0x82340
movq %rax, -0x68(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5c470
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x82b86
movq -0x68(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
callq 0x80e00
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x82b52
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x59ea0
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x59ea0
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x59ea0
movq -0x68(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)