#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*/ free(double *);
double *malloc(int);
scalar_t__ silhouette(double *, double *, double *, int, int);
double average_silhouette(double *points, double *samples, int n_samples,
                          int dims, int n_points) {
  double *distances;
  distances = malloc(sizeof(double) * n_points);
  double tot = 0;
  int i;
  for (i = 0; i < n_samples; i++) {
    tot += silhouette(points, &samples[i * dims], distances, dims, n_points);
  }
  free(distances);
  return tot / n_samples;
}


x86 assembly (clang, -O0):
<average_silhouette>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bd <average_silhouette+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1050 <silhouette@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116c <average_silhouette+0x3c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<average_silhouette>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %ecx,0x4(%rsp)
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%r13
lea    0x0(,%r12,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
mov    %r15d,0x14(%rsp)
jle    11b8 <average_silhouette+0x88>
movslq 0x4(%rsp),%r14
mov    %r15d,%r15d
shl    $0x3,%r14
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    0x4(%rsp),%ecx
mov    %r12d,%r8d
call   1050 <silhouette@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    %r14,%rbp
add    $0xffffffffffffffff,%r15
jne    1180 <average_silhouette+0x50>
jmp    11c2 <average_silhouette+0x92>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
xorps  %xmm1,%xmm1
cvtsi2sdl 0x14(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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