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

; 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_normalizationFactorEPff(ptr noundef nonnull align 8 dereferenceable(2456) %0, ptr noundef %1, float noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %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 ptr %1, ptr %5, align 8, !tbaa !5
  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 = %43, %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 %46

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 ptr, ptr %5, align 8, !tbaa !5
  %29 = load float, ptr %6, align 4, !tbaa !9
  %30 = load double, ptr %11, align 8, !tbaa !11
  %31 = fptrunc double %30 to float
  %32 = call noundef float @_ZN8xscatter27coherentScatterDistributionEPfff(ptr noundef nonnull align 8 dereferenceable(2456) %12, ptr noundef %28, float noundef %29, float noundef %31)
  %33 = fpext float %32 to double
  %34 = load double, ptr %8, align 8, !tbaa !11
  %35 = fmul double %33, %34
  %36 = load double, ptr %11, align 8, !tbaa !11
  %37 = call double @sin(double noundef %36) #4
  %38 = call double @llvm.fabs.f64(double %37)
  %39 = fmul double %35, %38
  %40 = fmul double %39, 2.000000e+00
  %41 = load double, ptr %7, align 8, !tbaa !11
  %42 = call double @llvm.fmuladd.f64(double %40, double 0x400921FB54442D18, double %41)
  store double %42, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %43

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

46:                                               ; preds = %22
  %47 = load double, ptr %7, align 8, !tbaa !11
  %48 = fptrunc double %47 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 %48
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEPfff(ptr noundef nonnull align 8 dereferenceable(2456), ptr noundef, float noundef, float 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_normalizationFactorEPff(ptr noundef nonnull align 8 dereferenceable(2456) %0, ptr noundef %1, float noundef %2) local_unnamed_addr #2 align 2 {
  br label %6

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN8xscatter27coherentScatterDistributionEPfff(ptr noundef nonnull align 8 dereferenceable(2456), ptr noundef, float noundef, float 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