; LLVM IR from sp-nitech/SPTK :: third_party/REAPER/core/track.ll (ZNK4sptk6reaper5Track5IndexEf)

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6reaper5Track10num_framesEv(ptr noundef nonnull align 8 dereferenceable(72)) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK4sptk6reaper5Track5IndexEf(ptr noundef nonnull align 8 dereferenceable(72) %0, float noundef %1) #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = call noundef i32 @_ZNK4sptk6reaper5Track10num_framesEv(ptr noundef nonnull align 8 dereferenceable(72) %10)
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %13, label %81

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1, ptr %6, align 4, !tbaa !11
  %14 = call noundef i32 @_ZNK4sptk6reaper5Track10num_framesEv(ptr noundef nonnull align 8 dereferenceable(72) %10)
  store i32 %14, ptr %8, align 4, !tbaa !11
  %15 = load float, ptr %5, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !11
  %17 = call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %10, i32 noundef %16)
  %18 = fcmp olt float %15, %17
  br i1 %18, label %19, label %21

19:                                               ; preds = %13
  %20 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %20, ptr %7, align 4, !tbaa !11
  br label %21

21:                                               ; preds = %19, %13
  %22 = load float, ptr %5, align 4, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = sub nsw i32 %23, 1
  %25 = call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %10, i32 noundef %24)
  %26 = fcmp oge float %22, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %21
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = sub nsw i32 %28, 1
  store i32 %29, ptr %7, align 4, !tbaa !11
  br label %62

30:                                               ; preds = %21
  br label %31

31:                                               ; preds = %60, %30
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %6, align 4, !tbaa !11
  %34 = load i32, ptr %8, align 4, !tbaa !11
  %35 = load i32, ptr %6, align 4, !tbaa !11
  %36 = sub nsw i32 %34, %35
  %37 = sdiv i32 %36, 2
  %38 = add nsw i32 %33, %37
  store i32 %38, ptr %7, align 4, !tbaa !11
  %39 = load i32, ptr %6, align 4, !tbaa !11
  %40 = load i32, ptr %7, align 4, !tbaa !11
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %32
  br label %61

43:                                               ; preds = %32
  %44 = load float, ptr %5, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !11
  %46 = call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %10, i32 noundef %45)
  %47 = fcmp olt float %44, %46
  br i1 %47, label %48, label %57

48:                                               ; preds = %43
  %49 = load float, ptr %5, align 4, !tbaa !9
  %50 = load i32, ptr %7, align 4, !tbaa !11
  %51 = sub nsw i32 %50, 1
  %52 = call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %10, i32 noundef %51)
  %53 = fcmp oge float %49, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %48
  br label %61

55:                                               ; preds = %48
  %56 = load i32, ptr %7, align 4, !tbaa !11
  store i32 %56, ptr %8, align 4, !tbaa !11
  br label %59

57:                                               ; preds = %43
  %58 = load i32, ptr %7, align 4, !tbaa !11
  store i32 %58, ptr %6, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %57, %55
  br label %60

60:                                               ; preds = %59
  br label %31, !llvm.loop !13

61:                                               ; preds = %54, %42
  br label %62

62:                                               ; preds = %61, %27
  %63 = load float, ptr %5, align 4, !tbaa !9
  %64 = load i32, ptr %7, align 4, !tbaa !11
  %65 = call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %10, i32 noundef %64)
  %66 = fsub float %63, %65
  %67 = call noundef float @_ZSt4fabsf(float noundef %66)
  %68 = load float, ptr %5, align 4, !tbaa !9
  %69 = load i32, ptr %7, align 4, !tbaa !11
  %70 = sub nsw i32 %69, 1
  %71 = call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %10, i32 noundef %70)
  %72 = fsub float %68, %71
  %73 = call noundef float @_ZSt4fabsf(float noundef %72)
  %74 = fcmp olt float %67, %73
  br i1 %74, label %75, label %77

75:                                               ; preds = %62
  %76 = load i32, ptr %7, align 4, !tbaa !11
  store i32 %76, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %80

77:                                               ; preds = %62
  %78 = load i32, ptr %7, align 4, !tbaa !11
  %79 = sub nsw i32 %78, 1
  store i32 %79, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %80

80:                                               ; preds = %77, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %84

81:                                               ; preds = %2
  %82 = call noundef i32 @_ZNK4sptk6reaper5Track10num_framesEv(ptr noundef nonnull align 8 dereferenceable(72) %10)
  %83 = sub nsw i32 %82, 1
  store i32 %83, ptr %3, align 4
  br label %84

84:                                               ; preds = %81, %80
  %85 = load i32, ptr %3, align 4
  ret i32 %85
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4fabsf(float noundef) #0

attributes #0 = { inlinehint 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { 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 #4 = { 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk6reaper5Track10num_framesEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK4sptk6reaper5Track5IndexEf(ptr noundef nonnull align 8 dereferenceable(72) %0, float noundef %1) local_unnamed_addr #2 align 2 {
  %3 = tail call noundef i32 @_ZNK4sptk6reaper5Track10num_framesEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  %4 = icmp sgt i32 %3, 1
  %5 = tail call noundef i32 @_ZNK4sptk6reaper5Track10num_framesEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  br i1 %4, label %6, label %34

6:                                                ; preds = %2
  %7 = tail call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef 1)
  %8 = add nsw i32 %5, -1
  %9 = tail call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %8)
  %10 = fcmp ugt float %9, %1
  br i1 %10, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %6
  %11 = sdiv i32 %8, 2
  %12 = add nsw i32 %11, 1
  %13 = icmp ult i32 %5, 3
  br i1 %13, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %21
  %14 = phi i32 [ %24, %21 ], [ %12, %.preheader ]
  %.033 = phi i32 [ %.1, %21 ], [ %5, %.preheader ]
  %.02532 = phi i32 [ %.126, %21 ], [ 1, %.preheader ]
  %15 = tail call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %14)
  %16 = fcmp ogt float %15, %1
  br i1 %16, label %17, label %21

17:                                               ; preds = %.lr.ph
  %18 = add nsw i32 %14, -1
  %19 = tail call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %18)
  %20 = fcmp ugt float %19, %1
  br i1 %20, label %21, label %.loopexit

21:                                               ; preds = %.lr.ph, %17
  %.126 = phi i32 [ %.02532, %17 ], [ %14, %.lr.ph ]
  %.1 = phi i32 [ %14, %17 ], [ %.033, %.lr.ph ]
  %22 = sub nsw i32 %.1, %.126
  %23 = sdiv i32 %22, 2
  %24 = add nsw i32 %23, %.126
  %.off = add i32 %22, 1
  %25 = icmp ult i32 %.off, 3
  br i1 %25, label %.loopexit, label %.lr.ph, !llvm.loop !5

.loopexit:                                        ; preds = %17, %21, %.preheader, %6
  %.024 = phi i32 [ %8, %6 ], [ %12, %.preheader ], [ %14, %17 ], [ %24, %21 ]
  %26 = tail call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %.024)
  %27 = fsub float %1, %26
  %28 = tail call noundef float @_ZSt4fabsf(float noundef %27)
  %29 = add nsw i32 %.024, -1
  %30 = tail call noundef float @_ZNK4sptk6reaper5Track1tEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %29)
  %31 = fsub float %1, %30
  %32 = tail call noundef float @_ZSt4fabsf(float noundef %31)
  %33 = fcmp olt float %28, %32
  %.024. = select i1 %33, i32 %.024, i32 %29
  br label %36

34:                                               ; preds = %2
  %35 = add nsw i32 %5, -1
  br label %36

36:                                               ; preds = %34, %.loopexit
  %.128 = phi i32 [ %.024., %.loopexit ], [ %35, %34 ]
  ret i32 %.128
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4fabsf(float noundef) local_unnamed_addr #0

attributes #0 = { inlinehint 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 #1 = { inlinehint 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 = { 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,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass