#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 */
scalar_t__ log(int);
double loglikelihood(double *lratio, char *bits, int N) {
  double ll;
  int j;
  ll = 0;
  for (j = 0; j < N; j++) {
    ll -= bits[j] ? log(1 + 1 / lratio[j]) : log(1 + lratio[j]);
  }
  return ll;
}


x86 assembly (clang, -O0):
<loglikelihood>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    11cd <loglikelihood+0xbd>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1186 <loglikelihood+0x76>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe9d(%rip),%xmm1
divsd  (%rax,%rcx,8),%xmm1
movsd  0xe90(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
mov    %rax,-0x30(%rbp)
jmp    11a8 <loglikelihood+0x98>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe6a(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <loglikelihood+0x22>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loglikelihood>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    117f <loglikelihood+0x6f>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1157 <loglikelihood+0x47>
nopl   (%rax)
addsd  %xmm0,%xmm2
cvttsd2si %xmm2,%edi
call   1030 <log@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r12
je     1183 <loglikelihood+0x73>
cmpb   $0x0,(%r14,%rbx,1)
movsd  (%r15,%rbx,8),%xmm2
movsd  %xmm0,(%rsp)
movsd  0xe91(%rip),%xmm0
je     1130 <loglikelihood+0x20>
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm2
jmp    1130 <loglikelihood+0x20>
xorpd  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @loglikelihood(double* %0, i8* %1, i32 %2) {
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %9
9: ; preds = %45, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %48
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %13
%22 = load double*, double** %4
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = fdiv double 1.000000e+00, %26
%28 = fadd double 1.000000e+00, %27
%29 = fptosi double %28 to i32
%30 = call i64 @log(i32 %29)
br label %40
31: ; preds = %13
%32 = load double*, double** %4
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = fadd double 1.000000e+00, %36
%38 = fptosi double %37 to i32
%39 = call i64 @log(i32 %38)
br label %40
40: ; preds = %31, %21
%41 = phi i64 [ %30, %21 ], [ %39, %31 ]
%42 = sitofp i64 %41 to double
%43 = load double, double* %7
%44 = fsub double %43, %42
store double %44, double* %7
br label %45
45: ; preds = %40
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %9
48: ; preds = %9
%49 = load double, double* %7
ret double %49
}

LLVM IR (-O2):
define double @loglikelihood(double* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %24
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %22, %7 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %21, %7 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %8
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = getelementptr inbounds double, double* %0, i64 %8
%14 = load double, double* %13
%15 = fdiv double 1.000000e+00, %14
%16 = select i1 %12, double %14, double %15
%17 = fadd double %16, 1.000000e+00
%18 = fptosi double %17 to i32
%19 = tail call i64 @log(i32 %18)
%20 = sitofp i64 %19 to double
%21 = fsub double %9, %20
%22 = add nuw nsw i64 %8, 1
%23 = icmp eq i64 %22, %6
br i1 %23, label %24, label %7
24: ; preds = %7, %3
%25 = phi double [ 0.000000e+00, %3 ], [ %21, %7 ]
ret double %25
}