#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*/ memset(double *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mult(double *, double *, double, int);
double sum(double *, int);
void wmean(double *mu, double **X, double *w, int n, int m) {
  memset(mu, 0, m * sizeof(double));
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      mu[j] += w[i] * X[i][j];
  mult(mu, mu, 1.0 / sum(w, n), m);
}


x86 assembly (clang, -O0):
<wmean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e3 <wmean+0xb3>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d0 <wmean+0xa0>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117a <wmean+0x4a>
jmp    11d5 <wmean+0xa5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1167 <wmean+0x37>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <sum@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movaps %xmm0,%xmm1
movsd  0xdee(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%edx
call   1050 <mult@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wmean>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x0(,%r14,8),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %r15d,0xc(%rsp)
test   %r15d,%r15d
jle    12db <wmean+0x1ab>
mov    0xc(%rsp),%r11d
mov    %r14d,%ecx
lea    (%rbx,%rcx,8),%r9
mov    %ecx,%eax
and    $0xfffffffc,%eax
mov    %rax,0x10(%rsp)
mov    %rcx,%r10
neg    %r10
lea    0x0(,%rcx,8),%r13
and    $0xffffffffffffffe0,%r13
xor    %edx,%edx
jmp    11ad <wmean+0x7d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    %r11,%rdx
je     12db <wmean+0x1ab>
test   %r14d,%r14d
jle    11a0 <wmean+0x70>
mov    (%r12,%rdx,8),%rdi
cmp    $0x4,%r14d
jb     1260 <wmean+0x130>
lea    0x0(,%rdx,8),%rax
add    %rbp,%rax
lea    0x8(,%rdx,8),%rsi
add    %rbp,%rsi
lea    (%rdi,%rcx,8),%r15
cmp    %rbx,%rsi
seta   %sil
cmp    %r9,%rax
setb   %r8b
cmp    %rbx,%r15
seta   %al
cmp    %r9,%rdi
setb   %r15b
test   %r8b,%sil
jne    1260 <wmean+0x130>
mov    $0x0,%esi
and    %r15b,%al
jne    1262 <wmean+0x132>
movsd  0x0(%rbp,%rdx,8),%xmm0
unpcklpd %xmm0,%xmm0
xor    %eax,%eax
movupd (%rdi,%rax,1),%xmm1
movupd 0x10(%rdi,%rax,1),%xmm2
movupd (%rbx,%rax,1),%xmm3
movupd 0x10(%rbx,%rax,1),%xmm4
mulpd  %xmm0,%xmm1
addpd  %xmm3,%xmm1
mulpd  %xmm0,%xmm2
addpd  %xmm4,%xmm2
movupd %xmm1,(%rbx,%rax,1)
movupd %xmm2,0x10(%rbx,%rax,1)
add    $0x20,%rax
cmp    %rax,%r13
jne    1210 <wmean+0xe0>
mov    0x10(%rsp),%rax
mov    %rax,%rsi
cmp    %rcx,%rax
je     11a0 <wmean+0x70>
jmp    1262 <wmean+0x132>
nopl   (%rax)
xor    %esi,%esi
mov    %rsi,%rax
test   $0x1,%cl
je     1286 <wmean+0x156>
movsd  0x0(%rbp,%rdx,8),%xmm0
mulsd  (%rdi,%rsi,8),%xmm0
addsd  (%rbx,%rsi,8),%xmm0
movsd  %xmm0,(%rbx,%rsi,8)
mov    %rsi,%rax
or     $0x1,%rax
not    %rsi
cmp    %r10,%rsi
je     11a0 <wmean+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x0(%rbp,%rdx,8),%xmm0
mulsd  (%rdi,%rax,8),%xmm0
addsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
movsd  0x0(%rbp,%rdx,8),%xmm0
mulsd  0x8(%rdi,%rax,8),%xmm0
addsd  0x8(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rax,8)
add    $0x2,%rax
cmp    %rax,%rcx
jne    12a0 <wmean+0x170>
jmp    11a0 <wmean+0x70>
mov    %rbp,%rdi
mov    0xc(%rsp),%esi
call   1040 <sum@plt>
movsd  0xd11(%rip),%xmm1
divsd  %xmm0,%xmm1
mov    %rbx,%rdi
mov    %rbx,%rsi
movapd %xmm1,%xmm0
mov    %r14d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mult@plt>

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

LLVM IR (-O2):
define void @wmean(double* %0, double** nocapture %1, double* %2, i32 %3, i32 %4) {
%6 = shl i32 %4, 3
%7 = tail call i32 @memset(double* %0, i32 0, i32 %6)
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %99
9: ; preds = %5
%10 = icmp sgt i32 %4, 0
%11 = zext i32 %3 to i64
%12 = zext i32 %4 to i64
%13 = getelementptr double, double* %0, i64 %12
%14 = icmp ult i32 %4, 4
%15 = and i64 %12, 4294967292
%16 = icmp eq i64 %15, %12
%17 = and i64 %12, 1
%18 = icmp eq i64 %17, 0
%19 = sub nsw i64 0, %12
br label %20
20: ; preds = %9, %96
%21 = phi i64 [ 0, %9 ], [ %97, %96 ]
%22 = getelementptr double, double* %2, i64 %21
%23 = add nuw i64 %21, 1
%24 = getelementptr double, double* %2, i64 %23
br i1 %10, label %25, label %96
25: ; preds = %20
%26 = getelementptr inbounds double, double* %2, i64 %21
%27 = getelementptr inbounds double*, double** %1, i64 %21
%28 = load double*, double** %27
br i1 %14, label %65, label %29
29: ; preds = %25
%30 = getelementptr double, double* %28, i64 %12
%31 = icmp ugt double* %24, %0
%32 = icmp ult double* %22, %13
%33 = and i1 %31, %32
%34 = icmp ugt double* %30, %0
%35 = icmp ult double* %28, %13
%36 = and i1 %34, %35
%37 = or i1 %33, %36
br i1 %37, label %65, label %38
38: ; preds = %29
%39 = load double, double* %26
%40 = insertelement <2 x double> poison, double %39, i64 0
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
%42 = insertelement <2 x double> poison, double %39, i64 0
%43 = shufflevector <2 x double> %42, <2 x double> poison, <2 x i32> zeroinitializer
br label %44
44: ; preds = %44, %38
%45 = phi i64 [ 0, %38 ], [ %62, %44 ]
%46 = getelementptr inbounds double, double* %28, i64 %45
%47 = bitcast double* %46 to <2 x double>*
%48 = load <2 x double>, <2 x double>* %47
%49 = getelementptr inbounds double, double* %46, i64 2
%50 = bitcast double* %49 to <2 x double>*
%51 = load <2 x double>, <2 x double>* %50
%52 = getelementptr inbounds double, double* %0, i64 %45
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = getelementptr inbounds double, double* %52, i64 2
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %41, <2 x double> %48, <2 x double> %54)
%59 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %43, <2 x double> %51, <2 x double> %57)
%60 = bitcast double* %52 to <2 x double>*
store <2 x double> %58, <2 x double>* %60
%61 = bitcast double* %55 to <2 x double>*
store <2 x double> %59, <2 x double>* %61
%62 = add nuw i64 %45, 4
%63 = icmp eq i64 %62, %15
br i1 %63, label %64, label %44
64: ; preds = %44
br i1 %16, label %96, label %65
65: ; preds = %29, %25, %64
%66 = phi i64 [ 0, %29 ], [ 0, %25 ], [ %15, %64 ]
%67 = xor i64 %66, -1
br i1 %18, label %76, label %68
68: ; preds = %65
%69 = load double, double* %26
%70 = getelementptr inbounds double, double* %28, i64 %66
%71 = load double, double* %70
%72 = getelementptr inbounds double, double* %0, i64 %66
%73 = load double, double* %72
%74 = tail call double @llvm.fmuladd.f64(double %69, double %71, double %73)
store double %74, double* %72
%75 = or i64 %66, 1
br label %76
76: ; preds = %68, %65
%77 = phi i64 [ %66, %65 ], [ %75, %68 ]
%78 = icmp eq i64 %67, %19
br i1 %78, label %96, label %79
79: ; preds = %76, %79
%80 = phi i64 [ %94, %79 ], [ %77, %76 ]
%81 = load double, double* %26
%82 = getelementptr inbounds double, double* %28, i64 %80
%83 = load double, double* %82
%84 = getelementptr inbounds double, double* %0, i64 %80
%85 = load double, double* %84
%86 = tail call double @llvm.fmuladd.f64(double %81, double %83, double %85)
store double %86, double* %84
%87 = add nuw nsw i64 %80, 1
%88 = load double, double* %26
%89 = getelementptr inbounds double, double* %28, i64 %87
%90 = load double, double* %89
%91 = getelementptr inbounds double, double* %0, i64 %87
%92 = load double, double* %91
%93 = tail call double @llvm.fmuladd.f64(double %88, double %90, double %92)
store double %93, double* %91
%94 = add nuw nsw i64 %80, 2
%95 = icmp eq i64 %94, %12
br i1 %95, label %96, label %79
96: ; preds = %76, %79, %64, %20
%97 = add nuw nsw i64 %21, 1
%98 = icmp eq i64 %97, %11
br i1 %98, label %99, label %20
99: ; preds = %96, %5
%100 = tail call double @sum(double* %2, i32 %3)
%101 = fdiv double 1.000000e+00, %100
%102 = tail call i32 @mult(double* %0, double* %0, double %101, i32 %4)
ret void
}