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

; 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"

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter47coherentScatterDistribution_normalizationFactorEff(ptr noundef nonnull align 8 dereferenceable(2456) %0, float noundef %1, float noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0x3F5C987103B761F5, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %13 = load double, ptr %8, align 8, !tbaa !11
  %14 = fdiv double 0x400921FB54442D18, %13
  %15 = fadd double 5.000000e-01, %14
  %16 = call double @llvm.floor.f64(double %15)
  %17 = fptosi double %16 to i32
  store i32 %17, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %18

18:                                               ; preds = %42, %3
  %19 = load i32, ptr %10, align 4, !tbaa !13
  %20 = load i32, ptr %9, align 4, !tbaa !13
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %45

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = load double, ptr %8, align 8, !tbaa !11
  %25 = load i32, ptr %10, align 4, !tbaa !13
  %26 = sitofp i32 %25 to double
  %27 = fmul double %24, %26
  store double %27, ptr %11, align 8, !tbaa !11
  %28 = load float, ptr %5, align 4, !tbaa !9
  %29 = load float, ptr %6, align 4, !tbaa !9
  %30 = load double, ptr %11, align 8, !tbaa !11
  %31 = call noundef float @_ZN8xscatter27coherentScatterDistributionEffd(ptr noundef nonnull align 8 dereferenceable(2456) %12, float noundef %28, float noundef %29, double noundef %30)
  %32 = fpext float %31 to double
  %33 = load double, ptr %8, align 8, !tbaa !11
  %34 = fmul double %32, %33
  %35 = load double, ptr %11, align 8, !tbaa !11
  %36 = call double @sin(double noundef %35) #4
  %37 = call double @llvm.fabs.f64(double %36)
  %38 = fmul double %34, %37
  %39 = fmul double %38, 2.000000e+00
  %40 = load double, ptr %7, align 8, !tbaa !11
  %41 = call double @llvm.fmuladd.f64(double %39, double 0x400921FB54442D18, double %40)
  store double %41, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %42

42:                                               ; preds = %23
  %43 = load i32, ptr %10, align 4, !tbaa !13
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %10, align 4, !tbaa !13
  br label %18, !llvm.loop !15

45:                                               ; preds = %22
  %46 = load double, ptr %7, align 8, !tbaa !11
  %47 = fptrunc double %46 to float
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret float %47
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"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"}


; 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)
declare double @sin(double noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN8xscatter47coherentScatterDistribution_normalizationFactorEff(ptr noundef nonnull align 8 dereferenceable(2456) %0, float noundef %1, float noundef %2) local_unnamed_addr #2 align 2 {
  br label %6

4:                                                ; preds = %6
  %5 = fptrunc double %16 to float
  ret float %5

6:                                                ; preds = %3, %6
  %.015 = phi double [ 0.000000e+00, %3 ], [ %16, %6 ]
  %.01314 = phi i32 [ 0, %3 ], [ %17, %6 ]
  %7 = uitofp nneg i32 %.01314 to double
  %8 = fmul double %7, 0x3F5C987103B761F5
  %9 = tail call noundef float @_ZN8xscatter27coherentScatterDistributionEffd(ptr noundef nonnull align 8 dereferenceable(2456) %0, float noundef %1, float noundef %2, double noundef %8)
  %10 = fpext float %9 to double
  %11 = fmul double %10, 0x3F5C987103B761F5
  %12 = tail call double @sin(double noundef %8) #3
  %13 = tail call double @llvm.fabs.f64(double %12)
  %14 = fmul double %11, %13
  %15 = fmul double %14, 2.000000e+00
  %16 = tail call double @llvm.fmuladd.f64(double %15, double 0x400921FB54442D18, double %.015)
  %17 = add nuw nsw i32 %.01314, 1
  %exitcond.not = icmp eq i32 %17, 1800
  br i1 %exitcond.not, label %4, label %6, !llvm.loop !5
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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