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

; 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::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 nounwind uwtable
define dso_local void @_ZN11alglib_impl12swapentriesbEPNS_9ae_vectorElllPNS_8ae_stateE(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #2
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = icmp eq i64 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  store i32 1, ptr %15, align 4
  br label %74

20:                                               ; preds = %5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = mul nsw i64 %21, %22
  store i64 %23, ptr %11, align 8, !tbaa !9
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = mul nsw i64 %24, %25
  store i64 %26, ptr %12, align 8, !tbaa !9
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %70, %20
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = sub nsw i64 %29, 1
  %31 = icmp sle i64 %28, %30
  br i1 %31, label %32, label %73

32:                                               ; preds = %27
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = load i64, ptr %13, align 8, !tbaa !9
  %38 = add nsw i64 %36, %37
  %39 = getelementptr inbounds i8, ptr %35, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !12, !range !14, !noundef !15
  %41 = trunc i8 %40 to i1
  %42 = zext i1 %41 to i8
  store i8 %42, ptr %14, align 1, !tbaa !12
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i64, ptr %12, align 8, !tbaa !9
  %47 = load i64, ptr %13, align 8, !tbaa !9
  %48 = add nsw i64 %46, %47
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !12, !range !14, !noundef !15
  %51 = trunc i8 %50 to i1
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = load i64, ptr %13, align 8, !tbaa !9
  %57 = add nsw i64 %55, %56
  %58 = getelementptr inbounds i8, ptr %54, i64 %57
  %59 = zext i1 %51 to i8
  store i8 %59, ptr %58, align 1, !tbaa !12
  %60 = load i8, ptr %14, align 1, !tbaa !12, !range !14, !noundef !15
  %61 = trunc i8 %60 to i1
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  %65 = load i64, ptr %12, align 8, !tbaa !9
  %66 = load i64, ptr %13, align 8, !tbaa !9
  %67 = add nsw i64 %65, %66
  %68 = getelementptr inbounds i8, ptr %64, i64 %67
  %69 = zext i1 %61 to i8
  store i8 %69, ptr %68, align 1, !tbaa !12
  br label %70

70:                                               ; preds = %32
  %71 = load i64, ptr %13, align 8, !tbaa !9
  %72 = add nsw i64 %71, 1
  store i64 %72, ptr %13, align 8, !tbaa !9
  br label %27, !llvm.loop !16

73:                                               ; preds = %27
  store i32 0, ptr %15, align 4
  br label %74

74:                                               ; preds = %73, %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %75 = load i32, ptr %15, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 1, label %76
  ]

76:                                               ; preds = %74, %74
  ret void

77:                                               ; preds = %74
  unreachable
}

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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN11alglib_impl12swapentriesbEPNS_9ae_vectorElllPNS_8ae_stateE(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readnone %4) local_unnamed_addr #0 {
  %6 = icmp eq i64 %1, %2
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = mul nsw i64 %3, %1
  %9 = mul nsw i64 %3, %2
  %.not.not23 = icmp sgt i64 %3, 0
  br i1 %.not.not23, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %xtraiter = and i64 %3, 1
  %11 = icmp eq i64 %3, 1
  br i1 %11, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

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

12:                                               ; preds = %12, %.lr.ph.new
  %.024 = phi i64 [ 0, %.lr.ph.new ], [ %32, %12 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %12 ]
  %13 = load ptr, ptr %10, align 8, !tbaa !5
  %14 = getelementptr i8, ptr %13, i64 %8
  %15 = getelementptr i8, ptr %14, i64 %.024
  %16 = load i8, ptr %15, align 1, !tbaa !8, !range !10, !noundef !11
  %17 = add nsw i64 %.024, %9
  %18 = getelementptr inbounds i8, ptr %13, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !8, !range !10, !noundef !11
  store i8 %19, ptr %15, align 1, !tbaa !8
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 %17
  store i8 %16, ptr %21, align 1, !tbaa !8
  %22 = or disjoint i64 %.024, 1
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr i8, ptr %23, i64 %8
  %25 = getelementptr i8, ptr %24, i64 %22
  %26 = load i8, ptr %25, align 1, !tbaa !8, !range !10, !noundef !11
  %27 = add nsw i64 %22, %9
  %28 = getelementptr inbounds i8, ptr %23, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !8, !range !10, !noundef !11
  store i8 %29, ptr %25, align 1, !tbaa !8
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 %27
  store i8 %26, ptr %31, align 1, !tbaa !8
  %32 = add nuw nsw i64 %.024, 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 %.loopexit.loopexit.unr-lcssa, label %12, !llvm.loop !12

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

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr i8, ptr %33, i64 %8
  %35 = getelementptr i8, ptr %34, i64 %.024.unr
  %36 = load i8, ptr %35, align 1, !tbaa !8, !range !10, !noundef !11
  %37 = add nsw i64 %.024.unr, %9
  %38 = getelementptr inbounds i8, ptr %33, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !8, !range !10, !noundef !11
  store i8 %39, ptr %35, align 1, !tbaa !8
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 %37
  store i8 %36, ptr %41, align 1, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %7, %5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"bool", !6, i64 0}
!10 = !{i8 0, i8 2}
!11 = !{}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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