; LLVM IR from Dimandragon/non-parametric-dsp :: alglib-cpp/src/ap.ll (ZN11alglib_impl5rsetmElldPNS_9ae_matrixEPNS_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::ae_matrix" = type { i64, i64, 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_impl5rsetmElldPNS_9ae_matrixEPNS_8ae_stateE(i64 noundef %0, i64 noundef %1, double noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store double %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = icmp sge i64 %14, 16
  br i1 %15, label %16, label %35

16:                                               ; preds = %5
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %31, %16
  %18 = load i64, ptr %11, align 8, !tbaa !5
  %19 = load i64, ptr %6, align 8, !tbaa !5
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %21, label %34

21:                                               ; preds = %17
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %23 = load double, ptr %8, align 8, !tbaa !9
  %24 = load ptr, ptr %9, align 8, !tbaa !11
  %25 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %24, i32 0, i32 6
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load i64, ptr %11, align 8, !tbaa !5
  %28 = getelementptr inbounds ptr, ptr %26, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = load ptr, ptr %10, align 8, !tbaa !11
  call void @_ZN11alglib_implL10rsetm_simdEldPdPNS_8ae_stateE(i64 noundef %22, double noundef %23, ptr noundef %29, ptr noundef %30)
  br label %31

31:                                               ; preds = %21
  %32 = load i64, ptr %11, align 8, !tbaa !5
  %33 = add nsw i64 %32, 1
  store i64 %33, ptr %11, align 8, !tbaa !5
  br label %17, !llvm.loop !14

34:                                               ; preds = %17
  store i32 1, ptr %13, align 4
  br label %65

35:                                               ; preds = %5
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %61, %35
  %37 = load i64, ptr %11, align 8, !tbaa !5
  %38 = load i64, ptr %6, align 8, !tbaa !5
  %39 = sub nsw i64 %38, 1
  %40 = icmp sle i64 %37, %39
  br i1 %40, label %41, label %64

41:                                               ; preds = %36
  store i64 0, ptr %12, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %57, %41
  %43 = load i64, ptr %12, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = sub nsw i64 %44, 1
  %46 = icmp sle i64 %43, %45
  br i1 %46, label %47, label %60

47:                                               ; preds = %42
  %48 = load double, ptr %8, align 8, !tbaa !9
  %49 = load ptr, ptr %9, align 8, !tbaa !11
  %50 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %49, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  %52 = load i64, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds ptr, ptr %51, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = load i64, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds double, ptr %54, i64 %55
  store double %48, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %47
  %58 = load i64, ptr %12, align 8, !tbaa !5
  %59 = add nsw i64 %58, 1
  store i64 %59, ptr %12, align 8, !tbaa !5
  br label %42, !llvm.loop !16

60:                                               ; preds = %42
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %11, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %11, align 8, !tbaa !5
  br label %36, !llvm.loop !17

64:                                               ; preds = %36
  store i32 0, ptr %13, align 4
  br label %65

65:                                               ; preds = %64, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %66 = load i32, ptr %13, align 4
  switch i32 %66, label %68 [
    i32 0, label %67
    i32 1, label %67
  ]

67:                                               ; preds = %65, %65
  ret void

68:                                               ; preds = %65
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN11alglib_implL10rsetm_simdEldPdPNS_8ae_stateE(i64 noundef, double noundef, 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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_impl5rsetmElldPNS_9ae_matrixEPNS_8ae_stateE(i64 noundef %0, i64 noundef %1, double noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = icmp sgt i64 %1, 15
  %7 = icmp sgt i64 %0, 0
  br i1 %6, label %.preheader, label %.preheader23

.preheader23:                                     ; preds = %5
  br i1 %7, label %.preheader22.lr.ph, label %.loopexit

.preheader22.lr.ph:                               ; preds = %.preheader23
  %.not.not2125 = icmp sgt i64 %1, 0
  %8 = getelementptr inbounds i8, ptr %3, i64 72
  br i1 %.not.not2125, label %.preheader22.us.preheader, label %.loopexit

.preheader22.us.preheader:                        ; preds = %.preheader22.lr.ph
  %xtraiter = and i64 %1, 3
  %9 = icmp ult i64 %1, 4
  %unroll_iter = and i64 %1, 9223372036854775804
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader22.us

.preheader22.us:                                  ; preds = %.preheader22.us.preheader, %._crit_edge.us
  %.128.us = phi i64 [ %35, %._crit_edge.us ], [ 0, %.preheader22.us.preheader ]
  br i1 %9, label %._crit_edge.us.unr-lcssa, label %.preheader22.us.new

.preheader22.us.new:                              ; preds = %.preheader22.us, %.preheader22.us.new
  %.026.us = phi i64 [ %29, %.preheader22.us.new ], [ 0, %.preheader22.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader22.us.new ], [ 0, %.preheader22.us ]
  %10 = load ptr, ptr %8, align 8, !tbaa !5
  %11 = getelementptr inbounds ptr, ptr %10, i64 %.128.us
  %12 = load ptr, ptr %11, align 8, !tbaa !8
  %13 = getelementptr inbounds double, ptr %12, i64 %.026.us
  store double %2, ptr %13, align 8, !tbaa !10
  %14 = or disjoint i64 %.026.us, 1
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %15, i64 %.128.us
  %17 = load ptr, ptr %16, align 8, !tbaa !8
  %18 = getelementptr inbounds double, ptr %17, i64 %14
  store double %2, ptr %18, align 8, !tbaa !10
  %19 = or disjoint i64 %.026.us, 2
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds ptr, ptr %20, i64 %.128.us
  %22 = load ptr, ptr %21, align 8, !tbaa !8
  %23 = getelementptr inbounds double, ptr %22, i64 %19
  store double %2, ptr %23, align 8, !tbaa !10
  %24 = or disjoint i64 %.026.us, 3
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds ptr, ptr %25, i64 %.128.us
  %27 = load ptr, ptr %26, align 8, !tbaa !8
  %28 = getelementptr inbounds double, ptr %27, i64 %24
  store double %2, ptr %28, align 8, !tbaa !10
  %29 = add nuw nsw i64 %.026.us, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader22.us.new, !llvm.loop !12

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader22.us.new, %.preheader22.us
  %.026.us.unr = phi i64 [ 0, %.preheader22.us ], [ %29, %.preheader22.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.026.us.epil = phi i64 [ %34, %.epil.preheader ], [ %.026.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds ptr, ptr %30, i64 %.128.us
  %32 = load ptr, ptr %31, align 8, !tbaa !8
  %33 = getelementptr inbounds double, ptr %32, i64 %.026.us.epil
  store double %2, ptr %33, align 8, !tbaa !10
  %34 = add nuw nsw i64 %.026.us.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !14

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %35 = add nuw nsw i64 %.128.us, 1
  %exitcond32.not = icmp eq i64 %35, %0
  br i1 %exitcond32.not, label %.loopexit, label %.preheader22.us, !llvm.loop !16

.preheader:                                       ; preds = %5
  br i1 %7, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %36 = getelementptr inbounds i8, ptr %3, i64 72
  br label %37

37:                                               ; preds = %.lr.ph, %37
  %.01829 = phi i64 [ 0, %.lr.ph ], [ %41, %37 ]
  %38 = load ptr, ptr %36, align 8, !tbaa !5
  %39 = getelementptr inbounds ptr, ptr %38, i64 %.01829
  %40 = load ptr, ptr %39, align 8, !tbaa !8
  tail call void @_ZN11alglib_implL10rsetm_simdEldPdPNS_8ae_stateE(i64 noundef %1, double noundef %2, ptr noundef %40, ptr noundef %4)
  %41 = add nuw nsw i64 %.01829, 1
  %exitcond33.not = icmp eq i64 %41, %0
  br i1 %exitcond33.not, label %.loopexit, label %37, !llvm.loop !17

.loopexit:                                        ; preds = %._crit_edge.us, %37, %.preheader22.lr.ph, %.preheader23, %.preheader
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN11alglib_implL10rsetm_simdEldPdPNS_8ae_stateE(i64 noundef, double noundef, 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}


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