// File: /workspace/github_c_makefile_star2_O3/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 0x52a74(%rip), %rdi     # 0xaa7b5
callq 0x54bec
testl %eax, %eax
jne 0x57d51
xorl %eax, %eax
callq 0x2e342
movq %rbx, %rdi
callq 0x38b30
movq %rax, %r14
leaq 0x35a355(%rip), %rax    # 0x3b20b8
movslq 0xec(%rax), %r12
leal 0x41(%r12), %eax
movsbl %al, %edi
movq %r14, %rsi
callq 0x2cbc4
movq %r14, %rdi
callq 0x3a180
leaq 0x7d2d7(%rip), %rax     # 0xd5060
movb (%r12,%rax), %al
movb %al, 0xe(%rsp)
movb $0x0, 0xf(%rsp)
leaq 0x53bbe(%rip), %rsi     # 0xab95b
movq %rbx, %rdi
callq 0x40f0
testq %rax, %rax
je 0x580bd
movq %rax, %rbp
movl %r15d, 0x54(%rsp)
leaq 0x52f7b(%rip), %rsi     # 0xaad38
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 0x57eb3
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 0x3a0b4
movq %rax, %r12
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax,%rbx,8)
movq %r15, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x3a0b4
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 0x2e0c5
movsd 0x40(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x2e0ed
movl $0x1, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x20(%rsp), %xmm4
leaq 0xe(%rsp), %rsi
callq 0x2cc6c
movq %rbp, %rdi
leaq 0x52ea5(%rip), %rsi     # 0xaad38
leaq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %rcx
xorl %eax, %eax
callq 0x4070
addq $0x8, %r13
cmpl $-0x1, %eax
jne 0x57dfc
jmp 0x57eb9
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rbp, %rdi
callq 0x42a0
movl %r14d, %edi
movl $0x2, %esi
callq 0x3d79d
movq %rax, %rbx
movq %rdx, %r13
movl $0x1, %edi
movl $0x2, %esi
callq 0x3d79d
movq %rax, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movl %r14d, %ebp
testl %r14d, %r14d
je 0x57f19
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 0x57ef7
leaq 0x60(%rsp), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x40397
movq %rax, 0x38(%rsp)
movq %rdx, 0x20(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3ed51
movq 0x28(%rsp), %rax
movq (%rax), %rax
leaq 0x60(%rsp), %rcx
movq (%rcx), %rdi
movupd (%rdi), %xmm0
movupd %xmm0, (%rax)
callq 0x3a180
movl $0x1, %edi
movl $0x2, %esi
callq 0x3d79d
movq %rax, 0x30(%rsp)
movq %rdx, %r13
testl %r14d, %r14d
je 0x58005
movsd 0x4d58d(%rip), %xmm1    # 0xa5510
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 0x4088c
ucomisd 0x4ddd8(%rip), %xmm0    # 0xa5da8
jne 0x57fd8
jnp 0x58084
ucomisd 0x4dd28(%rip), %xmm0    # 0xa5d08
jb 0x57fe8
sqrtsd %xmm0, %xmm0
jmp 0x57fed
callq 0x4300
movsd 0x10(%rsp), %xmm1
maxsd %xmm1, %xmm0
incq %rbx
movapd %xmm0, %xmm1
cmpq %rbx, %rbp
jne 0x57f8a
jmp 0x58012
movsd 0x4d503(%rip), %xmm0    # 0xa5510
movq 0x28(%rsp), %r14
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x3ed51
movq %r12, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
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 0x5769e
movq %r12, %rdi
movq %r15, %rsi
callq 0x3ed51
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ed51
xorl %eax, %eax
callq 0x2e6d0
jmp 0x580bd
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x3ed51
movq %r12, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3ed51
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x3ed51
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq