; LLVM IR from kylechampley/XrayPhysics :: src/xscatter.ll (ZN8xscatter27coherentScatterDistributionEPfff)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.xscatter = type { %class.xsec, %"class.std::vector.3", double, double, double, double }
%class.xsec = type { [101 x i32], %"class.std::vector", %"class.std::vector", %"class.std::vector", [101 x i32], %"class.std::vector", %"class.std::vector", %"class.std::vector", [101 x i32], %"class.std::vector", %"class.std::vector", %"class.std::vector", [101 x i32], %"class.std::vector", %"class.std::vector", %"class.std::vector", [101 x i32], %"class.std::vector", %"class.std::vector", %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<float *, std::allocator<float *>>::_Vector_impl" }
%"struct.std::_Vector_base<float *, std::allocator<float *>>::_Vector_impl" = type { %"struct.std::_Vector_base<float *, std::allocator<float *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float *, std::allocator<float *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<xscatter::IncoherentAndCoherentScatterFunctions_elem_s, std::allocator<xscatter::IncoherentAndCoherentScatterFunctions_elem_s>>::_Vector_impl" }
%"struct.std::_Vector_base<xscatter::IncoherentAndCoherentScatterFunctions_elem_s, std::allocator<xscatter::IncoherentAndCoherentScatterFunctions_elem_s>>::_Vector_impl" = type { %"struct.std::_Vector_base<xscatter::IncoherentAndCoherentScatterFunctions_elem_s, std::allocator<xscatter::IncoherentAndCoherentScatterFunctions_elem_s>>::_Vector_impl_data" }
%"struct.std::_Vector_base<xscatter::IncoherentAndCoherentScatterFunctions_elem_s, std::allocator<xscatter::IncoherentAndCoherentScatterFunctions_elem_s>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEifd(ptr noundef nonnull align 8 dereferenceable(2456), i32 noundef, float noundef, double noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEPfff(ptr noundef nonnull align 8 dereferenceable(2456) %0, ptr noundef %1, float noundef %2, float noundef %3) #2 align 2 {
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  %15 = alloca float, align 4
  %16 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store float %2, ptr %8, align 4, !tbaa !9
  store float %3, ptr %9, align 4, !tbaa !9
  %17 = load ptr, ptr %6, align 8
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %4
  store float 0.000000e+00, ptr %5, align 4
  br label %98

21:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 1, ptr %11, align 4, !tbaa !13
  br label %22

22:                                               ; preds = %48, %21
  %23 = load i32, ptr %11, align 4, !tbaa !13
  %24 = icmp sle i32 %23, 100
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %51

26:                                               ; preds = %22
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds float, ptr %27, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !9
  %32 = fpext float %31 to double
  %33 = fcmp ogt double %32, 0.000000e+00
  br i1 %33, label %34, label %47

34:                                               ; preds = %26
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !13
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds float, ptr %35, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !9
  %40 = fpext float %39 to double
  %41 = getelementptr inbounds %class.xscatter, ptr %17, i32 0, i32 0
  %42 = load i32, ptr %11, align 4, !tbaa !13
  %43 = call noundef float @_ZN4xsec13getAtomicMassEi(ptr noundef nonnull align 8 dereferenceable(2400) %41, i32 noundef %42)
  %44 = fpext float %43 to double
  %45 = load double, ptr %10, align 8, !tbaa !11
  %46 = call double @llvm.fmuladd.f64(double %40, double %44, double %45)
  store double %46, ptr %10, align 8, !tbaa !11
  br label %47

47:                                               ; preds = %34, %26
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %11, align 4, !tbaa !13
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %11, align 4, !tbaa !13
  br label %22, !llvm.loop !15

51:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store double 0.000000e+00, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store double 0.000000e+00, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 1, ptr %14, align 4, !tbaa !13
  br label %52

52:                                               ; preds = %92, %51
  %53 = load i32, ptr %14, align 4, !tbaa !13
  %54 = icmp sle i32 %53, 100
  br i1 %54, label %56, label %55

55:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %95

56:                                               ; preds = %52
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %14, align 4, !tbaa !13
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds float, ptr %57, i64 %59
  %61 = load float, ptr %60, align 4, !tbaa !9
  %62 = fpext float %61 to double
  %63 = fcmp ogt double %62, 0.000000e+00
  br i1 %63, label %64, label %91

64:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %65 = load i32, ptr %14, align 4, !tbaa !13
  %66 = load float, ptr %8, align 4, !tbaa !9
  %67 = load float, ptr %9, align 4, !tbaa !9
  %68 = fpext float %67 to double
  %69 = call noundef float @_ZN8xscatter27coherentScatterDistributionEifd(ptr noundef nonnull align 8 dereferenceable(2456) %17, i32 noundef %65, float noundef %66, double noundef %68)
  store float %69, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %70 = getelementptr inbounds %class.xscatter, ptr %17, i32 0, i32 0
  %71 = load i32, ptr %14, align 4, !tbaa !13
  %72 = call noundef float @_ZN4xsec13getAtomicMassEi(ptr noundef nonnull align 8 dereferenceable(2400) %70, i32 noundef %71)
  %73 = fpext float %72 to double
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i32, ptr %14, align 4, !tbaa !13
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds float, ptr %74, i64 %76
  %78 = load float, ptr %77, align 4, !tbaa !9
  %79 = fpext float %78 to double
  %80 = fmul double %73, %79
  %81 = load double, ptr %10, align 8, !tbaa !11
  %82 = fdiv double %80, %81
  store double %82, ptr %16, align 8, !tbaa !11
  %83 = load double, ptr %16, align 8, !tbaa !11
  %84 = load double, ptr %13, align 8, !tbaa !11
  %85 = fadd double %84, %83
  store double %85, ptr %13, align 8, !tbaa !11
  %86 = load double, ptr %16, align 8, !tbaa !11
  %87 = load float, ptr %15, align 4, !tbaa !9
  %88 = fpext float %87 to double
  %89 = load double, ptr %12, align 8, !tbaa !11
  %90 = call double @llvm.fmuladd.f64(double %86, double %88, double %89)
  store double %90, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %91

91:                                               ; preds = %64, %56
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %14, align 4, !tbaa !13
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %14, align 4, !tbaa !13
  br label %52, !llvm.loop !17

95:                                               ; preds = %55
  %96 = load double, ptr %12, align 8, !tbaa !11
  %97 = fptrunc double %96 to float
  store float %97, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %98

98:                                               ; preds = %95, %20
  %99 = load float, ptr %5, align 4
  ret float %99
}

declare noundef float @_ZN4xsec13getAtomicMassEi(ptr noundef nonnull align 8 dereferenceable(2400), i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEifd(ptr noundef nonnull align 8 dereferenceable(2456), i32 noundef, float noundef, double noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEPfff(ptr noundef nonnull align 8 dereferenceable(2456) %0, ptr noundef readonly %1, float noundef %2, float noundef %3) local_unnamed_addr #1 align 2 {
  %5 = icmp eq ptr %1, null
  br i1 %5, label %35, label %.preheader36

.preheader:                                       ; preds = %16
  %6 = fpext float %3 to double
  br label %19

.preheader36:                                     ; preds = %4, %16
  %indvars.iv = phi i64 [ %indvars.iv.next, %16 ], [ 1, %4 ]
  %.02738 = phi double [ %.1, %16 ], [ 0.000000e+00, %4 ]
  %7 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %8 = load float, ptr %7, align 4, !tbaa !5
  %9 = fcmp ogt float %8, 0.000000e+00
  br i1 %9, label %10, label %16

10:                                               ; preds = %.preheader36
  %11 = fpext float %8 to double
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = tail call noundef float @_ZN4xsec13getAtomicMassEi(ptr noundef nonnull align 8 dereferenceable(2400) %0, i32 noundef %12)
  %14 = fpext float %13 to double
  %15 = tail call double @llvm.fmuladd.f64(double %11, double %14, double %.02738)
  br label %16

16:                                               ; preds = %.preheader36, %10
  %.1 = phi double [ %15, %10 ], [ %.02738, %.preheader36 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 101
  br i1 %exitcond.not, label %.preheader, label %.preheader36, !llvm.loop !9

17:                                               ; preds = %34
  %18 = fptrunc double %.132 to float
  br label %35

19:                                               ; preds = %.preheader, %34
  %indvars.iv43 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next44, %34 ]
  %.03139 = phi double [ 0.000000e+00, %.preheader ], [ %.132, %34 ]
  %20 = getelementptr inbounds float, ptr %1, i64 %indvars.iv43
  %21 = load float, ptr %20, align 4, !tbaa !5
  %22 = fcmp ogt float %21, 0.000000e+00
  br i1 %22, label %23, label %34

23:                                               ; preds = %19
  %24 = trunc nuw nsw i64 %indvars.iv43 to i32
  %25 = tail call noundef float @_ZN8xscatter27coherentScatterDistributionEifd(ptr noundef nonnull align 8 dereferenceable(2456) %0, i32 noundef %24, float noundef %2, double noundef %6)
  %26 = tail call noundef float @_ZN4xsec13getAtomicMassEi(ptr noundef nonnull align 8 dereferenceable(2400) %0, i32 noundef %24)
  %27 = fpext float %26 to double
  %28 = load float, ptr %20, align 4, !tbaa !5
  %29 = fpext float %28 to double
  %30 = fmul double %27, %29
  %31 = fdiv double %30, %.1
  %32 = fpext float %25 to double
  %33 = tail call double @llvm.fmuladd.f64(double %31, double %32, double %.03139)
  br label %34

34:                                               ; preds = %19, %23
  %.132 = phi double [ %33, %23 ], [ %.03139, %19 ]
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next44, 101
  br i1 %exitcond46.not, label %17, label %19, !llvm.loop !11

35:                                               ; preds = %4, %17
  %.0 = phi float [ %18, %17 ], [ 0.000000e+00, %4 ]
  ret float %.0
}

declare noundef float @_ZN4xsec13getAtomicMassEi(ptr noundef nonnull align 8 dereferenceable(2400), i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass