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

; 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: nounwind
declare double @cos(double noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEifd(ptr noundef nonnull align 8 dereferenceable(2456) %0, i32 noundef %1, float noundef %2, double noundef %3) #3 align 2 {
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store float %2, ptr %8, align 4, !tbaa !11
  store double %3, ptr %9, align 8, !tbaa !13
  %11 = load ptr, ptr %6, align 8
  %12 = load float, ptr %8, align 4, !tbaa !11
  %13 = fpext float %12 to double
  %14 = fcmp olt double %13, 0.000000e+00
  br i1 %14, label %21, label %15

15:                                               ; preds = %4
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 1
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp sgt i32 %19, 100
  br i1 %20, label %21, label %22

21:                                               ; preds = %18, %15, %4
  store float 0.000000e+00, ptr %5, align 4
  br label %40

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %23 = load float, ptr %8, align 4, !tbaa !11
  %24 = fpext float %23 to double
  %25 = load double, ptr %9, align 8, !tbaa !13
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = call noundef double @_ZN8xscatter21getCoherentFormFactorEddi(ptr noundef nonnull align 8 dereferenceable(2456) %11, double noundef %24, double noundef %25, i32 noundef %26)
  store double %27, ptr %10, align 8, !tbaa !13
  %28 = getelementptr inbounds %class.xscatter, ptr %11, i32 0, i32 5
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = fmul double 5.000000e-01, %29
  %31 = load double, ptr %9, align 8, !tbaa !13
  %32 = call double @cos(double noundef %31) #4
  %33 = load double, ptr %9, align 8, !tbaa !13
  %34 = call double @cos(double noundef %33) #4
  %35 = call double @llvm.fmuladd.f64(double %32, double %34, double 1.000000e+00)
  %36 = fmul double %30, %35
  %37 = load double, ptr %10, align 8, !tbaa !13
  %38 = fmul double %36, %37
  %39 = fptrunc double %38 to float
  store float %39, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %40

40:                                               ; preds = %22, %21
  %41 = load float, ptr %5, align 4
  ret float %41
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !14, i64 2448}
!16 = !{!"_ZTS8xscatter", !17, i64 0, !22, i64 2400, !14, i64 2424, !14, i64 2432, !14, i64 2440, !14, i64 2448}
!17 = !{!"_ZTS4xsec", !7, i64 0, !18, i64 408, !18, i64 432, !18, i64 456, !7, i64 480, !18, i64 888, !18, i64 912, !18, i64 936, !7, i64 960, !18, i64 1368, !18, i64 1392, !18, i64 1416, !7, i64 1440, !18, i64 1848, !18, i64 1872, !18, i64 1896, !7, i64 1920, !18, i64 2328, !18, i64 2352, !18, i64 2376}
!18 = !{!"_ZTSSt6vectorIPfSaIS0_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIPfSaIS0_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIPfSaIS0_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIPfSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!"_ZTSSt6vectorIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIN8xscatter44IncoherentAndCoherentScatterFunctions_elem_sESaIS1_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_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 nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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 double @_ZN8xscatter21getCoherentFormFactorEddi(ptr noundef nonnull align 8 dereferenceable(2456), double noundef, double noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEifd(ptr noundef nonnull align 8 dereferenceable(2456) %0, i32 noundef %1, float noundef %2, double noundef %3) local_unnamed_addr #2 align 2 {
  %5 = fcmp olt float %2, 0.000000e+00
  %6 = add i32 %1, -101
  %7 = icmp ult i32 %6, -100
  %or.cond3 = or i1 %5, %7
  br i1 %or.cond3, label %20, label %8

8:                                                ; preds = %4
  %9 = fpext float %2 to double
  %10 = tail call noundef double @_ZN8xscatter21getCoherentFormFactorEddi(ptr noundef nonnull align 8 dereferenceable(2456) %0, double noundef %9, double noundef %3, i32 noundef %1)
  %11 = getelementptr inbounds i8, ptr %0, i64 2448
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = fmul double %12, 5.000000e-01
  %14 = tail call double @cos(double noundef %3) #3
  %15 = tail call double @cos(double noundef %3) #3
  %16 = tail call double @llvm.fmuladd.f64(double %14, double %15, double 1.000000e+00)
  %17 = fmul double %13, %16
  %18 = fmul double %10, %17
  %19 = fptrunc double %18 to float
  br label %20

20:                                               ; preds = %4, %8
  %.0 = phi float [ %19, %8 ], [ 0.000000e+00, %4 ]
  ret float %.0
}

attributes #0 = { 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 #1 = { mustprogress 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 = { 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 2448}
!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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass