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

; 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 nounwind uwtable
define dso_local noundef double @_ZN8xscatter24KleinNishinaCrossSectionEd(ptr noundef nonnull align 8 dereferenceable(2456) %0, double noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = fdiv double %10, 5.109750e+02
  store double %11, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = load double, ptr %5, align 8, !tbaa !9
  %13 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %12, double 1.000000e+00)
  store double %13, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load double, ptr %6, align 8, !tbaa !9
  %15 = call double @log(double noundef %14) #4
  store double %15, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %16 = load double, ptr %6, align 8, !tbaa !9
  %17 = fadd double 1.000000e+00, %16
  %18 = load double, ptr %6, align 8, !tbaa !9
  %19 = fmul double 2.000000e+00, %18
  %20 = load double, ptr %6, align 8, !tbaa !9
  %21 = fmul double %19, %20
  %22 = fdiv double %17, %21
  %23 = load double, ptr %5, align 8, !tbaa !9
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = call double @llvm.fmuladd.f64(double %23, double %24, double -1.000000e+00)
  %26 = load double, ptr %6, align 8, !tbaa !9
  %27 = fsub double %25, %26
  %28 = load double, ptr %7, align 8, !tbaa !9
  %29 = load double, ptr %5, align 8, !tbaa !9
  %30 = fmul double 4.000000e+00, %29
  %31 = call double @llvm.fmuladd.f64(double %27, double %28, double %30)
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = fmul double 2.000000e+00, %32
  %34 = load double, ptr %5, align 8, !tbaa !9
  %35 = fmul double %33, %34
  %36 = load double, ptr %5, align 8, !tbaa !9
  %37 = fmul double %35, %36
  %38 = fdiv double %31, %37
  %39 = fadd double %22, %38
  store double %39, ptr %8, align 8, !tbaa !9
  %40 = load double, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds %class.xscatter, ptr %9, i32 0, i32 3
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fmul double %40, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret double %43
}

; Function Attrs: nounwind
declare double @log(double 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 nounwind 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 = { nounwind "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 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 2432}
!12 = !{!"_ZTS8xscatter", !13, i64 0, !18, i64 2400, !10, i64 2424, !10, i64 2432, !10, i64 2440, !10, i64 2448}
!13 = !{!"_ZTS4xsec", !7, i64 0, !14, i64 408, !14, i64 432, !14, i64 456, !7, i64 480, !14, i64 888, !14, i64 912, !14, i64 936, !7, i64 960, !14, i64 1368, !14, i64 1392, !14, i64 1416, !7, i64 1440, !14, i64 1848, !14, i64 1872, !14, i64 1896, !7, i64 1920, !14, i64 2328, !14, i64 2352, !14, i64 2376}
!14 = !{!"_ZTSSt6vectorIPfSaIS0_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIPfSaIS0_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPfSaIS0_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPfSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"_ZTSSt6vectorIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 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 nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local noundef double @_ZN8xscatter24KleinNishinaCrossSectionEd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(2456) %0, double noundef %1) local_unnamed_addr #1 align 2 {
  %3 = fdiv double %1, 5.109750e+02
  %4 = insertelement <2 x double> poison, double %3, i64 0
  %5 = shufflevector <2 x double> %4, <2 x double> poison, <2 x i32> zeroinitializer
  %6 = insertelement <2 x double> %5, double 2.000000e+00, i64 1
  %7 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %5, <2 x double> %6, <2 x double> <double -1.000000e+00, double 1.000000e+00>)
  %8 = extractelement <2 x double> %7, i64 1
  %9 = tail call double @log(double noundef %8) #4
  %10 = fadd double %8, 1.000000e+00
  %11 = fmul double %8, 2.000000e+00
  %12 = fmul double %8, %11
  %13 = fdiv double %10, %12
  %14 = extractelement <2 x double> %7, i64 0
  %15 = fsub double %14, %8
  %16 = fmul double %3, 4.000000e+00
  %17 = tail call double @llvm.fmuladd.f64(double %15, double %9, double %16)
  %18 = fmul double %3, 2.000000e+00
  %19 = fmul double %3, %18
  %20 = fmul double %3, %19
  %21 = fdiv double %17, %20
  %22 = fadd double %13, %21
  %23 = getelementptr inbounds i8, ptr %0, i64 2432
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fmul double %24, %22
  ret double %25
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) 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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !19, i64 2432}
!6 = !{!"_ZTS8xscatter", !7, i64 0, !15, i64 2400, !19, i64 2424, !19, i64 2432, !19, i64 2440, !19, i64 2448}
!7 = !{!"_ZTS4xsec", !8, i64 0, !10, i64 408, !10, i64 432, !10, i64 456, !8, i64 480, !10, i64 888, !10, i64 912, !10, i64 936, !8, i64 960, !10, i64 1368, !10, i64 1392, !10, i64 1416, !8, i64 1440, !10, i64 1848, !10, i64 1872, !10, i64 1896, !8, i64 1920, !10, i64 2328, !10, i64 2352, !10, i64 2376}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIPfSaIS0_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIPfSaIS0_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIPfSaIS0_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIPfSaIS0_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"_ZTSSt6vectorIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!19 = !{!"double", !8, i64 0}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass