// File: /workspace/github_c_makefile_star2_O1/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
movl %esi, %ebp
movq %rdi, %r12
callq 0x37e22
movl %eax, %r13d
movslq %eax, %r15
leaq (,%r15,8), %rdi
leaq 0x5086f(%rip), %rsi     # 0xa7c34
movl $0x14, %edx
callq 0x390f5
movq %rax, %rbx
leaq 0x5033c(%rip), %rdi     # 0xa7715
callq 0x536e7
testl %eax, %eax
jne 0x573e9
xorl %eax, %eax
callq 0x2da74
leaq 0x5149f(%rip), %rsi     # 0xa888f
movq %r12, %rdi
callq 0x40f0
testq %rax, %rax
je 0x5749d
movq %rax, %r14
movl %r13d, (%rsp)
movl %ebp, 0x4(%rsp)
leaq 0x50879(%rip), %rsi     # 0xa7c8c
leaq 0x28(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x4070
cmpl $-0x1, %eax
movq %rbx, 0x20(%rsp)
je 0x574bf
movsd 0x4b0d8(%rip), %xmm1    # 0xa2510
movsd 0x4b0d8(%rip), %xmm0    # 0xa2518
leaq 0x50845(%rip), %r12     # 0xa7c8c
leaq 0x28(%rsp), %r13
movsd 0x28(%rsp), %xmm2
movapd %xmm2, %xmm3
maxsd %xmm1, %xmm3
movsd %xmm3, 0x10(%rsp)
movsd %xmm2, (%rbx)
minsd %xmm0, %xmm2
movsd %xmm2, 0x18(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x4070
movsd 0x18(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
addq $0x8, %rbx
movapd %xmm3, %xmm0
movapd %xmm2, %xmm1
cmpl $-0x1, %eax
jne 0x5744c
jmp 0x574cf
leaq 0x4bd66(%rip), %rdi     # 0xa320a
movq %r12, %rsi
xorl %eax, %eax
addq $0xf4278, %rsp          # imm = 0xF4278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4030
movsd 0x4b051(%rip), %xmm3    # 0xa2518
movsd 0x4b041(%rip), %xmm2    # 0xa2510
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x18(%rsp)
movq %r14, %rdi
callq 0x42a0
movl 0x4(%rsp), %r13d
testl %r13d, %r13d
je 0x57577
movslq %r13d, %rdi
leaq 0x50739(%rip), %rdx     # 0xa7c34
movl $0x4, %esi
movl $0x3, %ecx
callq 0x39210
movq %rax, %r14
movsd 0x18(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
subsd %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
divsd %xmm0, %xmm2
cmpl $0x0, (%rsp)
movq 0x20(%rsp), %rsi
movsd %xmm2, 0x10(%rsp)
jle 0x57566
xorl %eax, %eax
movsd (%rsi,%rax,8), %xmm0
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
cvttsd2si %xmm0, %ecx
xorl %edx, %edx
cmpl %r13d, %ecx
sete %dl
subl %edx, %ecx
movslq %ecx, %rcx
incl (%r14,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0x5753c
movq $0x0, 0x8(%rsp)
movl %r13d, %ebp
jmp 0x5767a
leaq -0x1df97(%rip), %rcx    # 0x395e7
movl $0x8, %edx
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4240
movl $0x1, %ebp
cmpl $0x2, (%rsp)
jl 0x575d8
movsd (%rbx), %xmm0
movl $0x1, %eax
movsd (%rbx,%rax,8), %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm1
jne 0x575c0
movapd %xmm2, %xmm1
jp 0x575c0
movapd %xmm0, %xmm1
cmpneqsd %xmm2, %xmm0
movq %xmm0, %rcx
subl %ecx, %ebp
incq %rax
movapd %xmm1, %xmm0
cmpq %rax, %r15
jne 0x575a7
movslq %ebp, %r14
leaq (,%r14,8), %rdi
leaq 0x5064a(%rip), %r13     # 0xa7c34
movq %r13, %rsi
movl $0x23, %edx
callq 0x390f5
movq %rax, %r12
movl $0x4, %esi
movq %r14, %rdi
movq %r13, %rdx
movl $0x24, %ecx
callq 0x39210
movq %rax, %r14
movsd (%rbx), %xmm0
movsd %xmm0, (%r12)
movsd (%rbx), %xmm0
movl $0x1, (%rax)
cmpl $0x2, (%rsp)
movq %r12, 0x8(%rsp)
jl 0x57675
xorl %ecx, %ecx
movl $0x1, %eax
movl 0x4(%rsp), %r13d
movsd (%rbx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
movslq %ecx, %rdx
jne 0x5764d
jnp 0x57667
leal 0x1(%rdx), %ecx
movsd %xmm1, 0x8(%r12,%rdx,8)
movsd (%rbx,%rax,8), %xmm0
movl $0x1, 0x4(%r14,%rdx,4)
jmp 0x5766b
incl (%r14,%rdx,4)
incq %rax
cmpq %rax, %r15
jne 0x5763d
jmp 0x5767a
movl 0x4(%rsp), %r13d
leaq 0x357a37(%rip), %rbx    # 0x3af0b8
movl %ebp, 0x38(%rbx)
movl %ebp, 0x20(%rbx)
xorl %r12d, %r12d
movq %r12, 0x10(%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x18(%rbx)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x24(%rbx)
movslq %ebp, %r15
leaq (,%r15,8), %rdi
leaq 0x5057a(%rip), %rsi     # 0xa7c34
movl $0x18, %edx
callq 0x390f5
movq %rax, 0x30(%rbx)
movl $0x1, 0x98(%rbx)
movl $0xa, 0x90(%rbx)
movq %r12, 0x80(%rbx)
movq %r14, %rdi
movl %r15d, %esi
callq 0x37504
cltq
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%rax,4), %xmm0
movsd %xmm0, 0x88(%rbx)
movl %r12d, 0xa8(%rbx)
movl %r12d, 0x94(%rbx)
testl %r13d, %r13d
je 0x577cd
jle 0x57877
movl %r13d, %ebp
xorl %r13d, %r13d
leaq 0x30(%rsp), %r15
leaq 0x7a150(%rsp), %r12
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x39529
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x18(%rsp), %xmm0
movq %r12, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x41b0
movq 0x30(%rbx), %rax
movq (%rax,%r13,8), %rdi
movq %r12, %rsi
callq 0x3a404
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
xorps %xmm3, %xmm3
cvtsi2sdl (%r14,%r13,4), %xmm3
movsd 0x7a8df(%rip), %xmm4    # 0xd2070
movsd 0x7a8df(%rip), %xmm5    # 0xd2078
xorpd %xmm2, %xmm2
movl $0x2, %edi
movsd 0x8(%rsp), %xmm0
movsd 0x4d5d0(%rip), %xmm1    # 0xa4d80
leaq 0x57177(%rip), %rsi     # 0xae92e
callq 0x2c3cc
incq %r13
cmpq %r13, %rbp
jne 0x57731
jmp 0x57877
testl %ebp, %ebp
jle 0x5786d
movl %ebp, %ebp
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
leaq 0x7a150(%rsp), %r13
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x39529
movq 0x8(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
movq %r13, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x41b0
movq 0x30(%rbx), %rax
movq (%rax,%r12,8), %rdi
movq %r13, %rsi
callq 0x3a404
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
xorps %xmm3, %xmm3
cvtsi2sdl (%r14,%r12,4), %xmm3
movsd 0x7a834(%rip), %xmm4    # 0xd2070
movsd 0x7a834(%rip), %xmm5    # 0xd2078
xorpd %xmm2, %xmm2
movl $0x2, %edi
movsd 0x4d52b(%rip), %xmm1    # 0xa4d80
leaq 0x570d2(%rip), %rsi     # 0xae92e
callq 0x2c3cc
incq %r12
cmpq %r12, %rbp
jne 0x577e7
movq 0x8(%rsp), %rdi
callq 0x39194
movq 0x20(%rsp), %rdi
callq 0x39194
movq %r14, %rdi
callq 0x39194
xorl %eax, %eax
callq 0x2de4a
addq $0xf4278, %rsp          # imm = 0xF4278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq