int getweightedmean_int(int n, int *data, double *sig) {
  int i;
  double tmp;
  double num = (double)n;
  long double mean_val1 = 0, mean_val2 = 0;
  for (i = 0; i < n; i++) {
    tmp = 1. / sig[i] / sig[i];
    mean_val1 += (long double)data[i] * tmp;
    mean_val2 += (long double)tmp;
  }
  return (int)(mean_val1 / mean_val2);
}


x86 assembly (clang, -O0):
<getweightedmean_int>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
fldz
fld    %st(0)
fstpt  -0x40(%rbp)
fstpt  -0x50(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1191 <getweightedmean_int+0x91>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  0xeb5(%rip),%xmm0
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x58(%rbp)
fildl  -0x58(%rbp)
fldl   -0x28(%rbp)
fldt   -0x40(%rbp)
fxch   %st(2)
fmulp  %st,%st(1)
faddp  %st,%st(1)
fstpt  -0x40(%rbp)
fldl   -0x28(%rbp)
fldt   -0x50(%rbp)
faddp  %st,%st(1)
fstpt  -0x50(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <getweightedmean_int+0x2a>
fldt   -0x40(%rbp)
fldt   -0x50(%rbp)
fdivrp %st,%st(1)
fnstcw -0x5a(%rbp)
movzwl -0x5a(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x5c(%rbp)
fldcw  -0x5c(%rbp)
fistpl -0x54(%rbp)
fldcw  -0x5a(%rbp)
mov    -0x54(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getweightedmean_int>:
test   %edi,%edi
jle    117b <getweightedmean_int+0x7b>
mov    %edi,%eax
fldz
xor    %ecx,%ecx
movsd  0xeee(%rip),%xmm0
fld    %st(0)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rdx,%rcx,8),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
divsd  %xmm1,%xmm2
mov    (%rsi,%rcx,4),%edi
mov    %edi,-0xc(%rsp)
movsd  %xmm2,-0x8(%rsp)
fldl   -0x8(%rsp)
fld    %st(0)
fimull -0xc(%rsp)
faddp  %st,%st(2)
faddp  %st,%st(2)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1120 <getweightedmean_int+0x20>
fdivp  %st,%st(1)
fnstcw -0x14(%rsp)
movzwl -0x14(%rsp),%eax
or     $0xc00,%eax
mov    %ax,-0x12(%rsp)
fldcw  -0x12(%rsp)
fistpl -0x10(%rsp)
fldcw  -0x14(%rsp)
mov    -0x10(%rsp),%eax
ret
ret

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

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