#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_factorial(int);
void degree_complexity(double *Pk, int *degrees, double kav, int N) {
  int i;
  double Complexity, log(), logfactorial();
  Complexity = 0.0;
  for (i = 0; i < N; i++) {
    Complexity = Complexity + log(Pk[degrees[i]]) -
                 (double)degrees[i] * log(kav) + kav +
                 log_factorial(degrees[i]);
  }
  Complexity = Complexity / (double)N;
}


x86 assembly (clang, -O0):
<degree_complexity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1209 <degree_complexity+0xe9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <log_factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1147 <degree_complexity+0x27>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<degree_complexity>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
test   %edx,%edx
jle    116b <degree_complexity+0x4b>
mov    %rsi,%r12
mov    %rdi,%r14
mov    %edx,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax)
movslq (%r12,%rbx,4),%rax
movsd  (%r14,%rax,8),%xmm0
call   1040 <log@plt>
movsd  (%rsp),%xmm0
call   1040 <log@plt>
mov    (%r12,%rbx,4),%edi
call   1030 <log_factorial@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <degree_complexity+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @degree_complexity(double* nocapture %0, i32* nocapture %1, double %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %21
6: ; preds = %4
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %19, %8 ]
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = tail call double @log(double %14)
%16 = tail call double @log(double %2)
%17 = load i32, i32* %10
%18 = tail call double @log_factorial(i32 %17)
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %8, %4
ret void
}