; LLVM IR from venumb/ZSPACE :: cpp/depends/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_impl11swapentriesEPNS_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 double, align 8
  %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 8, 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 %68

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 = %64, %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 %67

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 double, ptr %35, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !12
  store double %40, ptr %14, align 8, !tbaa !12
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = add nsw i64 %44, %45
  %47 = getelementptr inbounds double, ptr %43, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !12
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %49, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = load i64, ptr %13, align 8, !tbaa !9
  %54 = add nsw i64 %52, %53
  %55 = getelementptr inbounds double, ptr %51, i64 %54
  store double %48, ptr %55, align 8, !tbaa !12
  %56 = load double, ptr %14, align 8, !tbaa !12
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = load i64, ptr %12, align 8, !tbaa !9
  %61 = load i64, ptr %13, align 8, !tbaa !9
  %62 = add nsw i64 %60, %61
  %63 = getelementptr inbounds double, ptr %59, i64 %62
  store double %56, ptr %63, align 8, !tbaa !12
  br label %64

64:                                               ; preds = %32
  %65 = load i64, ptr %13, align 8, !tbaa !9
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %13, align 8, !tbaa !9
  br label %27, !llvm.loop !14

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

68:                                               ; preds = %67, %19
  call void @llvm.lifetime.end.p0(i64 8, 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
  %69 = load i32, ptr %15, align 4
  switch i32 %69, label %71 [
    i32 0, label %70
    i32 1, label %70
  ]

70:                                               ; preds = %68, %68
  ret void

71:                                               ; preds = %68
  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 = !{!"double", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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_impl11swapentriesEPNS_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 double, ptr %13, i64 %8
  %15 = getelementptr double, ptr %14, i64 %.024
  %16 = load double, ptr %15, align 8, !tbaa !8
  %17 = add nsw i64 %.024, %9
  %18 = getelementptr inbounds double, ptr %13, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !8
  store double %19, ptr %15, align 8, !tbaa !8
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %20, i64 %17
  store double %16, ptr %21, align 8, !tbaa !8
  %22 = or disjoint i64 %.024, 1
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr double, ptr %23, i64 %8
  %25 = getelementptr double, ptr %24, i64 %22
  %26 = load double, ptr %25, align 8, !tbaa !8
  %27 = add nsw i64 %22, %9
  %28 = getelementptr inbounds double, ptr %23, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !8
  store double %29, ptr %25, align 8, !tbaa !8
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %30, i64 %27
  store double %26, ptr %31, align 8, !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 !10

.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 double, ptr %33, i64 %8
  %35 = getelementptr double, ptr %34, i64 %.024.unr
  %36 = load double, ptr %35, align 8, !tbaa !8
  %37 = add nsw i64 %.024.unr, %9
  %38 = getelementptr inbounds double, ptr %33, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !8
  store double %39, ptr %35, align 8, !tbaa !8
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds double, ptr %40, i64 %37
  store double %36, ptr %41, align 8, !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 = !{!"double", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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