// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/plot.c
// Function: error_histogram_plot
void error_histogram_plot(char** names, int filecount)
{
 /*!Last Changed 27.12.2007*/
 int i, j, index, counts[10], count;
 Point p1, p2, p3;
 char* plotname, st2[11];
 char* pos;
 double obs, min = +INT_MAX, max = -INT_MAX;
 FILE* myfile;
 if (!get_parameter_o("hold"))
   clear_image();
 for (i = 0; i < filecount; i++)
  {
   myfile = fopen(names[i], "r");
   if (!myfile)
    {
     printf(m1274, names[i]);
     return;
    }
   while (fscanf(myfile, "%lf\n", &obs) != EOF)
    {
     if (obs > max)
       max = obs;
     if (obs < min)
       min = obs;
    }
   fclose(myfile);
  } 
 for (i = 0; i < filecount; i++)
  {
   p1.x = min;
   p1.y = max;
   p2.x = img.yaxis.namesavailable;
   p2.y = i;
   myfile = fopen(names[i], "r");
   for (j = 0; j < 10; j++)
     counts[j] = 0;
   if (!myfile)
    {
     printf(m1274, names[i]);
     return;
    }
   count = 0;
   while (fscanf(myfile, "%lf\n", &obs) != EOF)
    {
     if (max != min)
      {
       index = (int) (10 * (obs - min) / (max - min));
       if (index == 10)
         index--;
      }
     else
       index = 5;
     counts[index]++;
     count++;
    }
   fclose(myfile);
   for (j = 0; j < 10; j++)
     st2[j] = '0' + (30 * counts[j]) / count;
   st2[10] = '\0';
   add_object(OBJECT_ERRORHISTOGRAM, p1, p2, p3, st2);
   if (img.yaxis.namesavailable == 0)
    {
     plotname = file_only_name(names[i]);     
     pos = strchr(plotname, '-');
     img.xaxis.names = alloc(img.xaxis.names, (i + 1) * sizeof(char *), (i + 1)); 
     if (pos)
       img.xaxis.names[i] = strcopy(img.xaxis.names[i], (pos + 1));
     else
       img.xaxis.names[i] = strcopy(img.xaxis.names[i], "Try Again");
     safe_free(plotname);
    }   
  }
 img.yaxis.names = alloc(img.yaxis.names, (img.yaxis.namesavailable + 1) * sizeof(char *), (img.yaxis.namesavailable + 1));
 plotname = file_only_name(names[0]);
 img.yaxis.names[img.yaxis.namesavailable] = strcopy(img.yaxis.names[img.yaxis.namesavailable], plotname);
 safe_free(plotname);
 img.xaxis.namesavailable = filecount;
 img.yaxis.namesavailable++;
 img.xaxis.limitsset = 1;
 img.xaxis.lim.division = img.xaxis.namesavailable;
 img.xaxis.lim.min = 0;
 img.xaxis.lim.max = img.xaxis.namesavailable;
 img.xaxis.lim.precision = 0;
 img.yaxis.limitsset = 1;
 img.yaxis.lim.division = img.yaxis.namesavailable;
 img.yaxis.lim.min = 0;
 img.yaxis.lim.max = 10 * img.yaxis.namesavailable;
 export_image();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %esi, %ebx
movq %rdi, %rbp
leaq 0x496da(%rip), %rdi     # 0x9a6e5
callq 0x4cff1
testl %eax, %eax
jne 0x5101b
xorl %eax, %eax
callq 0x2a510
testl %ebx, %ebx
movl $0x0, %eax
movl %ebx, 0x44(%rsp)
cmovgl %ebx, %eax
movq %rax, 0x48(%rsp)
movsd 0x444da(%rip), %xmm0    # 0x95510
movsd %xmm0, 0x10(%rsp)
movsd 0x444d4(%rip), %xmm0    # 0x95518
movsd %xmm0, 0x8(%rsp)
leaq 0x4a82e(%rip), %rbx     # 0x9b87f
leaq 0x49c14(%rip), %r15     # 0x9ac6c
leaq 0x38(%rsp), %r12
xorl %r14d, %r14d
cmpq 0x48(%rsp), %r14
je 0x510c5
movq (%rbp,%r14,8), %rdi
movq %rbx, %rsi
callq 0x40f0
movq %rax, %r13
testq %rax, %rax
jne 0x510a3
jmp 0x512a3
movsd 0x38(%rsp), %xmm0
movapd %xmm0, %xmm1
maxsd 0x10(%rsp), %xmm1
minsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x4070
cmpl $-0x1, %eax
jne 0x51081
movq %r13, %rdi
callq 0x42a0
incq %r14
jmp 0x51060
movsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x358fda(%rip), %rbx    # 0x3aa0b8
leaq 0x49b87(%rip), %r12     # 0x9ac6c
leaq 0x38(%rsp), %r13
pushq $0x5
popq %r14
pushq $0x9
popq %r15
xorl %eax, %eax
movq %rbp, 0x20(%rsp)
cmpq 0x48(%rsp), %rax
je 0x512ad
cvtsi2sdl 0xa8(%rbx), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rax, 0x18(%rsp)
movq (%rbp,%rax,8), %rdi
leaq 0x4a75c(%rip), %rsi     # 0x9b87f
callq 0x40f0
movq %rax, %rbp
xorl %eax, %eax
cmpq $0xa, %rax
je 0x5113d
andl $0x0, 0x70(%rsp,%rax,4)
incq %rax
jmp 0x5112d
testq %rbp, %rbp
je 0x51381
cvtsi2sdl 0x18(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebx, %ebx
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x4070
cmpl $-0x1, %eax
je 0x511af
movsd 0x10(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
movq %r14, %rax
jne 0x5117c
jnp 0x511a7
movsd 0x38(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
mulsd 0x46ba8(%rip), %xmm0    # 0x97d38
divsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %r15d, %ecx
cmpl $0xa, %eax
je 0x511a4
movl %eax, %ecx
movslq %ecx, %rax
incl 0x70(%rsp,%rax,4)
incl %ebx
jmp 0x51154
movq %rbp, %rdi
callq 0x42a0
xorl %ecx, %ecx
movq 0x20(%rsp), %rbp
cmpq $0xa, %rcx
je 0x511d7
imull $0x1e, 0x70(%rsp,%rcx,4), %eax
cltd
idivl %ebx
addb $0x30, %al
movb %al, 0x55(%rsp,%rcx)
incq %rcx
jmp 0x511be
movb $0x0, 0x5f(%rsp)
pushq $0x5
popq %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
leaq 0x55(%rsp), %rsi
callq 0x28f8d
leaq 0x358eb0(%rip), %rbx    # 0x3aa0b8
cmpl $0x0, 0xa8(%rbx)
je 0x5121e
movq 0x18(%rsp), %rax
incq %rax
jmp 0x510f9
movq %rbp, %rax
movq 0x18(%rsp), %rbp
movq (%rax,%rbp,8), %rdi
callq 0x34033
movq %rax, 0x30(%rsp)
movq %rax, %rdi
pushq $0x2d
popq %rsi
callq 0x4220
movq %rax, 0x60(%rsp)
movq 0x30(%rbx), %rdi
leaq 0x1(%rbp), %rdx
movq %rdx, 0x28(%rsp)
leaq 0x8(,%rbp,8), %rsi
callq 0x34f30
movq %rax, 0x30(%rbx)
movq 0x60(%rsp), %rcx
leaq 0x1(%rcx), %rsi
testq %rcx, %rcx
movq (%rax,%rbp,8), %rdi
leaq 0x499aa(%rip), %rax     # 0x9ac23
cmoveq %rax, %rsi
callq 0x3604c
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
movq 0x20(%rsp), %rbp
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq 0x28(%rsp), %rax
jmp 0x510f9
movq (%rbp,%r14,8), %rsi
jmp 0x5138f
movq 0xa0(%rbx), %rdi
movslq 0xa8(%rbx), %rdx
leaq 0x8(,%rdx,8), %rsi
incq %rdx
callq 0x34f30
movq %rax, 0xa0(%rbx)
movq (%rbp), %rdi
callq 0x34033
movq %rbx, %r14
movq %rax, %rbx
movq 0xa0(%r14), %rax
movslq 0xa8(%r14), %rcx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x3604c
movq 0xa0(%r14), %rcx
movslq 0xa8(%r14), %rdx
movq %rax, (%rcx,%rdx,8)
movq %rbx, %rdi
callq 0x34ff7
movl 0x44(%rsp), %ecx
movl %ecx, 0x38(%r14)
movl 0xa8(%r14), %eax
incl %eax
movl %eax, 0xa8(%r14)
movl %ecx, 0x20(%r14)
andq $0x0, 0x10(%r14)
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x18(%r14)
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %rcx, 0x24(%r14)
movl $0x1, 0x98(%r14)
movl %eax, 0x90(%r14)
andq $0x0, 0x80(%r14)
imull $0xa, %eax, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x88(%r14)
xorl %eax, %eax
callq 0x2a858
jmp 0x5139d
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x44e74(%rip), %rdi     # 0x9620a
xorl %eax, %eax
callq 0x4030
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq