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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN4xsec7sigma_eEPffi(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 = %50, %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 %53

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 %49

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 = sitofp i32 %31 to float
  %33 = load float, ptr %9, align 4, !tbaa !9
  %34 = call float @llvm.fmuladd.f32(float %30, float %32, float %33)
  store float %34, ptr %9, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !11
  %36 = sitofp i32 %35 to float
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i32, ptr %11, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %37, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !9
  %42 = fmul float %36, %41
  %43 = load i32, ptr %11, align 4, !tbaa !11
  %44 = load float, ptr %7, align 4, !tbaa !9
  %45 = load i32, ptr %8, align 4, !tbaa !11
  %46 = call noundef float @_ZN4xsec7sigma_eEifi(ptr noundef nonnull align 8 dereferenceable(2400) %12, i32 noundef %43, float noundef %44, i32 noundef %45)
  %47 = load float, ptr %10, align 4, !tbaa !9
  %48 = call float @llvm.fmuladd.f32(float %42, float %46, float %47)
  store float %48, ptr %10, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %25, %17
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %11, align 4, !tbaa !11
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %11, align 4, !tbaa !11
  br label %13, !llvm.loop !13

53:                                               ; preds = %16
  %54 = load float, ptr %9, align 4, !tbaa !9
  %55 = load float, ptr %10, align 4, !tbaa !9
  %56 = fdiv float %55, %54
  store float %56, ptr %10, align 4, !tbaa !9
  %57 = 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 %57
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN4xsec7sigma_eEifi(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"

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN4xsec7sigma_eEPffi(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 = %24
  %6 = extractelement <2 x float> %25, i64 0
  %7 = extractelement <2 x float> %25, i64 1
  %8 = fdiv float %7, %6
  ret float %8

9:                                                ; preds = %4, %24
  %indvars.iv = phi i64 [ 1, %4 ], [ %indvars.iv.next, %24 ]
  %10 = phi <2 x float> [ zeroinitializer, %4 ], [ %25, %24 ]
  %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 %24

14:                                               ; preds = %9
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  %16 = uitofp nneg i32 %15 to float
  %17 = fmul float %12, %16
  %18 = tail call noundef float @_ZN4xsec7sigma_eEifi(ptr noundef nonnull align 8 dereferenceable(2400) %0, i32 noundef %15, float noundef %2, i32 noundef %3)
  %19 = insertelement <2 x float> poison, float %12, i64 0
  %20 = insertelement <2 x float> %19, float %17, i64 1
  %21 = insertelement <2 x float> poison, float %16, i64 0
  %22 = insertelement <2 x float> %21, float %18, i64 1
  %23 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %20, <2 x float> %22, <2 x float> %10)
  br label %24

24:                                               ; preds = %9, %14
  %25 = phi <2 x float> [ %23, %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 @_ZN4xsec7sigma_eEifi(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