#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ floor(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
double find_percentile(double *array, int num, double perc) {
  int index;
  if ((array != NULL) != 1) {
    fprintf(
        stderr, "assertion fails in file %s, line %d\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Starlink/match/refs/heads/master/atpmatch.c",
        3907);
    exit(1);
  };
  if ((num > 0) != 1) {
    fprintf(
        stderr, "assertion fails in file %s, line %d\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Starlink/match/refs/heads/master/atpmatch.c",
        3908);
    exit(1);
  };
  if (((perc > 0.0) && (perc <= 1.0)) != 1) {
    fprintf(
        stderr, "assertion fails in file %s, line %d\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Starlink/match/refs/heads/master/atpmatch.c",
        3909);
    exit(1);
  };
  index = (int)floor(num * perc + 0.5);
  if (index >= num) {
    index = num - 1;
  }
  return (array[index]);
}


x86 assembly (clang, -O0):
<find_percentile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x1,%eax
je     1185 <find_percentile+0x55>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
lea    0xec4(%rip),%rdx
mov    $0xf43,%ecx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x1,%eax
je     11c5 <find_percentile+0x95>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
lea    0xe84(%rip),%rdx
mov    $0xf44,%ecx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x1d(%rbp)
jbe    11ef <find_percentile+0xbf>
movsd  0xe1c(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
setae  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x1,%eax
je     122b <find_percentile+0xfb>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
lea    0xe1e(%rip),%rdx
mov    $0xf45,%ecx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdc7(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1266 <find_percentile+0x136>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_percentile>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1193 <find_percentile+0x63>
mov    %esi,%ebx
test   %esi,%esi
jle    11b1 <find_percentile+0x81>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11cf <find_percentile+0x9f>
movsd  0xeab(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     11cf <find_percentile+0x9f>
mov    %rdi,%r14
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe97(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1050 <floor@plt>
lea    -0x1(%rbx),%ecx
cmp    %ebx,%eax
cmovl  %eax,%ecx
movslq %ecx,%rax
movsd  (%r14,%rax,8),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
lea    0xe8b(%rip),%rdx
mov    $0xf43,%ecx
jmp    11eb <find_percentile+0xbb>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
lea    0xe6d(%rip),%rdx
mov    $0xf44,%ecx
jmp    11eb <find_percentile+0xbb>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
lea    0xe4f(%rip),%rdx
mov    $0xf45,%ecx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"assertion fails in file %s, line %d\0A\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Starlink/match/refs/heads/master/atpmatch.c\00"
define double @find_percentile(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%8 = load double*, double** %4
%9 = icmp ne double* %8, null
%10 = zext i1 %9 to i32
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 3907)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
%19 = zext i1 %18 to i32
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 3908)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = load double, double* %6
%27 = fcmp ogt double %26, 0.000000e+00
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load double, double* %6
%30 = fcmp ole double %29, 1.000000e+00
br label %31
31: ; preds = %28, %25
%32 = phi i1 [ false, %25 ], [ %30, %28 ]
%33 = zext i1 %32 to i32
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 3909)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i32, i32* %5
%41 = sitofp i32 %40 to double
%42 = load double, double* %6
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double 5.000000e-01)
%44 = fptosi double %43 to i32
%45 = call i64 @floor(i32 %44)
%46 = trunc i64 %45 to i32
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = load i32, i32* %5
%49 = icmp sge i32 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %39
%51 = load i32, i32* %5
%52 = sub nsw i32 %51, 1
store i32 %52, i32* %7
br label %53
53: ; preds = %50, %39
%54 = load double*, double** %4
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
ret double %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"assertion fails in file %s, line %d\0A\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Starlink/match/refs/heads/master/atpmatch.c\00"
define double @find_percentile(double* %0, i32 %1, double %2) {
%4 = icmp eq double* %0, null
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 3907)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %3
%10 = icmp sgt i32 %1, 0
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 3908)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = fcmp ogt double %2, 0.000000e+00
%17 = fcmp ole double %2, 1.000000e+00
%18 = and i1 %16, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 3909)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = sitofp i32 %1 to double
%25 = tail call double @llvm.fmuladd.f64(double %24, double %2, double 5.000000e-01)
%26 = fptosi double %25 to i32
%27 = tail call i64 @floor(i32 %26)
%28 = trunc i64 %27 to i32
%29 = icmp slt i32 %28, %1
%30 = add nsw i32 %1, -1
%31 = select i1 %29, i32 %28, i32 %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
ret double %34
}