; LLVM IR from kylechampley/XrayPhysics :: src/xsource.ll (ZN10xraySource9gamma_invEf)

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

%class.xraySource = type { float, i32, float, ptr, i32, float, float, ptr }

; 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 nounwind uwtable
define dso_local noundef float @_ZN10xraySource9gamma_invEf(ptr noundef nonnull align 8 dereferenceable(48) %0, float noundef %1) #1 align 2 {
  %3 = alloca float, align 4
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load float, ptr %5, align 4, !tbaa !9
  %11 = getelementptr inbounds %class.xraySource, ptr %9, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds float, ptr %12, i64 0
  %14 = load float, ptr %13, align 4, !tbaa !9
  %15 = fcmp ole float %10, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store float 0.000000e+00, ptr %3, align 4
  br label %74

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %64, %17
  %19 = load i32, ptr %6, align 4, !tbaa !14
  %20 = getelementptr inbounds %class.xraySource, ptr %9, i32 0, i32 4
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i32 2, ptr %7, align 4
  br label %67

24:                                               ; preds = %18
  %25 = load float, ptr %5, align 4, !tbaa !9
  %26 = getelementptr inbounds %class.xraySource, ptr %9, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %6, align 4, !tbaa !14
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds float, ptr %27, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !9
  %32 = fcmp ole float %25, %31
  br i1 %32, label %33, label %63

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %34 = load float, ptr %5, align 4, !tbaa !9
  %35 = getelementptr inbounds %class.xraySource, ptr %9, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = load i32, ptr %6, align 4, !tbaa !14
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %36, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !9
  %42 = fsub float %34, %41
  %43 = getelementptr inbounds %class.xraySource, ptr %9, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = load i32, ptr %6, align 4, !tbaa !14
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %44, i64 %46
  %48 = load float, ptr %47, align 4, !tbaa !9
  %49 = getelementptr inbounds %class.xraySource, ptr %9, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = load i32, ptr %6, align 4, !tbaa !14
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %50, i64 %53
  %55 = load float, ptr %54, align 4, !tbaa !9
  %56 = fsub float %48, %55
  %57 = fdiv float %42, %56
  store float %57, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !14
  %59 = sub nsw i32 %58, 1
  %60 = sitofp i32 %59 to float
  %61 = load float, ptr %8, align 4, !tbaa !9
  %62 = fadd float %60, %61
  store float %62, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %67

63:                                               ; preds = %24
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %6, align 4, !tbaa !14
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !14
  br label %18, !llvm.loop !16

67:                                               ; preds = %33, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %68 = load i32, ptr %7, align 4
  switch i32 %68, label %76 [
    i32 2, label %69
    i32 1, label %74
  ]

69:                                               ; preds = %67
  %70 = getelementptr inbounds %class.xraySource, ptr %9, i32 0, i32 4
  %71 = load i32, ptr %70, align 8, !tbaa !15
  %72 = sub nsw i32 %71, 1
  %73 = sitofp i32 %72 to float
  store float %73, ptr %3, align 4
  br label %74

74:                                               ; preds = %69, %67, %16
  %75 = load float, ptr %3, align 4
  ret float %75

76:                                               ; preds = %67
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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, !6, i64 16}
!12 = !{!"_ZTS10xraySource", !10, i64 0, !13, i64 4, !10, i64 8, !6, i64 16, !13, i64 24, !10, i64 28, !10, i64 32, !6, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef float @_ZN10xraySource9gamma_invEf(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0, float noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load float, ptr %4, align 4, !tbaa !12
  %6 = fcmp ult float %5, %1
  br i1 %6, label %.preheader, label %27

.preheader:                                       ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = icmp sgt i32 %8, 1
  br i1 %9, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %8 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %13
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %13 ]
  %10 = getelementptr inbounds float, ptr %4, i64 %indvars.iv
  %11 = load float, ptr %10, align 4, !tbaa !12
  %12 = fcmp ult float %11, %1
  br i1 %12, label %13, label %14

13:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

14:                                               ; preds = %.lr.ph
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  %16 = add nsw i32 %15, -1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds float, ptr %4, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !12
  %20 = fsub float %1, %19
  %21 = fsub float %11, %19
  %22 = fdiv float %20, %21
  %23 = sitofp i32 %16 to float
  %24 = fadd float %22, %23
  br label %27

._crit_edge:                                      ; preds = %13, %.preheader
  %25 = add nsw i32 %8, -1
  %26 = sitofp i32 %25 to float
  br label %27

27:                                               ; preds = %14, %2, %._crit_edge
  %.1 = phi float [ %24, %14 ], [ %26, %._crit_edge ], [ 0.000000e+00, %2 ]
  ret float %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 = !{!6, !11, i64 16}
!6 = !{!"_ZTS10xraySource", !7, i64 0, !10, i64 4, !7, i64 8, !11, i64 16, !10, i64 24, !7, i64 28, !7, i64 32, !11, i64 40}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass