// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/statistics.c
// Function: file_percentile
double file_percentile(char *file, double percentile)
{
 /*Last Changed 11.07.2005*/
 FILE *myfile;
 double *observations, pos, result, weight;
 int count, i, posi;
 count = file_length(file);
 observations = safemalloc(count * sizeof(double), "file_percentile", 5);
 if ((myfile = fopen(file, "r")) == NULL)
  {
   printf(m1274, file);
   return 0;
  }
 for (i = 0; i < count; i++)
   fscanf(myfile, "%lf", &(observations[i]));
 fclose(myfile); 
 qsort(observations, count, sizeof(double), sort_function_double_ascending);
 pos = (2 * count * percentile) / 100;
 posi = (int) pos;
 if (pos <= 1)
   result = observations[0];
 else
   if (pos >= 2 * count - 1)
     result = observations[count - 1];
   else
     if (pos == posi && posi % 2 == 1)
       result = observations[(posi - 1) / 2];
     else
       if (posi % 2 == 1)
        {
         weight = (pos - posi) / 2;
         result = weight * observations[(posi - 1) / 2] + (1 - weight) * observations[(posi + 1) / 2];
        }
       else
        {
         weight = (pos - posi + 1) / 2;
         result = weight * observations[posi / 2 - 1] + (1 - weight) * observations[posi / 2];
        }
 safe_free(observations);
 return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x50f90
movl %eax, -0x44(%rbp)
movslq -0x44(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x29c58(%rip), %rsi     # 0xede37
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x23fae(%rip), %rsi     # 0xe81a6
callq 0x40c0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0xc4226
movq -0x10(%rbp), %rsi
leaq 0x1ec78(%rip), %rdi     # 0xe2e8a
movb $0x0, %al
callq 0x4030
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0xc4495
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0xc4261
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rdx
movslq -0x48(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x22579(%rip), %rsi     # 0xe67c8
movb $0x0, %al
callq 0x4070
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xc422d
movq -0x20(%rbp), %rdi
callq 0x4250
movq -0x28(%rbp), %rdi
movslq -0x44(%rbp), %rsi
movl $0x8, %edx
leaq -0x70dbe(%rip), %rcx    # 0x534c0
callq 0x41f0
movl -0x44(%rbp), %eax
shll %eax
cvtsi2sd %eax, %xmm0
mulsd -0x18(%rbp), %xmm0
movsd 0x1e7a7(%rip), %xmm1    # 0xe2a40
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
cvttsd2si -0x30(%rbp), %eax
movl %eax, -0x4c(%rbp)
movsd 0x1dd66(%rip), %xmm0    # 0xe2018
ucomisd -0x30(%rbp), %xmm0
jb 0xc42cb
movq -0x28(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0xc4482
movsd -0x30(%rbp), %xmm0
movl -0x44(%rbp), %eax
shll %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jb 0xc42fe
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0xc4480
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x4c(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jne 0xc434e
jp 0xc434e
movl -0x4c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0xc434e
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0xc447e
movl -0x4c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0xc43ed
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x4c(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd 0x1e928(%rip), %xmm1    # 0xe2ca0
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x68(%rbp), %rax
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x1dc66(%rip), %xmm1    # 0xe2018
subsd -0x40(%rbp), %xmm1
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
mulsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0xc447c
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x4c(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd 0x1dc15(%rip), %xmm1    # 0xe2018
addsd %xmm1, %xmm0
movsd 0x1e891(%rip), %xmm1    # 0xe2ca0
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x4c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x78(%rbp), %rax
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x1dbcf(%rip), %xmm1    # 0xe2018
subsd -0x40(%rbp), %xmm1
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x4c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x70(%rbp), %rax
movslq %ecx, %rcx
mulsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0xc447e
jmp 0xc4480
jmp 0xc4482
movq -0x28(%rbp), %rdi
callq 0x52e80
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)