#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*/ AT_histo_bin_width(long const, double const, double const,
                                      long const, long, double *);
int /*<<< orphan*/ AT_histo_midpoint(long const, double const, double const,
                                     long const, long, double *);
void AT_histo_sum(const long number_of_bins, const double lowest_left_limit,
                  const double step, const long histo_type,
                  const double frequency[], double *sum) {
  long i;
  double midpoint = 0.0;
  double bin_width = 0.0;
  *sum = 0.0;
  for (i = 0; i < number_of_bins; i++) {
    AT_histo_midpoint(number_of_bins, lowest_left_limit, step, histo_type, i,
                      &midpoint);
    AT_histo_bin_width(number_of_bins, lowest_left_limit, step, histo_type, i,
                       &bin_width);
    *sum += frequency[i] * midpoint * bin_width;
  }
}


x86 assembly (clang, -O0):
<AT_histo_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11ed <AT_histo_sum+0xcd>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1030 <AT_histo_midpoint@plt>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1040 <AT_histo_bin_width@plt>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1165 <AT_histo_sum+0x45>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AT_histo_sum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x20(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,(%rcx)
test   %rdi,%rdi
jle    11d1 <AT_histo_sum+0xb1>
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
xor    %ebx,%ebx
lea    0x18(%rsp),%rbp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
nop
mov    %r13,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %r12,%rsi
mov    %rbx,%rdx
lea    0x20(%rsp),%rcx
call   1030 <AT_histo_midpoint@plt>
mov    %r13,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <AT_histo_bin_width@plt>
movsd  (%r14,%rbx,8),%xmm0
mulsd  0x20(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
addsd  (%r15),%xmm0
movsd  %xmm0,(%r15)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <AT_histo_sum+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @AT_histo_sum(i64 %0, double %1, double %2, i64 %3, double* nocapture %4, double* nocapture %5) {
%7 = alloca double
%8 = alloca double
%9 = bitcast double* %7 to i8*
store double 0.000000e+00, double* %7
%10 = bitcast double* %8 to i8*
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %5
%11 = icmp sgt i64 %0, 0
br i1 %11, label %12, label %25
12: ; preds = %6, %12
%13 = phi i64 [ %23, %12 ], [ 0, %6 ]
%14 = call i32 @AT_histo_midpoint(i64 %0, double %1, double %2, i64 %3, i64 %13, double* %7)
%15 = call i32 @AT_histo_bin_width(i64 %0, double %1, double %2, i64 %3, i64 %13, double* %8)
%16 = getelementptr inbounds double, double* %4, i64 %13
%17 = load double, double* %16
%18 = load double, double* %7
%19 = fmul double %17, %18
%20 = load double, double* %8
%21 = load double, double* %5
%22 = call double @llvm.fmuladd.f64(double %19, double %20, double %21)
store double %22, double* %5
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i64 %23, %0
br i1 %24, label %25, label %12
25: ; preds = %12, %6
ret void
}