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

; 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 nounwind uwtable
define dso_local noundef float @_ZN10xraySource3rjkEii(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store float 0.000000e+00, ptr %8, align 4, !tbaa !11
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %19

13:                                               ; preds = %3
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store float 0x401FD3F7C0000000, ptr %8, align 4, !tbaa !11
  br label %18

17:                                               ; preds = %13
  store float 0x4012CDD300000000, ptr %8, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %17, %16
  br label %50

19:                                               ; preds = %3
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store float 0x401BDF3B60000000, ptr %8, align 4, !tbaa !11
  br label %27

26:                                               ; preds = %22
  store float 0x40180B43A0000000, ptr %8, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %26, %25
  br label %49

28:                                               ; preds = %19
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 2
  br i1 %30, label %31, label %37

31:                                               ; preds = %28
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store float 0x4014126EA0000000, ptr %8, align 4, !tbaa !11
  br label %36

35:                                               ; preds = %31
  store float 0x40111EB860000000, ptr %8, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %35, %34
  br label %48

37:                                               ; preds = %28
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 3
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store float 0x4013A9FBE0000000, ptr %8, align 4, !tbaa !11
  br label %45

44:                                               ; preds = %40
  store float 0x400FE978E0000000, ptr %8, align 4, !tbaa !11
  br label %45

45:                                               ; preds = %44, %43
  br label %47

46:                                               ; preds = %37
  store float 0.000000e+00, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %58

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47, %36
  br label %49

49:                                               ; preds = %48, %27
  br label %50

50:                                               ; preds = %49, %18
  %51 = load float, ptr %8, align 4, !tbaa !11
  %52 = fpext float %51 to double
  %53 = fsub double %52, 1.000000e+00
  %54 = load float, ptr %8, align 4, !tbaa !11
  %55 = fpext float %54 to double
  %56 = fdiv double %53, %55
  %57 = fptrunc double %56 to float
  store float %57, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %58

58:                                               ; preds = %50, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %59 = load float, ptr %4, align 4
  ret float %59
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}


; 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(none) uwtable
define dso_local noundef float @_ZN10xraySource3rjkEii(ptr nocapture noundef nonnull readnone align 8 dereferenceable(48) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  switch i32 %1, label %16 [
    i32 0, label %4
    i32 1, label %6
    i32 2, label %8
    i32 3, label %10
  ]

4:                                                ; preds = %3
  %5 = icmp eq i32 %2, 0
  %. = select i1 %5, double 0x401FD3F7C0000000, double 0x4012CDD300000000
  br label %12

6:                                                ; preds = %3
  %7 = icmp eq i32 %2, 0
  %.13 = select i1 %7, double 0x401BDF3B60000000, double 0x40180B43A0000000
  br label %12

8:                                                ; preds = %3
  %9 = icmp eq i32 %2, 0
  %.14 = select i1 %9, double 0x4014126EA0000000, double 0x40111EB860000000
  br label %12

10:                                               ; preds = %3
  %11 = icmp eq i32 %2, 0
  %.15 = select i1 %11, double 0x4013A9FBE0000000, double 0x400FE978E0000000
  br label %12

12:                                               ; preds = %10, %8, %6, %4
  %.0 = phi double [ %., %4 ], [ %.13, %6 ], [ %.14, %8 ], [ %.15, %10 ]
  %13 = fadd double %.0, -1.000000e+00
  %14 = fdiv double %13, %.0
  %15 = fptrunc double %14 to float
  br label %16

16:                                               ; preds = %3, %12
  %.011 = phi float [ %15, %12 ], [ 0.000000e+00, %3 ]
  ret float %.011
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass