#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*/ glbGetBGCenters(int, int, double *, double *);
double *glbGetBGFitRatePtr(int, int);
int /*<<< orphan*/ glbGetEnergyWindowBins(int, int, int *, int *);
double *glbGetRuleRatePtr(int, int);
double *glbGetSignalFitRatePtr(int, int);
double glb_likelihood(double, double);
double glbChiNoSysTotalRates(int exp, int rule, int n_params, double *x,
                             double *errors, void *user_data) {
  double *true_rates = glbGetRuleRatePtr(exp, rule);
  double *signal_fit_rates = glbGetSignalFitRatePtr(exp, rule);
  double *bg_fit_rates = glbGetBGFitRatePtr(exp, rule);
  double bg_norm_center, bg_tilt_center;
  int ew_low, ew_high;
  double fit_rate, true_rate;
  double total_fit_rate, total_true_rate;
  double chi2 = 0.0;
  int i;
  glbGetEnergyWindowBins(exp, rule, &ew_low, &ew_high);
  glbGetBGCenters(exp, rule, &bg_norm_center, &bg_tilt_center);
  total_fit_rate = 0.0;
  total_true_rate = 0.0;
  for (i = ew_low; i <= ew_high; i++) {
    fit_rate = (signal_fit_rates[i] + bg_norm_center * bg_fit_rates[i]);
    total_fit_rate += fit_rate;
    total_true_rate += true_rates[i];
  }
  chi2 = glb_likelihood(total_true_rate, total_fit_rate);
  return chi2;
}


x86 assembly (clang, -O0):
<glbChiNoSysTotalRates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <glbGetRuleRatePtr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <glbGetSignalFitRatePtr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <glbGetBGFitRatePtr@plt>
mov    %rax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x54(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1030 <glbGetEnergyWindowBins@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1080 <glbGetBGCenters@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x58(%rbp),%eax
jg     1272 <glbChiNoSysTotalRates+0x112>
mov    -0x38(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x48(%rbp),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11f4 <glbChiNoSysTotalRates+0x94>
movsd  -0x78(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
call   1060 <glb_likelihood@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glbChiNoSysTotalRates>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r12d
mov    %edi,%ebp
call   1040 <glbGetRuleRatePtr@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %r12d,%esi
call   1050 <glbGetSignalFitRatePtr@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    %r12d,%esi
call   1070 <glbGetBGFitRatePtr@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    %r12d,%esi
call   1030 <glbGetEnergyWindowBins@plt>
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rcx
mov    %ebp,%edi
mov    %r12d,%esi
call   1080 <glbGetBGCenters@plt>
movslq 0xc(%rsp),%rcx
mov    0x8(%rsp),%edx
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
cmp    %ecx,%edx
jl     125d <glbChiNoSysTotalRates+0xfd>
movsd  0x10(%rsp),%xmm2
lea    0x1(%rdx),%esi
mov    %esi,%eax
sub    %ecx,%eax
test   $0x1,%al
jne    11f6 <glbChiNoSysTotalRates+0x96>
xorpd  %xmm0,%xmm0
mov    %rcx,%rax
xorpd  %xmm1,%xmm1
cmp    %ecx,%edx
jne    121b <glbChiNoSysTotalRates+0xbb>
jmp    125d <glbChiNoSysTotalRates+0xfd>
movsd  (%rbx,%rcx,8),%xmm1
mulsd  %xmm2,%xmm1
addsd  (%r15,%rcx,8),%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm0,%xmm1
addsd  (%r14,%rcx,8),%xmm0
lea    0x1(%rcx),%rax
cmp    %ecx,%edx
je     125d <glbChiNoSysTotalRates+0xfd>
mov    %esi,%ecx
nopl   (%rax)
movsd  (%rbx,%rax,8),%xmm3
mulsd  %xmm2,%xmm3
addsd  (%r15,%rax,8),%xmm3
addsd  %xmm1,%xmm3
addsd  (%r14,%rax,8),%xmm0
movsd  0x8(%rbx,%rax,8),%xmm1
mulsd  %xmm2,%xmm1
addsd  0x8(%r15,%rax,8),%xmm1
addsd  %xmm3,%xmm1
addsd  0x8(%r14,%rax,8),%xmm0
add    $0x2,%rax
cmp    %eax,%ecx
jne    1220 <glbChiNoSysTotalRates+0xc0>
call   1060 <glb_likelihood@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @glbChiNoSysTotalRates(i32 %0, i32 %1, i32 %2, double* %3, double* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca i8*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store double* %4, double** %11
store i8* %5, i8** %12
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = call double* @glbGetRuleRatePtr(i32 %26, i32 %27)
store double* %28, double** %13
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call double* @glbGetSignalFitRatePtr(i32 %29, i32 %30)
store double* %31, double** %14
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = call double* @glbGetBGFitRatePtr(i32 %32, i32 %33)
store double* %34, double** %15
store double 0.000000e+00, double* %24
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = call i32 @glbGetEnergyWindowBins(i32 %35, i32 %36, i32* %18, i32* %19)
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = call i32 @glbGetBGCenters(i32 %38, i32 %39, double* %16, double* %17)
store double 0.000000e+00, double* %22
store double 0.000000e+00, double* %23
%41 = load i32, i32* %18
store i32 %41, i32* %25
br label %42
42: ; preds = %69, %6
%43 = load i32, i32* %25
%44 = load i32, i32* %19
%45 = icmp sle i32 %43, %44
br i1 %45, label %46, label %72
46: ; preds = %42
%47 = load double*, double** %14
%48 = load i32, i32* %25
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = load double, double* %16
%53 = load double*, double** %15
%54 = load i32, i32* %25
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = call double @llvm.fmuladd.f64(double %52, double %57, double %51)
store double %58, double* %20
%59 = load double, double* %20
%60 = load double, double* %22
%61 = fadd double %60, %59
store double %61, double* %22
%62 = load double*, double** %13
%63 = load i32, i32* %25
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
%66 = load double, double* %65
%67 = load double, double* %23
%68 = fadd double %67, %66
store double %68, double* %23
br label %69
69: ; preds = %46
%70 = load i32, i32* %25
%71 = add nsw i32 %70, 1
store i32 %71, i32* %25
br label %42
72: ; preds = %42
%73 = load double, double* %23
%74 = load double, double* %22
%75 = call double @glb_likelihood(double %73, double %74)
store double %75, double* %24
%76 = load double, double* %24
ret double %76
}

LLVM IR (-O2):
define double @glbChiNoSysTotalRates(i32 %0, i32 %1, i32 %2, double* nocapture readnone %3, double* nocapture readnone %4, i8* nocapture readnone %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = tail call double* @glbGetRuleRatePtr(i32 %0, i32 %1)
%12 = tail call double* @glbGetSignalFitRatePtr(i32 %0, i32 %1)
%13 = tail call double* @glbGetBGFitRatePtr(i32 %0, i32 %1)
%14 = bitcast double* %7 to i8*
%15 = bitcast double* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = bitcast i32* %10 to i8*
%18 = call i32 @glbGetEnergyWindowBins(i32 %0, i32 %1, i32* %9, i32* %10)
%19 = call i32 @glbGetBGCenters(i32 %0, i32 %1, double* %7, double* %8)
%20 = load i32, i32* %9
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, %20
br i1 %22, label %74, label %23
23: ; preds = %6
%24 = load double, double* %7
%25 = sext i32 %20 to i64
%26 = add i32 %21, 1
%27 = sub i32 %26, %20
%28 = and i32 %27, 1
%29 = icmp eq i32 %28, 0
br i1 %29, label %41, label %30
30: ; preds = %23
%31 = getelementptr inbounds double, double* %12, i64 %25
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %13, i64 %25
%34 = load double, double* %33
%35 = call double @llvm.fmuladd.f64(double %24, double %34, double %32)
%36 = fadd double %35, 0.000000e+00
%37 = getelementptr inbounds double, double* %11, i64 %25
%38 = load double, double* %37
%39 = fadd double %38, 0.000000e+00
%40 = add nsw i64 %25, 1
br label %41
41: ; preds = %30, %23
%42 = phi double [ undef, %23 ], [ %36, %30 ]
%43 = phi double [ undef, %23 ], [ %39, %30 ]
%44 = phi i64 [ %25, %23 ], [ %40, %30 ]
%45 = phi double [ 0.000000e+00, %23 ], [ %39, %30 ]
%46 = phi double [ 0.000000e+00, %23 ], [ %36, %30 ]
%47 = icmp eq i32 %21, %20
br i1 %47, label %74, label %48
48: ; preds = %41, %48
%49 = phi i64 [ %71, %48 ], [ %44, %41 ]
%50 = phi double [ %70, %48 ], [ %45, %41 ]
%51 = phi double [ %67, %48 ], [ %46, %41 ]
%52 = getelementptr inbounds double, double* %12, i64 %49
%53 = load double, double* %52
%54 = getelementptr inbounds double, double* %13, i64 %49
%55 = load double, double* %54
%56 = call double @llvm.fmuladd.f64(double %24, double %55, double %53)
%57 = fadd double %51, %56
%58 = getelementptr inbounds double, double* %11, i64 %49
%59 = load double, double* %58
%60 = fadd double %50, %59
%61 = add nsw i64 %49, 1
%62 = getelementptr inbounds double, double* %12, i64 %61
%63 = load double, double* %62
%64 = getelementptr inbounds double, double* %13, i64 %61
%65 = load double, double* %64
%66 = call double @llvm.fmuladd.f64(double %24, double %65, double %63)
%67 = fadd double %57, %66
%68 = getelementptr inbounds double, double* %11, i64 %61
%69 = load double, double* %68
%70 = fadd double %60, %69
%71 = add nsw i64 %49, 2
%72 = trunc i64 %71 to i32
%73 = icmp eq i32 %26, %72
br i1 %73, label %74, label %48
74: ; preds = %41, %48, %6
%75 = phi double [ 0.000000e+00, %6 ], [ %42, %41 ], [ %67, %48 ]
%76 = phi double [ 0.000000e+00, %6 ], [ %43, %41 ], [ %70, %48 ]
%77 = call double @glb_likelihood(double %76, double %75)
ret double %77
}