// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/plot.c
// Function: plotgauss2d
void plotgauss2d(char* names, int contour)
{
 int i;
 double obs1, obs2, dist, maxdist;
 double *observations1 = NULL, *observations2 = NULL, *averages;
 matrix observations, covariance, avg, x;
 Point p, dummyp, p3;
 char st2[2], *legendname;
 FILE* myfile;
 int datacount, color;
 if (!get_parameter_o("hold"))
   clear_image();
 legendname = file_only_name(names);
 color = img.imagelegend.legendcount;
 p3.x = color;
 add_legend((char)('A' + color), legendname);
 safe_free(legendname);
 st2[0] = plots[color];
 st2[1] = '\0';
 datacount = 0;
 myfile = fopen(names, "r");
 if (!myfile)
   return;
 while (fscanf(myfile,"%lf %lf\n", &obs1, &obs2) != EOF)
  {
   datacount++;
   observations1 = alloc(observations1, datacount * sizeof(double), datacount);
   observations1[datacount - 1] = obs1;
   observations2 = alloc(observations2, datacount * sizeof(double), datacount);
   observations2[datacount - 1] = obs2;
   p.x = (double) obs1;
   check_x_range(p);
   p.y = (double) obs2;
   check_y_range(p);
   add_object(OBJECT_STRING, p, dummyp, p3, st2);
  }
 fclose(myfile);
 observations = matrix_alloc(datacount, 2);
 avg = matrix_alloc(1, 2);
 for (i = 0; i < datacount; i++)
  {
   observations.values[i][0] = observations1[i];
   observations.values[i][1] = observations2[i];
  }
 covariance = matrix_covariance(observations, &averages);
 matrix_free(observations);
 memcpy(avg.values[0], averages, 2 * sizeof(double));
 safe_free(averages);
 x = matrix_alloc(1, 2);
 maxdist = -INT_MAX;
 for (i = 0; i < datacount; i++)
  {
   x.values[0][0] = observations1[i];
   x.values[0][1] = observations2[i];
   dist = mahalanobis_distance(x, avg, covariance);
   if (dist == -1)
    {
     matrix_free(x);
     safe_free(observations1);
     safe_free(observations2);
     matrix_free(covariance);
     matrix_free(avg);
     return;
    }
   dist = sqrt(dist);
   if (dist > maxdist)
     maxdist = dist;
  }
 matrix_free(x);
 safe_free(observations1);
 safe_free(observations2);
 plot_covariance(avg, covariance, contour, color, maxdist);
 matrix_free(covariance);
 matrix_free(avg);
 export_image();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x50f2e(%rip), %rdi     # 0xa7715
callq 0x536e7
testl %eax, %eax
jne 0x567f7
xorl %eax, %eax
callq 0x2da74
movq %rbx, %rdi
callq 0x37f08
movq %rax, %r14
leaq 0x3588af(%rip), %rax    # 0x3af0b8
movslq 0xec(%rax), %r12
leal 0x41(%r12), %eax
movsbl %al, %edi
movq %r14, %rsi
callq 0x2c324
movq %r14, %rdi
callq 0x39194
leaq 0x7b831(%rip), %rax     # 0xd2060
movb (%r12,%rax), %al
movb %al, 0xe(%rsp)
movb $0x0, 0xf(%rsp)
leaq 0x5204c(%rip), %rsi     # 0xa888f
movq %rbx, %rdi
callq 0x40f0
testq %rax, %rax
je 0x56b63
movq %rax, %rbp
movl %r15d, 0x54(%rsp)
leaq 0x51425(%rip), %rsi     # 0xa7c88
xorl %r14d, %r14d
leaq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %rax, %rdi
xorl %eax, %eax
callq 0x4070
cmpl $-0x1, %eax
movq %r12, 0x58(%rsp)
je 0x56959
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x8, %r13d
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r14, %rbx
incq %r14
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x390c8
movq %rax, %r12
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax,%rbx,8)
movq %r15, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x390c8
movq %rax, %r15
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rax,%rbx,8)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm1
callq 0x2d7ef
movsd 0x40(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x2d817
movl $0x1, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x20(%rsp), %xmm4
leaq 0xe(%rsp), %rsi
callq 0x2c3cc
movq %rbp, %rdi
leaq 0x5134f(%rip), %rsi     # 0xa7c88
leaq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %rcx
xorl %eax, %eax
callq 0x4070
addq $0x8, %r13
cmpl $-0x1, %eax
jne 0x568a2
jmp 0x5695f
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rbp, %rdi
callq 0x42a0
movl %r14d, %edi
movl $0x2, %esi
callq 0x3c6e5
movq %rax, %rbx
movq %rdx, %r13
movl $0x1, %edi
movl $0x2, %esi
callq 0x3c6e5
movq %rax, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movl %r14d, %ebp
testl %r14d, %r14d
je 0x569bf
xorl %eax, %eax
movsd (%r12,%rax,8), %xmm0
movq (%r13,%rax,8), %rcx
movsd %xmm0, (%rcx)
movsd (%r15,%rax,8), %xmm0
movsd %xmm0, 0x8(%rcx)
incq %rax
cmpq %rax, %rbp
jne 0x5699d
leaq 0x60(%rsp), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3f03e
movq %rax, 0x38(%rsp)
movq %rdx, 0x20(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3dbad
movq 0x28(%rsp), %rax
movq (%rax), %rax
leaq 0x60(%rsp), %rcx
movq (%rcx), %rdi
movupd (%rdi), %xmm0
movupd %xmm0, (%rax)
callq 0x39194
movl $0x1, %edi
movl $0x2, %esi
callq 0x3c6e5
movq %rax, 0x30(%rsp)
movq %rdx, %r13
testl %r14d, %r14d
je 0x56aab
movsd 0x4bae7(%rip), %xmm1    # 0xa2510
xorl %ebx, %ebx
movq 0x28(%rsp), %r14
movsd %xmm1, 0x10(%rsp)
movsd (%r12,%rbx,8), %xmm0
movq (%r13), %rax
movsd %xmm0, (%rax)
movsd (%r15,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rax)
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movq 0x38(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0x3f534
ucomisd 0x4c332(%rip), %xmm0    # 0xa2da8
jne 0x56a7e
jnp 0x56b2a
ucomisd 0x4c282(%rip), %xmm0    # 0xa2d08
jb 0x56a8e
sqrtsd %xmm0, %xmm0
jmp 0x56a93
callq 0x4300
movsd 0x10(%rsp), %xmm1
maxsd %xmm1, %xmm0
incq %rbx
movapd %xmm0, %xmm1
cmpq %rbx, %rbp
jne 0x56a30
jmp 0x56ab8
movsd 0x4ba5d(%rip), %xmm0    # 0xa2510
movq 0x28(%rsp), %r14
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x3dbad
movq %r12, %rdi
callq 0x39194
movq %r15, %rdi
callq 0x39194
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq 0x38(%rsp), %r12
movq %r12, %rdx
movq 0x20(%rsp), %r15
movq %r15, %rcx
movl 0x54(%rsp), %r8d
movq 0x58(%rsp), %r9
movsd 0x10(%rsp), %xmm0
callq 0x56163
movq %r12, %rdi
movq %r15, %rsi
callq 0x3dbad
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3dbad
xorl %eax, %eax
callq 0x2de4a
jmp 0x56b63
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x3dbad
movq %r12, %rdi
callq 0x39194
movq %r15, %rdi
callq 0x39194
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3dbad
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x3dbad
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq