; LLVM IR from zsiciarz/aquila :: aquila/source (FramesCollection)

; 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.Aquila::Frame" = type { %"class.Aquila::SignalSource", ptr, i32, i32 }
%"class.Aquila::SignalSource" = type { ptr, %"class.std::vector.0", double }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.Aquila::FramesCollection" = type <{ %"class.std::vector", i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Aquila::Frame, std::allocator<Aquila::Frame>>::_Vector_impl" }
%"struct.std::_Vector_base<Aquila::Frame, std::allocator<Aquila::Frame>>::_Vector_impl" = type { %"struct.std::_Vector_base<Aquila::Frame, std::allocator<Aquila::Frame>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Aquila::Frame, std::allocator<Aquila::Frame>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Aquila16FramesCollection12divideFramesERKNS_12SignalSourceEjj(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %2, i32 noundef %3) #0 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca %"class.Aquila::Frame", align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  br label %78

23:                                               ; preds = %4
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = getelementptr inbounds %"class.Aquila::FramesCollection", ptr %19, i32 0, i32 1
  store i32 %24, ptr %25, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds ptr, ptr %27, i64 5
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef i64 %29(ptr noundef nonnull align 8 dereferenceable(40) %26)
  store i64 %30, ptr %9, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = sub i32 %31, %32
  store i32 %33, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %34 = load i64, ptr %9, align 8, !tbaa !19
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = udiv i64 %34, %36
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr %11, align 4, !tbaa !9
  %39 = getelementptr inbounds %"class.Aquila::FramesCollection", ptr %19, i32 0, i32 0
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  call void @_ZNSt6vectorIN6Aquila5FrameESaIS1_EE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24) %39, i64 noundef %41)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !19
  br label %42

42:                                               ; preds = %73, %23
  %43 = load i64, ptr %14, align 8, !tbaa !19
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = icmp ult i64 %43, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %42
  store i32 2, ptr %15, align 4
  br label %76

48:                                               ; preds = %42
  %49 = load i64, ptr %14, align 8, !tbaa !19
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = mul i64 %49, %51
  %53 = trunc i64 %52 to i32
  store i32 %53, ptr %12, align 4, !tbaa !9
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = add i32 %54, %55
  store i32 %56, ptr %13, align 4, !tbaa !9
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = zext i32 %57 to i64
  %59 = load i64, ptr %9, align 8, !tbaa !19
  %60 = icmp ule i64 %58, %59
  br i1 %60, label %61, label %71

61:                                               ; preds = %48
  %62 = getelementptr inbounds %"class.Aquila::FramesCollection", ptr %19, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 56, ptr %16) #4
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = load i32, ptr %13, align 4, !tbaa !9
  call void @_ZN6Aquila5FrameC1ERKNS_12SignalSourceEjj(ptr noundef nonnull align 8 dereferenceable(56) %16, ptr noundef nonnull align 8 dereferenceable(40) %63, i32 noundef %64, i32 noundef %65)
  invoke void @_ZNSt6vectorIN6Aquila5FrameESaIS1_EE9push_backEOS1_(ptr noundef nonnull align 8 dereferenceable(24) %62, ptr noundef nonnull align 8 dereferenceable(56) %16)
          to label %66 unwind label %67

66:                                               ; preds = %61
  call void @_ZN6Aquila12SignalSourceD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %16) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %16) #4
  br label %72

67:                                               ; preds = %61
  %68 = landingpad { ptr, i32 }
          cleanup
  %69 = extractvalue { ptr, i32 } %68, 0
  store ptr %69, ptr %17, align 8
  %70 = extractvalue { ptr, i32 } %68, 1
  store i32 %70, ptr %18, align 4
  call void @_ZN6Aquila12SignalSourceD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %16) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %79

71:                                               ; preds = %48
  store i32 2, ptr %15, align 4
  br label %76

72:                                               ; preds = %66
  br label %73

73:                                               ; preds = %72
  %74 = load i64, ptr %14, align 8, !tbaa !19
  %75 = add i64 %74, 1
  store i64 %75, ptr %14, align 8, !tbaa !19
  br label %42, !llvm.loop !21

76:                                               ; preds = %71, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %77

77:                                               ; preds = %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %78

78:                                               ; preds = %77, %22
  ret void

79:                                               ; preds = %67
  %80 = load ptr, ptr %17, align 8
  %81 = load i32, ptr %18, align 4
  %82 = insertvalue { ptr, i32 } poison, ptr %80, 0
  %83 = insertvalue { ptr, i32 } %82, i32 %81, 1
  resume { ptr, i32 } %83
}

declare i32 @__gxx_personality_v0(...)

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

; 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
declare dso_local void @_ZNSt6vectorIN6Aquila5FrameESaIS1_EE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIN6Aquila5FrameESaIS1_EE9push_backEOS1_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(56)) #0 align 2

declare void @_ZN6Aquila5FrameC1ERKNS_12SignalSourceEjj(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Aquila12SignalSourceD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #3 align 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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTSN6Aquila16FramesCollectionE", !13, i64 0, !10, i64 24}
!13 = !{!"_ZTSSt6vectorIN6Aquila5FrameESaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIN6Aquila5FrameESaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIN6Aquila5FrameESaIS1_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIN6Aquila5FrameESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%"class.Aquila::Frame" = type { %"class.Aquila::SignalSource", ptr, i32, i32 }
%"class.Aquila::SignalSource" = type { ptr, %"class.std::vector.0", double }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Aquila16FramesCollection12divideFramesERKNS_12SignalSourceEjj(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca %"class.Aquila::Frame", align 8
  %6 = icmp eq i32 %2, 0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %2, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %1, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %9, i64 40
  %11 = load ptr, ptr %10, align 8
  %12 = tail call noundef i64 %11(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %13 = sub i32 %2, %3
  %14 = zext i32 %13 to i64
  %15 = udiv i64 %12, %14
  %16 = and i64 %15, 4294967295
  tail call void @_ZNSt6vectorIN6Aquila5FrameESaIS1_EE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %16)
  %.not25 = icmp eq i64 %16, 0
  br i1 %.not25, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7, %22
  %.023 = phi i64 [ %23, %22 ], [ 0, %7 ]
  %17 = trunc i64 %.023 to i32
  %18 = mul i32 %13, %17
  %19 = add i32 %18, %2
  %20 = zext i32 %19 to i64
  %.not = icmp ult i64 %12, %20
  br i1 %.not, label %.loopexit, label %21

21:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %5) #4
  call void @_ZN6Aquila5FrameC1ERKNS_12SignalSourceEjj(ptr noundef nonnull align 8 dereferenceable(56) %5, ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %18, i32 noundef %19)
  invoke void @_ZNSt6vectorIN6Aquila5FrameESaIS1_EE9push_backEOS1_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(56) %5)
          to label %22 unwind label %25

22:                                               ; preds = %21
  call void @_ZN6Aquila12SignalSourceD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %5) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %5) #4
  %23 = add nuw nsw i64 %.023, 1
  %24 = icmp ult i64 %23, %16
  br i1 %24, label %.lr.ph, label %.loopexit, !llvm.loop !17

25:                                               ; preds = %21
  %26 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6Aquila12SignalSourceD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %5) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %5) #4
  resume { ptr, i32 } %26

.loopexit:                                        ; preds = %.lr.ph, %22, %7, %4
  ret void
}

declare i32 @__gxx_personality_v0(...)

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIN6Aquila5FrameESaIS1_EE9push_backEOS1_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #0 align 2

declare void @_ZN6Aquila5FrameC1ERKNS_12SignalSourceEjj(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Aquila12SignalSourceD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #3 align 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 #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, !14, i64 24}
!6 = !{!"_ZTSN6Aquila16FramesCollectionE", !7, i64 0, !14, i64 24}
!7 = !{!"_ZTSSt6vectorIN6Aquila5FrameESaIS1_EE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIN6Aquila5FrameESaIS1_EE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIN6Aquila5FrameESaIS1_EE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIN6Aquila5FrameESaIS1_EE17_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 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass