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

; 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: mustprogress uwtable
declare dso_local noundef float @_ZN4xsec5sigmaEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400), ptr noundef, float noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN4xsec9sigma_invEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400) %0, ptr noundef %1, float noundef %2, i32 noundef %3) #1 align 2 {
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store float %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !11
  %18 = call noundef float @_ZN4xsec5sigmaEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400) %15, ptr noundef %16, float noundef 1.000000e+00, i32 noundef %17)
  store float %18, ptr %10, align 4, !tbaa !9
  %19 = load float, ptr %8, align 4, !tbaa !9
  %20 = load float, ptr %10, align 4, !tbaa !9
  %21 = fcmp oge float %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  store float 1.000000e+00, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %64

23:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %24 = load float, ptr %10, align 4, !tbaa !9
  store float %24, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 1, ptr %13, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %57, %23
  %26 = load i32, ptr %13, align 4, !tbaa !11
  %27 = icmp slt i32 %26, 20000
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 2, ptr %11, align 4
  br label %60

29:                                               ; preds = %25
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i32, ptr %13, align 4, !tbaa !11
  %32 = add nsw i32 %31, 1
  %33 = sitofp i32 %32 to float
  %34 = load i32, ptr %9, align 4, !tbaa !11
  %35 = call noundef float @_ZN4xsec5sigmaEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400) %15, ptr noundef %30, float noundef %33, i32 noundef %34)
  store float %35, ptr %12, align 4, !tbaa !9
  %36 = load float, ptr %10, align 4, !tbaa !9
  %37 = load float, ptr %8, align 4, !tbaa !9
  %38 = fcmp oge float %36, %37
  br i1 %38, label %39, label %55

39:                                               ; preds = %29
  %40 = load float, ptr %8, align 4, !tbaa !9
  %41 = load float, ptr %12, align 4, !tbaa !9
  %42 = fcmp oge float %40, %41
  br i1 %42, label %43, label %55

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %44 = load float, ptr %10, align 4, !tbaa !9
  %45 = load float, ptr %8, align 4, !tbaa !9
  %46 = fsub float %44, %45
  %47 = load float, ptr %10, align 4, !tbaa !9
  %48 = load float, ptr %12, align 4, !tbaa !9
  %49 = fsub float %47, %48
  %50 = fdiv float %46, %49
  store float %50, ptr %14, align 4, !tbaa !9
  %51 = load i32, ptr %13, align 4, !tbaa !11
  %52 = sitofp i32 %51 to float
  %53 = load float, ptr %14, align 4, !tbaa !9
  %54 = fadd float %52, %53
  store float %54, ptr %5, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %60

55:                                               ; preds = %39, %29
  %56 = load float, ptr %12, align 4, !tbaa !9
  store float %56, ptr %10, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %55
  %58 = load i32, ptr %13, align 4, !tbaa !11
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %13, align 4, !tbaa !11
  br label %25, !llvm.loop !13

60:                                               ; preds = %43, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  %61 = load i32, ptr %11, align 4
  switch i32 %61, label %63 [
    i32 2, label %62
  ]

62:                                               ; preds = %60
  store float 2.000000e+04, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

63:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %64

64:                                               ; preds = %63, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %65 = load float, ptr %5, align 4
  ret float %65
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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
declare dso_local noundef float @_ZN4xsec5sigmaEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400), ptr noundef, float noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN4xsec9sigma_invEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400) %0, ptr noundef %1, float noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = tail call noundef float @_ZN4xsec5sigmaEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400) %0, ptr noundef %1, float noundef 1.000000e+00, i32 noundef %3)
  %6 = fcmp ugt float %5, %2
  br i1 %6, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %4, %7
  %.025 = phi float [ %10, %7 ], [ %5, %4 ]
  %.023 = phi i32 [ %8, %7 ], [ 1, %4 ]
  %exitcond = icmp eq i32 %.023, 20000
  br i1 %exitcond, label %.loopexit, label %7

7:                                                ; preds = %.preheader
  %8 = add nuw nsw i32 %.023, 1
  %9 = uitofp nneg i32 %8 to float
  %10 = tail call noundef float @_ZN4xsec5sigmaEPKcfi(ptr noundef nonnull align 8 dereferenceable(2400) %0, ptr noundef %1, float noundef %9, i32 noundef %3)
  %11 = fcmp ult float %.025, %2
  %12 = fcmp ugt float %10, %2
  %or.cond = or i1 %11, %12
  br i1 %or.cond, label %.preheader, label %13, !llvm.loop !5

13:                                               ; preds = %7
  %14 = fsub float %.025, %2
  %15 = fsub float %.025, %10
  %16 = fdiv float %14, %15
  %17 = uitofp nneg i32 %.023 to float
  %18 = fadd float %16, %17
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %13, %4
  %.2 = phi float [ 1.000000e+00, %4 ], [ %18, %13 ], [ 2.000000e+04, %.preheader ]
  ret float %.2
}

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

!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,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass