#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 log(int);
double expected_loglikelihood(double *lratio, double *bpr, int N) {
  double ll;
  int j;
  ll = 0;
  for (j = 0; j < N; j++) {
    if (bpr[j] > 0) {
      ll -= bpr[j] * log(1 + 1 / lratio[j]);
    }
    if (bpr[j] < 1) {
      ll -= (1 - bpr[j]) * log(1 + lratio[j]);
    }
  }
  return ll;
}


x86 assembly (clang, -O0):
<expected_loglikelihood>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125e <expected_loglikelihood+0x14e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c6 <expected_loglikelihood+0xb6>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe86(%rip),%xmm1
divsd  (%rax,%rcx,8),%xmm1
movsd  0xe79(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm2
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe2a(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    124b <expected_loglikelihood+0x13b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe0f(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xdf5(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %eax,%xmm2
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1250 <expected_loglikelihood+0x140>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <expected_loglikelihood+0x22>
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expected_loglikelihood>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    1206 <expected_loglikelihood+0xf6>
mov    %rsi,%r12
mov    %rdi,%r14
mov    %edx,%r15d
xor    %ebx,%ebx
movsd  0xeca(%rip),%xmm1
xorpd  %xmm0,%xmm0
jmp    114d <expected_loglikelihood+0x3d>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     120a <expected_loglikelihood+0xfa>
movsd  (%r12,%rbx,8),%xmm2
ucomisd 0xead(%rip),%xmm2
jbe    11a9 <expected_loglikelihood+0x99>
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
divsd  (%r14,%rbx,8),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  %xmm2,0x10(%rsp)
call   1030 <log@plt>
movsd  0xe78(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
subsd  %xmm2,%xmm0
movsd  (%r12,%rbx,8),%xmm2
ucomisd %xmm2,%xmm1
jbe    1140 <expected_loglikelihood+0x30>
movapd %xmm1,%xmm3
subsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  (%r14,%rbx,8),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xe05(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
jmp    1140 <expected_loglikelihood+0x30>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @expected_loglikelihood(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %9
9: ; preds = %66, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %69
13: ; preds = %9
%14 = load double*, double** %5
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = fcmp ogt double %18, 0.000000e+00
br i1 %19, label %20, label %39
20: ; preds = %13
%21 = load double*, double** %5
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = load double*, double** %4
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = fdiv double 1.000000e+00, %30
%32 = fadd double 1.000000e+00, %31
%33 = fptosi double %32 to i32
%34 = call i32 @log(i32 %33)
%35 = sitofp i32 %34 to double
%36 = load double, double* %7
%37 = fneg double %25
%38 = call double @llvm.fmuladd.f64(double %37, double %35, double %36)
store double %38, double* %7
br label %39
39: ; preds = %20, %13
%40 = load double*, double** %5
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = fcmp olt double %44, 1.000000e+00
br i1 %45, label %46, label %65
46: ; preds = %39
%47 = load double*, double** %5
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = fsub double 1.000000e+00, %51
%53 = load double*, double** %4
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = fadd double 1.000000e+00, %57
%59 = fptosi double %58 to i32
%60 = call i32 @log(i32 %59)
%61 = sitofp i32 %60 to double
%62 = load double, double* %7
%63 = fneg double %52
%64 = call double @llvm.fmuladd.f64(double %63, double %61, double %62)
store double %64, double* %7
br label %65
65: ; preds = %46, %39
br label %66
66: ; preds = %65
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %9
69: ; preds = %9
%70 = load double, double* %7
ret double %70
}

LLVM IR (-O2):
define double @expected_loglikelihood(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %42
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %38
%8 = phi i64 [ 0, %5 ], [ %40, %38 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %39, %38 ]
%10 = getelementptr inbounds double, double* %1, i64 %8
%11 = load double, double* %10
%12 = fcmp ogt double %11, 0.000000e+00
br i1 %12, label %13, label %24
13: ; preds = %7
%14 = getelementptr inbounds double, double* %0, i64 %8
%15 = load double, double* %14
%16 = fdiv double 1.000000e+00, %15
%17 = fadd double %16, 1.000000e+00
%18 = fptosi double %17 to i32
%19 = tail call i32 @log(i32 %18)
%20 = sitofp i32 %19 to double
%21 = fneg double %11
%22 = tail call double @llvm.fmuladd.f64(double %21, double %20, double %9)
%23 = load double, double* %10
br label %24
24: ; preds = %13, %7
%25 = phi double [ %23, %13 ], [ %11, %7 ]
%26 = phi double [ %22, %13 ], [ %9, %7 ]
%27 = fcmp olt double %25, 1.000000e+00
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = fsub double 1.000000e+00, %25
%30 = getelementptr inbounds double, double* %0, i64 %8
%31 = load double, double* %30
%32 = fadd double %31, 1.000000e+00
%33 = fptosi double %32 to i32
%34 = tail call i32 @log(i32 %33)
%35 = sitofp i32 %34 to double
%36 = fneg double %29
%37 = tail call double @llvm.fmuladd.f64(double %36, double %35, double %26)
br label %38
38: ; preds = %24, %28
%39 = phi double [ %37, %28 ], [ %26, %24 ]
%40 = add nuw nsw i64 %8, 1
%41 = icmp eq i64 %40, %6
br i1 %41, label %42, label %7
42: ; preds = %38, %3
%43 = phi double [ 0.000000e+00, %3 ], [ %39, %38 ]
ret double %43
}