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

; 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 @_ZN8xscatter29incoherentScatterDistributionEiff(ptr noundef nonnull align 8 dereferenceable(2456), i32 noundef, float noundef, float noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter29incoherentScatterDistributionEPfff(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 %97

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 = %91, %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 %94

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 %90

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

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

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

94:                                               ; preds = %55
  %95 = load double, ptr %12, align 8, !tbaa !11
  %96 = fptrunc double %95 to float
  store float %96, 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 %97

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

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 @_ZN8xscatter29incoherentScatterDistributionEiff(ptr noundef nonnull align 8 dereferenceable(2456), i32 noundef, float noundef, float noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter29incoherentScatterDistributionEPfff(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 %33, label %.preheader36

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

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

15:                                               ; preds = %.preheader36, %9
  %.1 = phi double [ %14, %9 ], [ %.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

16:                                               ; preds = %32
  %17 = fptrunc double %.132 to float
  br label %33

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

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

32:                                               ; preds = %.preheader, %21
  %.132 = phi double [ %31, %21 ], [ %.03139, %.preheader ]
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next44, 101
  br i1 %exitcond46.not, label %16, label %.preheader, !llvm.loop !11

33:                                               ; preds = %4, %16
  %.0 = phi float [ %17, %16 ], [ 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,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass