; LLVM IR from Dimandragon/non-parametric-dsp :: alglib-cpp/src/alglibinternal.ll (ZN11alglib_impl7niscopyEPKNS_5nisetEPS0_PNS_8ae_stateE)

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

%"struct.alglib_impl::niset" = type { i64, i64, %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", i64 }
%"struct.alglib_impl::ae_vector" = type { i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, ptr }
%union.anon = type { 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 uwtable
define dso_local void @_ZN11alglib_impl7niscopyEPKNS_5nisetEPS0_PNS_8ae_stateE(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN11alglib_impl8nisclearEPNS_5nisetEPNS_8ae_stateE(ptr noundef %10, ptr noundef %11)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.alglib_impl::niset", ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %14, ptr %7, align 8, !tbaa !15
  store i64 0, ptr %8, align 8, !tbaa !15
  br label %15

15:                                               ; preds = %42, %3
  %16 = load i64, ptr %8, align 8, !tbaa !15
  %17 = load i64, ptr %7, align 8, !tbaa !15
  %18 = sub nsw i64 %17, 1
  %19 = icmp sle i64 %16, %18
  br i1 %19, label %20, label %45

20:                                               ; preds = %15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.alglib_impl::niset", ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %22, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load i64, ptr %8, align 8, !tbaa !15
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !15
  store i64 %27, ptr %9, align 8, !tbaa !15
  %28 = load i64, ptr %9, align 8, !tbaa !15
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.alglib_impl::niset", ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load i64, ptr %8, align 8, !tbaa !15
  %34 = getelementptr inbounds i64, ptr %32, i64 %33
  store i64 %28, ptr %34, align 8, !tbaa !15
  %35 = load i64, ptr %8, align 8, !tbaa !15
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.alglib_impl::niset", ptr %36, i32 0, i32 3
  %38 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = load i64, ptr %9, align 8, !tbaa !15
  %41 = getelementptr inbounds i64, ptr %39, i64 %40
  store i64 %35, ptr %41, align 8, !tbaa !15
  br label %42

42:                                               ; preds = %20
  %43 = load i64, ptr %8, align 8, !tbaa !15
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %8, align 8, !tbaa !15
  br label %15, !llvm.loop !17

45:                                               ; preds = %15
  %46 = load i64, ptr %7, align 8, !tbaa !15
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.alglib_impl::niset", ptr %47, i32 0, i32 1
  store i64 %46, ptr %48, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11alglib_impl8nisclearEPNS_5nisetEPNS_8ae_stateE(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 #3 = { 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, !11, i64 8}
!10 = !{!"_ZTSN11alglib_impl5nisetE", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 80, !11, i64 144}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSN11alglib_impl9ae_vectorE", !11, i64 0, !11, i64 8, !13, i64 16, !14, i64 24, !7, i64 56}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!11, !11, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 nounwind uwtable
define dso_local void @_ZN11alglib_impl7niscopyEPKNS_5nisetEPS0_PNS_8ae_stateE(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  tail call void @_ZN11alglib_impl8nisclearEPNS_5nisetEPNS_8ae_stateE(ptr noundef %1, ptr noundef %2)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not.not15 = icmp sgt i64 %5, 0
  br i1 %.not.not15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = getelementptr inbounds i8, ptr %1, i64 72
  %8 = getelementptr inbounds i8, ptr %1, i64 136
  %xtraiter = and i64 %5, 1
  %9 = icmp eq i64 %5, 1
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %5, 9223372036854775806
  br label %10

10:                                               ; preds = %10, %.lr.ph.new
  %.016 = phi i64 [ 0, %.lr.ph.new ], [ %26, %10 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %10 ]
  %11 = load ptr, ptr %6, align 8, !tbaa !14
  %12 = getelementptr inbounds i64, ptr %11, i64 %.016
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = load ptr, ptr %7, align 8, !tbaa !14
  %15 = getelementptr inbounds i64, ptr %14, i64 %.016
  store i64 %13, ptr %15, align 8, !tbaa !15
  %16 = load ptr, ptr %8, align 8, !tbaa !14
  %17 = getelementptr inbounds i64, ptr %16, i64 %13
  store i64 %.016, ptr %17, align 8, !tbaa !15
  %18 = or disjoint i64 %.016, 1
  %19 = load ptr, ptr %6, align 8, !tbaa !14
  %20 = getelementptr inbounds i64, ptr %19, i64 %18
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %7, align 8, !tbaa !14
  %23 = getelementptr inbounds i64, ptr %22, i64 %18
  store i64 %21, ptr %23, align 8, !tbaa !15
  %24 = load ptr, ptr %8, align 8, !tbaa !14
  %25 = getelementptr inbounds i64, ptr %24, i64 %21
  store i64 %18, ptr %25, align 8, !tbaa !15
  %26 = add nuw nsw i64 %.016, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %10, !llvm.loop !16

._crit_edge.loopexit.unr-lcssa:                   ; preds = %10, %.lr.ph
  %.016.unr = phi i64 [ 0, %.lr.ph ], [ %26, %10 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %27 = load ptr, ptr %6, align 8, !tbaa !14
  %28 = getelementptr inbounds i64, ptr %27, i64 %.016.unr
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %7, align 8, !tbaa !14
  %31 = getelementptr inbounds i64, ptr %30, i64 %.016.unr
  store i64 %29, ptr %31, align 8, !tbaa !15
  %32 = load ptr, ptr %8, align 8, !tbaa !14
  %33 = getelementptr inbounds i64, ptr %32, i64 %29
  store i64 %.016.unr, ptr %33, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %3
  %34 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %5, ptr %34, align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11alglib_impl8nisclearEPNS_5nisetEPNS_8ae_stateE(ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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, !7, i64 8}
!6 = !{!"_ZTSN11alglib_impl5nisetE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 80, !7, i64 144}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN11alglib_impl9ae_vectorE", !7, i64 0, !7, i64 8, !11, i64 16, !12, i64 24, !8, i64 56}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass