// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x4a678(%rip), %rdi     # 0x9a6e5
callq 0x4cff1
testl %eax, %eax
jne 0x5007d
xorl %eax, %eax
callq 0x2a510
movq %rbx, %rdi
callq 0x34033
movq %rax, %r14
leaq 0x35a029(%rip), %rax    # 0x3aa0b8
movslq 0xec(%rax), %r12
leal 0x41(%r12), %eax
movsbl %al, %edi
movq %r14, %rsi
callq 0x28ee8
movq %r14, %rdi
callq 0x34ff7
leaq 0x7cfab(%rip), %rax     # 0xcd060
movb (%r12,%rax), %al
movb %al, 0x6(%rsp)
movb $0x0, 0x7(%rsp)
leaq 0x4b7b6(%rip), %rsi     # 0x9b87f
movq %rbx, %rdi
callq 0x40f0
testq %rax, %rax
je 0x5038a
movq %rax, %rbp
movl %r15d, 0x34(%rsp)
movq %r12, 0x48(%rsp)
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x18(%rsp)
pushq $0x8
popq %r14
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rbp, %rdi
leaq 0x4ab60(%rip), %rsi     # 0x9ac68
leaq 0x40(%rsp), %rdx
leaq 0x38(%rsp), %rcx
xorl %eax, %eax
callq 0x4070
cmpl $-0x1, %eax
je 0x501b7
leaq 0x1(%rbx), %r13
movq %r12, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x34f30
movq %rax, %r12
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rax,%rbx,8)
movq %r15, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x34f30
movq %rax, %r15
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax,%rbx,8)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm1
callq 0x2a296
movsd 0x38(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x2a2be
pushq $0x1
popq %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm4
leaq 0x6(%rsp), %rsi
callq 0x28f8d
addq $0x8, %r14
movq %r13, %rbx
jmp 0x500fe
movq %rbp, %rdi
callq 0x42a0
pushq $0x2
popq %r13
movl %ebx, %edi
movl %r13d, %esi
callq 0x380d3
movq %rax, %r14
movq %rdx, %rbp
pushq $0x1
popq %rdi
movl %r13d, %esi
callq 0x380d3
movq %rax, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
xorl %eax, %eax
cmpq %rax, %rbx
je 0x5020e
movsd (%r12,%rax,8), %xmm0
movq (%rbp,%rax,8), %rcx
movsd %xmm0, (%rcx)
movsd (%r15,%rax,8), %xmm0
movsd %xmm0, 0x8(%rcx)
incq %rax
jmp 0x501ea
leaq 0x50(%rsp), %r13
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x3a4c9
movq %rax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3929f
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%r13), %rdi
movups (%rdi), %xmm0
movups %xmm0, (%rax)
callq 0x34ff7
pushq $0x1
popq %rdi
pushq $0x2
popq %rsi
callq 0x380d3
movq %rax, %r14
movq %rdx, %rbp
movsd 0x452aa(%rip), %xmm0    # 0x95510
movsd %xmm0, 0x10(%rsp)
xorl %r13d, %r13d
cmpq %r13, %rbx
je 0x502e2
movsd (%r12,%r13,8), %xmm0
movq (%rbp), %rax
movsd %xmm0, (%rax)
movsd (%r15,%r13,8), %xmm0
movsd %xmm0, 0x8(%rax)
movq %r14, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq 0x20(%rsp), %r8
movq 0x28(%rsp), %r9
callq 0x3a8ff
ucomisd 0x45afc(%rip), %xmm0    # 0x95db0
jne 0x502bc
jnp 0x50351
ucomisd 0x45a54(%rip), %xmm0    # 0x95d18
jb 0x502cc
sqrtsd %xmm0, %xmm0
jmp 0x502d1
callq 0x4300
maxsd 0x10(%rsp), %xmm0
incq %r13
movsd %xmm0, 0x10(%rsp)
jmp 0x5026f
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3929f
movq %r12, %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
movq 0x18(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq 0x20(%rsp), %r12
movq %r12, %rdx
movq 0x28(%rsp), %r15
movq %r15, %rcx
movl 0x34(%rsp), %r8d
movq 0x48(%rsp), %r9
movsd 0x10(%rsp), %xmm0
callq 0x4f99f
movq %r12, %rdi
movq %r15, %rsi
callq 0x3929f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3929f
xorl %eax, %eax
callq 0x2a858
jmp 0x5038a
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3929f
movq %r12, %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x3929f
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3929f
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq