#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 */
double log(int);
double bm25(int dl, int tf, int df, double avgdl, int n_df) {
  double k1 = 1.6;
  double b = 0.75;
  double score;
  score = log((n_df - df + 0.5) / (df + 0.5));
  score *= tf * (k1 + 1);
  score /= (tf + k1 * (1 - b + b * dl / avgdl));
  return score;
}


x86 assembly (clang, -O0):
<bm25>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movsd  0xee7(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xed2(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xeb3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xea2(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
addsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe52(%rip),%xmm2
subsd  -0x30(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
cvtsi2sdl -0x4(%rbp),%xmm4
mulsd  %xmm4,%xmm3
divsd  -0x18(%rbp),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bm25>:
push   %rbp
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %esi,%ebx
mov    %edi,%ebp
sub    %edx,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0xed3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sd %edx,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0xeb3(%rip),%xmm2
mulsd  %xmm1,%xmm2
cvtsi2sd %ebp,%xmm3
mulsd  0xeab(%rip),%xmm3
mulsd  %xmm2,%xmm0
divsd  (%rsp),%xmm3
addsd  0xea2(%rip),%xmm3
mulsd  0xea2(%rip),%xmm3
addsd  %xmm1,%xmm3
divsd  %xmm3,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @bm25(i32 %0, i32 %1, i32 %2, double %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double %3, double* %9
store i32 %4, i32* %10
store double 1.600000e+00, double* %11
store double 7.500000e-01, double* %12
%14 = load i32, i32* %10
%15 = load i32, i32* %8
%16 = sub nsw i32 %14, %15
%17 = sitofp i32 %16 to double
%18 = fadd double %17, 5.000000e-01
%19 = load i32, i32* %8
%20 = sitofp i32 %19 to double
%21 = fadd double %20, 5.000000e-01
%22 = fdiv double %18, %21
%23 = fptosi double %22 to i32
%24 = call double @log(i32 %23)
store double %24, double* %13
%25 = load i32, i32* %7
%26 = sitofp i32 %25 to double
%27 = load double, double* %11
%28 = fadd double %27, 1.000000e+00
%29 = fmul double %26, %28
%30 = load double, double* %13
%31 = fmul double %30, %29
store double %31, double* %13
%32 = load i32, i32* %7
%33 = sitofp i32 %32 to double
%34 = load double, double* %11
%35 = load double, double* %12
%36 = fsub double 1.000000e+00, %35
%37 = load double, double* %12
%38 = load i32, i32* %6
%39 = sitofp i32 %38 to double
%40 = fmul double %37, %39
%41 = load double, double* %9
%42 = fdiv double %40, %41
%43 = fadd double %36, %42
%44 = call double @llvm.fmuladd.f64(double %34, double %43, double %33)
%45 = load double, double* %13
%46 = fdiv double %45, %44
store double %46, double* %13
%47 = load double, double* %13
ret double %47
}

LLVM IR (-O2):
define double @bm25(i32 %0, i32 %1, i32 %2, double %3, i32 %4) {
%6 = sub nsw i32 %4, %2
%7 = sitofp i32 %6 to double
%8 = fadd double %7, 5.000000e-01
%9 = sitofp i32 %2 to double
%10 = fadd double %9, 5.000000e-01
%11 = fdiv double %8, %10
%12 = fptosi double %11 to i32
%13 = tail call double @log(i32 %12)
%14 = sitofp i32 %1 to double
%15 = fmul double %14, 2.600000e+00
%16 = fmul double %15, %13
%17 = sitofp i32 %0 to double
%18 = fmul double %17, 7.500000e-01
%19 = fdiv double %18, %3
%20 = fadd double %19, 2.500000e-01
%21 = tail call double @llvm.fmuladd.f64(double %20, double 1.600000e+00, double %14)
%22 = fdiv double %16, %21
ret double %22
}