// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/plot.c
// Function: histogram_plot
void histogram_plot(char* filename, int bincount)
{
 /*!Last Changed 11.10.2010*/
 Point p1, p2;
 char st[MAXLENGTH], pst[READLINELENGTH];
 double prev, max = -INT_MAX, min = +INT_MAX, obs, binwidth, *observations, *distinct_observations = NULL;
 FILE* myfile;
 int i, j, bin, *counts, filesize = file_length(filename), distinctcount;
 observations = safemalloc(filesize * sizeof(double), "histogram_plot", 20);
 if (!get_parameter_o("hold"))
   clear_image();
 myfile = fopen(filename, "r");
 if (!myfile)
  {
   printf(m1274, filename);
   return;
  }
 i = 0;
 while (fscanf(myfile, "%lf\n", &obs) != EOF)
  {
   if (obs > max)
     max = obs;
   if (obs < min)
     min = obs;
   observations[i] = obs;
   i++;
  }
 fclose(myfile);
 if (bincount == 0)
  {
   qsort(observations, filesize, sizeof(double), sort_function_double_ascending);
   distinctcount = 1;
   prev = observations[0];
   for (i = 1; i < filesize; i++)
     if (observations[i] != prev)
      {
       prev = observations[i];
       distinctcount++;
      }
   distinct_observations = safemalloc(distinctcount * sizeof(double), "histogram_plot", 35);
   counts = safecalloc(distinctcount, sizeof(int), "histogram_plot", 36);
   distinct_observations[0] = observations[0];
   prev = observations[0];
   counts[0] = 1;
   j = 0;
   for (i = 1; i < filesize; i++)
     if (observations[i] != prev)
      {
       j++;
       distinct_observations[j] = observations[i];
       prev = observations[i];
       counts[j] = 1;
      }
     else
       counts[j]++;
  }
 else
  {
   counts = safecalloc(bincount, sizeof(int), "histogram_plot", 3);
   binwidth = (max - min) / bincount;
   for (i = 0; i < filesize; i++)
    {
     bin = (int)((observations[i] - min) / binwidth);
     if (bin == bincount)
       bin--;
      counts[bin]++;
    }
  }
 img.xaxis.limitsset = 1;
 if (bincount != 0)
   img.xaxis.namesavailable = bincount;
 else 
   img.xaxis.namesavailable = distinctcount;
 img.xaxis.lim.division = img.xaxis.namesavailable;
 img.xaxis.lim.min = 0;
 img.xaxis.lim.max = img.xaxis.namesavailable;
 img.xaxis.lim.precision = 0;
 if (bincount != 0)
   img.xaxis.names = safemalloc(bincount * sizeof(char*), "histogram_plot", 24); 
 else 
   img.xaxis.names = safemalloc(distinctcount * sizeof(char*), "histogram_plot", 24); 
 img.yaxis.limitsset = 1;
 img.yaxis.lim.division = 10;
 img.yaxis.lim.min = 0;
 if (bincount != 0)
   img.yaxis.lim.max = counts[find_max_in_list(counts, bincount)];
 else
   img.yaxis.lim.max = counts[find_max_in_list(counts, distinctcount)];  
 img.yaxis.namesavailable = 0;
 img.yaxis.lim.precision = 0;
 if (bincount != 0)
  {
   for (i = 0; i < bincount; i++)
    {
     set_precision(pst, NULL, NULL);
     sprintf(st, pst, min + binwidth * i);  
     img.xaxis.names[i] = strcopy(img.xaxis.names[i], st);
     p1.x = i;
     p1.y = MARGIN;
     p2.x = 0;
     p2.y = counts[i];
     add_object(OBJECT_RECTANGLE, p1, p2, dummyp, "");
    }
  }
 else 
  {
   for (i = 0; i < distinctcount; i++)
    {
     set_precision(pst, NULL, NULL);
     sprintf(st, pst, distinct_observations[i]);  
     img.xaxis.names[i] = strcopy(img.xaxis.names[i], st);
     p1.x = i;
     p1.y = MARGIN;
     p2.x = 0;
     p2.y = counts[i];
     add_object(OBJECT_RECTANGLE, p1, p2, dummyp, "");
    }
   safe_free(distinct_observations);
  }
 safe_free(observations);
 safe_free(counts);
 export_image();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf4278, %rsp          # imm = 0xF4278
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
callq 0x33f62
movl %eax, %ebp
movslq %eax, %r13
leaq (,%r13,8), %rdi
leaq 0x4a066(%rip), %rsi     # 0x9ac14
pushq $0x14
popq %rdx
callq 0x34f59
movq %rax, %rbx
leaq 0x49b25(%rip), %rdi     # 0x9a6e5
callq 0x4cff1
testl %eax, %eax
jne 0x50bd0
xorl %eax, %eax
callq 0x2a510
leaq 0x4aca8(%rip), %rsi     # 0x9b87f
movq %r14, %rdi
callq 0x40f0
testq %rax, %rax
je 0x50cf0
movq %rax, %r15
movsd 0x44925(%rip), %xmm0    # 0x95518
movsd %xmm0, 0x8(%rsp)
movsd 0x4490f(%rip), %xmm0    # 0x95510
movsd %xmm0, (%rsp)
leaq 0x4a05f(%rip), %r14     # 0x9ac6c
leaq 0x28(%rsp), %r12
movq %rbx, 0x20(%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x4070
cmpl $-0x1, %eax
je 0x50c56
movsd 0x28(%rsp), %xmm0
movapd %xmm0, %xmm1
maxsd (%rsp), %xmm1
movsd %xmm0, (%rbx)
minsd 0x8(%rsp), %xmm0
addq $0x8, %rbx
movsd %xmm1, (%rsp)
movsd %xmm0, 0x8(%rsp)
jmp 0x50c17
movq %r15, %rdi
callq 0x42a0
cmpl $0x0, 0x10(%rsp)
je 0x50d12
movslq 0x10(%rsp), %rdi
leaq 0x49f9f(%rip), %rdx     # 0x9ac14
pushq $0x4
popq %rsi
pushq $0x3
popq %rcx
callq 0x35067
movq 0x10(%rsp), %rdi
movq %rax, %r15
movsd (%rsp), %xmm2
subsd 0x8(%rsp), %xmm2
cvtsi2sd %edi, %xmm0
divsd %xmm0, %xmm2
xorl %r12d, %r12d
testl %ebp, %ebp
cmovlel %r12d, %ebp
xorl %eax, %eax
movq 0x20(%rsp), %rsi
cmpq %rax, %rbp
je 0x50cd8
movsd (%rsi,%rax,8), %xmm1
subsd 0x8(%rsp), %xmm1
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
xorl %edx, %edx
cmpl %edi, %ecx
sete %dl
subl %edx, %ecx
movslq %ecx, %rcx
incl (%r15,%rcx,4)
incq %rax
jmp 0x50cab
movsd %xmm2, (%rsp)
movl %edi, %ebp
movq $0x0, 0x18(%rsp)
movq %rdi, %r13
jmp 0x50df8
leaq 0x45513(%rip), %rdi     # 0x9620a
movq %r14, %rsi
xorl %eax, %eax
addq $0xf4278, %rsp          # imm = 0xF4278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4030
leaq -0x1b95a(%rip), %rcx    # 0x353bf
pushq $0x8
popq %rdx
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4240
movsd (%rbx), %xmm0
pushq $0x1
popq %rbp
pushq $0x1
popq %rax
cmpq %r13, %rax
jge 0x50d69
movsd (%rbx,%rax,8), %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm1
jne 0x50d54
movapd %xmm2, %xmm1
jp 0x50d54
movapd %xmm0, %xmm1
cmpneqsd %xmm2, %xmm0
movq %xmm0, %rcx
subl %ecx, %ebp
incq %rax
movapd %xmm1, %xmm0
jmp 0x50d36
movl %ebp, %r15d
leaq (,%r15,8), %rdi
leaq 0x49e99(%rip), %r14     # 0x9ac14
pushq $0x23
popq %rdx
movq %r14, %rsi
callq 0x34f59
movq %rax, %r12
pushq $0x4
popq %rsi
pushq $0x24
popq %rcx
movq %r15, 0x18(%rsp)
movq %r15, %rdi
movq %r14, %rdx
callq 0x35067
movq %rax, %r15
movsd (%rbx), %xmm0
movsd %xmm0, (%r12)
movl $0x1, (%rax)
xorl %ecx, %ecx
pushq $0x1
popq %rax
cmpq %r13, %rax
jge 0x50def
movsd (%rbx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
movslq %ecx, %rdx
jne 0x50dcc
jnp 0x50de6
leal 0x1(%rdx), %ecx
movsd %xmm1, 0x8(%r12,%rdx,8)
movsd (%rbx,%rax,8), %xmm0
movl $0x1, 0x4(%r15,%rdx,4)
jmp 0x50dea
incl (%r15,%rdx,4)
incq %rax
jmp 0x50db7
cvtsi2sd %ebp, %xmm0
movq 0x10(%rsp), %r13
leaq 0x3592b9(%rip), %rbx    # 0x3aa0b8
movl %ebp, 0x38(%rbx)
movl %ebp, 0x20(%rbx)
andq $0x0, 0x10(%rbx)
movsd %xmm0, 0x18(%rbx)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x24(%rbx)
movslq %ebp, %r14
leaq (,%r14,8), %rdi
leaq 0x49de5(%rip), %rsi     # 0x9ac14
pushq $0x18
popq %rdx
callq 0x34f59
movq %rax, 0x30(%rbx)
movl $0x1, 0x98(%rbx)
movl $0xa, 0x90(%rbx)
andq $0x0, 0x80(%rbx)
movq %r15, %rdi
movl %r14d, %esi
callq 0x336b5
cltq
cvtsi2sdl (%r15,%rax,4), %xmm0
andl $0x0, 0xa8(%rbx)
andl $0x0, 0x94(%rbx)
movsd %xmm0, 0x88(%rbx)
testl %r13d, %r13d
je 0x50f34
movq %r13, %r14
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
leaq 0x30(%rsp), %r12
leaq 0x7a150(%rsp), %r13
cmpq %rbp, %r14
je 0x50fc3
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x35305
cvtsi2sd %ebp, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
movq %r13, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x41b0
movq 0x30(%rbx), %rax
movq (%rax,%rbp,8), %rdi
movq %r13, %rsi
callq 0x3604c
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
cvtsi2sdl (%r15,%rbp,4), %xmm3
movsd 0x7c16d(%rip), %xmm4    # 0xcd070
movsd 0x7c16d(%rip), %xmm5    # 0xcd078
xorpd %xmm2, %xmm2
pushq $0x2
popq %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x46e68(%rip), %xmm1    # 0x97d88
leaq 0x509f7(%rip), %rsi     # 0xa191e
callq 0x28f8d
incq %rbp
jmp 0x50ea2
xorl %ebp, %ebp
leaq 0x30(%rsp), %r14
leaq 0x7a150(%rsp), %r13
cmpq %rbp, 0x18(%rsp)
je 0x50fbb
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x35305
movsd (%r12,%rbp,8), %xmm0
movq %r13, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x41b0
movq 0x30(%rbx), %rax
movq (%rax,%rbp,8), %rdi
movq %r13, %rsi
callq 0x3604c
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
cvtsi2sd %ebp, %xmm0
cvtsi2sdl (%r15,%rbp,4), %xmm3
movsd 0x7c0dd(%rip), %xmm4    # 0xcd070
movsd 0x7c0dd(%rip), %xmm5    # 0xcd078
xorpd %xmm2, %xmm2
pushq $0x2
popq %rdi
movsd 0x46dde(%rip), %xmm1    # 0x97d88
leaq 0x5096d(%rip), %rsi     # 0xa191e
callq 0x28f8d
incq %rbp
jmp 0x50f43
movq %r12, %rdi
callq 0x34ff7
movq 0x20(%rsp), %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
xorl %eax, %eax
callq 0x2a858
addq $0xf4278, %rsp          # imm = 0xF4278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq