#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*/ assert(int);
int log(double);
double loglikelihood(long edge_count, double edgelen_sum) {
  assert(edge_count >= 0);
  if (edge_count == 0 ||
      edgelen_sum < ((double)2.22507385850720138309023271733240406e-308L))
    return 0;
  return edge_count * (log(edge_count) - 1 - log(edgelen_sum));
}


x86 assembly (clang, -O0):
<loglikelihood>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
je     1161 <loglikelihood+0x41>
movsd  0xeaa(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    116e <loglikelihood+0x4e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ad <loglikelihood+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
call   1040 <log@plt>
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
mov    -0x20(%rbp),%rax
sub    %edx,%ecx
movslq %ecx,%rcx
imul   %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loglikelihood>:
push   %rbp
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %rdi,%rbx
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1030 <assert@plt>
xorpd  %xmm0,%xmm0
test   %rbx,%rbx
je     117a <loglikelihood+0x5a>
movsd  0xeb8(%rip),%xmm1
ucomisd (%rsp),%xmm1
ja     117a <loglikelihood+0x5a>
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
call   1040 <log@plt>
mov    %eax,%ebp
movsd  (%rsp),%xmm0
call   1040 <log@plt>
not    %eax
add    %ebp,%eax
cltq
imul   %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @loglikelihood(i64 %0, double %1) {
%3 = alloca double
%4 = alloca i64
%5 = alloca double
store i64 %0, i64* %4
store double %1, double* %5
%6 = load i64, i64* %4
%7 = icmp sge i64 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i64, i64* %4
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load double, double* %5
%14 = fcmp olt double %13, 0x10000000000000
br i1 %14, label %15, label %16
15: ; preds = %12, %2
store double 0.000000e+00, double* %3
br label %28
16: ; preds = %12
%17 = load i64, i64* %4
%18 = load i64, i64* %4
%19 = sitofp i64 %18 to double
%20 = call i32 @log(double %19)
%21 = sub nsw i32 %20, 1
%22 = load double, double* %5
%23 = call i32 @log(double %22)
%24 = sub nsw i32 %21, %23
%25 = sext i32 %24 to i64
%26 = mul nsw i64 %17, %25
%27 = sitofp i64 %26 to double
store double %27, double* %3
br label %28
28: ; preds = %16, %15
%29 = load double, double* %3
ret double %29
}

LLVM IR (-O2):
define double @loglikelihood(i64 %0, double %1) {
%3 = lshr i64 %0, 63
%4 = trunc i64 %3 to i32
%5 = xor i32 %4, 1
%6 = tail call i32 @assert(i32 %5)
%7 = icmp eq i64 %0, 0
%8 = fcmp olt double %1, 0x10000000000000
%9 = or i1 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %2
%11 = sitofp i64 %0 to double
%12 = tail call i32 @log(double %11)
%13 = tail call i32 @log(double %1)
%14 = xor i32 %13, -1
%15 = add i32 %12, %14
%16 = sext i32 %15 to i64
%17 = mul nsw i64 %16, %0
%18 = sitofp i64 %17 to double
br label %19
19: ; preds = %2, %10
%20 = phi double [ %18, %10 ], [ 0.000000e+00, %2 ]
ret double %20
}