// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq %rdi, %r12
callq 0x38a4a
movl %eax, %ebx
movslq %eax, %r15
leaq (,%r15,8), %rdi
leaq 0x523e8(%rip), %rsi     # 0xaace4
movl $0x14, %edx
callq 0x3a0e1
movq %rax, %rbp
leaq 0x51ea5(%rip), %rdi     # 0xaa7b5
callq 0x54bec
testl %eax, %eax
jne 0x58920
xorl %eax, %eax
callq 0x2e342
leaq 0x53034(%rip), %rsi     # 0xab95b
movq %r12, %rdi
callq 0x40f0
testq %rax, %rax
je 0x589cc
movq %rax, %r14
movl %ebx, 0xc(%rsp)
leaq 0x523f6(%rip), %rsi     # 0xaad3c
leaq 0x28(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x4070
cmpl $-0x1, %eax
je 0x589ee
movsd 0x4cbaa(%rip), %xmm1    # 0xa5510
movsd 0x4cbaa(%rip), %xmm0    # 0xa5518
leaq 0x523c7(%rip), %r12     # 0xaad3c
leaq 0x28(%rsp), %r13
movq %rbp, %rbx
movsd 0x28(%rsp), %xmm2
movapd %xmm2, %xmm3
maxsd %xmm1, %xmm3
movsd %xmm3, (%rsp)
movsd %xmm2, (%rbx)
minsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x4070
movsd 0x10(%rsp), %xmm3
movsd (%rsp), %xmm2
addq $0x8, %rbx
movapd %xmm3, %xmm0
movapd %xmm2, %xmm1
cmpl $-0x1, %eax
jne 0x5897d
jmp 0x589fe
leaq 0x4d837(%rip), %rdi     # 0xa620a
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 0x4cb22(%rip), %xmm3    # 0xa5518
movsd 0x4cb12(%rip), %xmm2    # 0xa5510
movsd %xmm2, (%rsp)
movsd %xmm3, 0x10(%rsp)
movq %r14, %rdi
callq 0x42a0
movl 0x18(%rsp), %r12d
movslq %r12d, %rbx
testl %r12d, %r12d
movq %rbp, 0x20(%rsp)
je 0x58a98
leaq 0x522ba(%rip), %rdx     # 0xaace4
movl $0x4, %esi
movq %rbx, %rdi
movl $0x3, %ecx
callq 0x3a1fc
movq %rax, %r14
movsd 0x10(%rsp), %xmm1
movsd (%rsp), %xmm2
subsd %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
divsd %xmm0, %xmm2
cmpl $0x0, 0xc(%rsp)
jle 0x58b97
xorl %esi, %esi
xorl %eax, %eax
movsd (%rbp,%rax,8), %xmm0
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
cvttsd2si %xmm0, %ecx
xorl %edx, %edx
cmpl %r12d, %ecx
sete %dl
subl %edx, %ecx
movslq %ecx, %rcx
incl (%r14,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0x58a68
jmp 0x58b99
leaq -0x1e4ac(%rip), %rcx    # 0x3a5f3
movl $0x8, %edx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x4240
movl $0x1, %r13d
cmpl $0x2, 0xc(%rsp)
jl 0x58af9
movsd (%rbp), %xmm0
movl $0x1, %eax
movsd (%rbp,%rax,8), %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm1
jne 0x58ae0
movapd %xmm2, %xmm1
jp 0x58ae0
movapd %xmm0, %xmm1
cmpneqsd %xmm2, %xmm0
movq %xmm0, %rcx
subl %ecx, %r13d
incq %rax
movapd %xmm1, %xmm0
cmpq %rax, %r15
jne 0x58ac6
movq %rbx, (%rsp)
movslq %r13d, %r14
leaq (,%r14,8), %rdi
leaq 0x521d5(%rip), %rbx     # 0xaace4
movq %rbx, %rsi
movl $0x23, %edx
callq 0x3a0e1
movq %rax, %rbp
movl $0x4, %esi
movq %r14, %rdi
movq %rbx, %rdx
movq 0x20(%rsp), %rbx
movl $0x24, %ecx
callq 0x3a1fc
movq %rbp, %rsi
movq %rax, %r14
movsd (%rbx), %xmm0
movsd %xmm0, (%rbp)
movl $0x1, (%rax)
cmpl $0x2, 0xc(%rsp)
jl 0x58b91
xorl %ecx, %ecx
movl $0x1, %eax
movsd (%rbx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
movslq %ecx, %rdx
jne 0x58b6c
jnp 0x58b85
leal 0x1(%rdx), %ecx
movsd %xmm1, 0x8(%rsi,%rdx,8)
movsd (%rbx,%rax,8), %xmm0
movl $0x1, 0x4(%r14,%rdx,4)
jmp 0x58b89
incl (%r14,%rdx,4)
incq %rax
cmpq %rax, %r15
jne 0x58b5c
movq (%rsp), %rbx
jmp 0x58b9c
xorl %esi, %esi
movl %r12d, %r13d
leaq 0x359515(%rip), %rbp    # 0x3b20b8
movl %r13d, 0x38(%rbp)
movl %r13d, 0x20(%rbp)
movq $0x0, 0x10(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x18(%rbp)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x24(%rbp)
testl %r12d, %r12d
je 0x58cfa
shlq $0x3, %rbx
leaq 0x52102(%rip), %rsi     # 0xaace4
movq %rbx, %rdi
movl $0x18, %edx
movsd %xmm2, (%rsp)
callq 0x3a0e1
movq %rax, 0x30(%rbp)
movl $0x1, 0x98(%rbp)
movl $0xa, 0x90(%rbp)
movq $0x0, 0x80(%rbp)
movq %r14, %rdi
movl %r12d, %esi
callq 0x38002
cltq
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%rax,4), %xmm0
movsd %xmm0, 0x88(%rbp)
xorl %eax, %eax
movl %eax, 0xa8(%rbp)
movl %eax, 0x94(%rbp)
testl %r12d, %r12d
jle 0x58e13
movl %r12d, %ebx
xorl %r13d, %r13d
leaq 0x30(%rsp), %r15
leaq 0x7a150(%rsp), %r12
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a535
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd %xmm1, 0x18(%rsp)
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x10(%rsp), %xmm0
movq %r12, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x41b0
movq 0x30(%rbp), %rax
movq (%rax,%r13,8), %rdi
movq %r12, %rsi
callq 0x3b494
movq 0x30(%rbp), %rcx
movq %rax, (%rcx,%r13,8)
xorps %xmm3, %xmm3
cvtsi2sdl (%r14,%r13,4), %xmm3
movsd 0x7c3b2(%rip), %xmm4    # 0xd5070
movsd 0x7c3b2(%rip), %xmm5    # 0xd5078
xorpd %xmm2, %xmm2
movl $0x2, %edi
movsd 0x18(%rsp), %xmm0
movsd 0x4f12b(%rip), %xmm1    # 0xa7e08
leaq 0x58cda(%rip), %rsi     # 0xb19be
callq 0x2cc6c
incq %r13
cmpq %r13, %rbx
jne 0x58c5f
jmp 0x58e13
movslq %r13d, %r15
movq %rsi, (%rsp)
leaq (,%r15,8), %rdi
leaq 0x51fd4(%rip), %rsi     # 0xaace4
movl $0x18, %edx
callq 0x3a0e1
movq %rax, 0x30(%rbp)
movl $0x1, 0x98(%rbp)
movl $0xa, 0x90(%rbp)
movq $0x0, 0x80(%rbp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x38002
cltq
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%rax,4), %xmm0
movsd %xmm0, 0x88(%rbp)
xorl %eax, %eax
movl %eax, 0xa8(%rbp)
movl %eax, 0x94(%rbp)
testl %r15d, %r15d
jle 0x58e0a
movl %r13d, %ebx
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
leaq 0x7a150(%rsp), %r13
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a535
movq (%rsp), %rax
movsd (%rax,%r12,8), %xmm0
movq %r13, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x41b0
movq 0x30(%rbp), %rax
movq (%rax,%r12,8), %rdi
movq %r13, %rsi
callq 0x3b494
movq 0x30(%rbp), %rcx
movq %rax, (%rcx,%r12,8)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
xorps %xmm3, %xmm3
cvtsi2sdl (%r14,%r12,4), %xmm3
movsd 0x7c297(%rip), %xmm4    # 0xd5070
movsd 0x7c297(%rip), %xmm5    # 0xd5078
xorpd %xmm2, %xmm2
movl $0x2, %edi
movsd 0x4f016(%rip), %xmm1    # 0xa7e08
leaq 0x58bc5(%rip), %rsi     # 0xb19be
callq 0x2cc6c
incq %r12
cmpq %r12, %rbx
jne 0x58d85
movq (%rsp), %rdi
callq 0x3a180
movq 0x20(%rsp), %rdi
callq 0x3a180
movq %r14, %rdi
callq 0x3a180
xorl %eax, %eax
callq 0x2e6d0
addq $0xf4278, %rsp          # imm = 0xF4278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq