; LLVM IR from kylechampley/XrayPhysics :: src/xsec.ll (ZN4xsec5sigmaEPffi)

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

@_ZL10atomicMass = external hidden constant [101 x float], align 16

; 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 float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN4xsec5sigmaEPffi(ptr noundef nonnull align 8 dereferenceable(2400) %0, ptr noundef %1, float noundef %2, i32 noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store float %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !11
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store float 0.000000e+00, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store float 0.000000e+00, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 1, ptr %11, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %54, %4
  %14 = load i32, ptr %11, align 4, !tbaa !11
  %15 = icmp sle i32 %14, 100
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %57

17:                                               ; preds = %13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %11, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds float, ptr %18, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !9
  %23 = fpext float %22 to double
  %24 = fcmp ogt double %23, 0.000000e+00
  br i1 %24, label %25, label %53

25:                                               ; preds = %17
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %11, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds float, ptr %26, i64 %28
  %30 = load float, ptr %29, align 4, !tbaa !9
  %31 = load i32, ptr %11, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [101 x float], ptr @_ZL10atomicMass, i64 0, i64 %32
  %34 = load float, ptr %33, align 4, !tbaa !9
  %35 = load float, ptr %9, align 4, !tbaa !9
  %36 = call float @llvm.fmuladd.f32(float %30, float %34, float %35)
  store float %36, ptr %9, align 4, !tbaa !9
  %37 = load i32, ptr %11, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [101 x float], ptr @_ZL10atomicMass, i64 0, i64 %38
  %40 = load float, ptr %39, align 4, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds float, ptr %41, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !9
  %46 = fmul float %40, %45
  %47 = load i32, ptr %11, align 4, !tbaa !11
  %48 = load float, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !11
  %50 = call noundef float @_ZN4xsec5sigmaEifi(ptr noundef nonnull align 8 dereferenceable(2400) %12, i32 noundef %47, float noundef %48, i32 noundef %49)
  %51 = load float, ptr %10, align 4, !tbaa !9
  %52 = call float @llvm.fmuladd.f32(float %46, float %50, float %51)
  store float %52, ptr %10, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %25, %17
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %11, align 4, !tbaa !11
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %11, align 4, !tbaa !11
  br label %13, !llvm.loop !13

57:                                               ; preds = %16
  %58 = load float, ptr %9, align 4, !tbaa !9
  %59 = load float, ptr %10, align 4, !tbaa !9
  %60 = fdiv float %59, %58
  store float %60, ptr %10, align 4, !tbaa !9
  %61 = load float, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret float %61
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN4xsec5sigmaEifi(ptr noundef nonnull align 8 dereferenceable(2400), i32 noundef, float noundef, i32 noundef) #2 align 2

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 = { 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 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@_ZL10atomicMass = external hidden local_unnamed_addr constant [101 x float], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN4xsec5sigmaEPffi(ptr noundef nonnull align 8 dereferenceable(2400) %0, ptr nocapture noundef readonly %1, float noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  br label %9

5:                                                ; preds = %25
  %6 = extractelement <2 x float> %26, i64 0
  %7 = extractelement <2 x float> %26, i64 1
  %8 = fdiv float %7, %6
  ret float %8

9:                                                ; preds = %4, %25
  %indvars.iv = phi i64 [ 1, %4 ], [ %indvars.iv.next, %25 ]
  %10 = phi <2 x float> [ zeroinitializer, %4 ], [ %26, %25 ]
  %11 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %12 = load float, ptr %11, align 4, !tbaa !5
  %13 = fcmp ogt float %12, 0.000000e+00
  br i1 %13, label %14, label %25

14:                                               ; preds = %9
  %15 = getelementptr inbounds [101 x float], ptr @_ZL10atomicMass, i64 0, i64 %indvars.iv
  %16 = load float, ptr %15, align 4, !tbaa !5
  %17 = fmul float %12, %16
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  %19 = tail call noundef float @_ZN4xsec5sigmaEifi(ptr noundef nonnull align 8 dereferenceable(2400) %0, i32 noundef %18, float noundef %2, i32 noundef %3)
  %20 = insertelement <2 x float> poison, float %12, i64 0
  %21 = insertelement <2 x float> %20, float %17, i64 1
  %22 = insertelement <2 x float> poison, float %16, i64 0
  %23 = insertelement <2 x float> %22, float %19, i64 1
  %24 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %21, <2 x float> %23, <2 x float> %10)
  br label %25

25:                                               ; preds = %9, %14
  %26 = phi <2 x float> [ %24, %14 ], [ %10, %9 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 101
  br i1 %exitcond.not, label %5, label %9, !llvm.loop !9
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN4xsec5sigmaEifi(ptr noundef nonnull align 8 dereferenceable(2400), i32 noundef, float noundef, i32 noundef) local_unnamed_addr #0 align 2

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

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

!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"}


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