; LLVM IR from Squishy47/Schroeder-All-Pass-Filter :: CircularBuffer.ll (ZN14CircularBuffer9getSampleEf)

; 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.CircularBuffer = type <{ %"class.std::vector", i32, i32, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_ZN14CircularBuffer9getSampleEf(ptr noundef nonnull align 8 dereferenceable(36) %0, float noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 2
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = sitofp i32 %7 to float
  %9 = load float, ptr %4, align 4, !tbaa !9
  %10 = fsub float %8, %9
  %11 = fptosi float %10 to i32
  %12 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 3
  store i32 %11, ptr %12, align 8, !tbaa !18
  %13 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 3
  %14 = load i32, ptr %13, align 8, !tbaa !18
  %15 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !19
  %17 = sub nsw i32 %16, 1
  %18 = icmp sgt i32 %14, %17
  br i1 %18, label %19, label %25

19:                                               ; preds = %2
  %20 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = sub nsw i32 %23, %21
  store i32 %24, ptr %22, align 8, !tbaa !18
  br label %36

25:                                               ; preds = %2
  %26 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %35

29:                                               ; preds = %25
  %30 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !19
  %32 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !18
  %34 = add nsw i32 %33, %31
  store i32 %34, ptr %32, align 8, !tbaa !18
  br label %35

35:                                               ; preds = %29, %25
  br label %36

36:                                               ; preds = %35, %19
  %37 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 0
  %38 = getelementptr inbounds %class.CircularBuffer, ptr %5, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !18
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %37, i64 noundef %40) #1
  %42 = load float, ptr %41, align 4, !tbaa !9
  ret float %42
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

attributes #0 = { 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 = { 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, !17, i64 28}
!12 = !{!"_ZTS14CircularBuffer", !13, i64 0, !17, i64 24, !17, i64 28, !17, i64 32}
!13 = !{!"_ZTSSt6vectorIfSaIfEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"int", !7, i64 0}
!18 = !{!12, !17, i64 32}
!19 = !{!12, !17, i64 24}


; 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 nounwind uwtable
define dso_local noundef float @_ZN14CircularBuffer9getSampleEf(ptr noundef nonnull align 8 dereferenceable(36) %0, float noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 28
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sitofp i32 %4 to float
  %6 = fsub float %5, %1
  %7 = fptosi float %6 to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %7, ptr %8, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !16
  %.not = icmp sgt i32 %10, %7
  br i1 %.not, label %13, label %11

11:                                               ; preds = %2
  %12 = sub nsw i32 %7, %10
  br label %.sink.split

13:                                               ; preds = %2
  %14 = icmp slt i32 %7, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %13
  %16 = add nsw i32 %10, %7
  br label %.sink.split

.sink.split:                                      ; preds = %11, %15
  %.sink = phi i32 [ %16, %15 ], [ %12, %11 ]
  store i32 %.sink, ptr %8, align 8, !tbaa !15
  br label %17

17:                                               ; preds = %.sink.split, %13
  %18 = phi i32 [ %7, %13 ], [ %.sink, %.sink.split ]
  %19 = sext i32 %18 to i64
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #1
  %21 = load float, ptr %20, align 4, !tbaa !17
  ret float %21
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 = { 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, !14, i64 28}
!6 = !{!"_ZTS14CircularBuffer", !7, i64 0, !14, i64 24, !14, i64 28, !14, i64 32}
!7 = !{!"_ZTSSt6vectorIfSaIfEE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"int", !12, i64 0}
!15 = !{!6, !14, i64 32}
!16 = !{!6, !14, i64 24}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass