; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/src/ap.ll (ZN6alglib13real_2d_array10setcontentEllPKd)

; 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.alglib::ae_matrix_wrapper" = type <{ ptr, ptr, %"struct.alglib_impl::ae_matrix", i8, [7 x i8] }>
%"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
declare dso_local void @_ZN6alglib17ae_matrix_wrapper9setlengthEll(ptr noundef nonnull align 8 dereferenceable(97), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6alglib13real_2d_array10setcontentEllPKd(ptr noundef nonnull align 8 dereferenceable(97) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = load i64, ptr %7, align 8, !tbaa !9
  call void @_ZN6alglib17ae_matrix_wrapper9setlengthEll(ptr noundef nonnull align 8 dereferenceable(97) %12, i64 noundef %13, i64 noundef %14)
  %15 = getelementptr inbounds %"class.alglib::ae_matrix_wrapper", ptr %12, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp eq ptr %16, null
  br i1 %17, label %32, label %18

18:                                               ; preds = %4
  %19 = getelementptr inbounds %"class.alglib::ae_matrix_wrapper", ptr %12, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !16
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = icmp ne i64 %22, %23
  br i1 %24, label %32, label %25

25:                                               ; preds = %18
  %26 = getelementptr inbounds %"class.alglib::ae_matrix_wrapper", ptr %12, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !17
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = icmp ne i64 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %25, %18, %4
  store i32 1, ptr %11, align 4
  br label %69

33:                                               ; preds = %25
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %65, %33
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = icmp slt i64 %35, %36
  br i1 %37, label %38, label %68

38:                                               ; preds = %34
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %61, %38
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = icmp slt i64 %40, %41
  br i1 %42, label %43, label %64

43:                                               ; preds = %39
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = mul nsw i64 %45, %46
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = add nsw i64 %47, %48
  %50 = getelementptr inbounds double, ptr %44, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !18
  %52 = getelementptr inbounds %"class.alglib::ae_matrix_wrapper", ptr %12, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %53, i32 0, i32 6
  %55 = load ptr, ptr %54, align 8, !tbaa !20
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = getelementptr inbounds ptr, ptr %55, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = getelementptr inbounds double, ptr %58, i64 %59
  store double %51, ptr %60, align 8, !tbaa !18
  br label %61

61:                                               ; preds = %43
  %62 = load i64, ptr %10, align 8, !tbaa !9
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %10, align 8, !tbaa !9
  br label %39, !llvm.loop !21

64:                                               ; preds = %39
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = add nsw i64 %66, 1
  store i64 %67, ptr %9, align 8, !tbaa !9
  br label %34, !llvm.loop !23

68:                                               ; preds = %34
  store i32 0, ptr %11, align 4
  br label %69

69:                                               ; preds = %68, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %70 = load i32, ptr %11, align 4
  switch i32 %70, label %72 [
    i32 0, label %71
    i32 1, label %71
  ]

71:                                               ; preds = %69, %69
  ret void

72:                                               ; preds = %69
  unreachable
}

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 = { 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 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN6alglib17ae_matrix_wrapperE", !6, i64 8, !13, i64 16, !14, i64 96}
!13 = !{!"_ZTSN11alglib_impl9ae_matrixE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !14, i64 32, !15, i64 40, !7, i64 72}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!13, !10, i64 0}
!17 = !{!13, !10, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6alglib13real_2d_array10setcontentEllPKd(ptr noundef nonnull align 8 dereferenceable(97) %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 align 2 {
  tail call void @_ZN6alglib17ae_matrix_wrapper9setlengthEll(ptr noundef nonnull align 8 dereferenceable(97) %0, i64 noundef %1, i64 noundef %2)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %4
  %9 = load i64, ptr %6, align 8, !tbaa !14
  %.not = icmp eq i64 %9, %1
  br i1 %.not, label %10, label %.loopexit

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %.not20 = icmp eq i64 %12, %2
  %13 = icmp sgt i64 %1, 0
  %or.cond = and i1 %.not20, %13
  br i1 %or.cond, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %10
  %14 = icmp sgt i64 %2, 0
  %15 = getelementptr inbounds i8, ptr %6, i64 72
  br i1 %14, label %.preheader.us.preheader, label %.loopexit

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

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01623.us = phi i64 [ %54, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %17 = mul nuw nsw i64 %.01623.us, %2
  %18 = getelementptr double, ptr %3, i64 %17
  br i1 %16, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.022.us = phi i64 [ %46, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %19 = getelementptr double, ptr %18, i64 %.022.us
  %20 = load double, ptr %19, align 8, !tbaa !16
  %21 = load ptr, ptr %15, align 8, !tbaa !18
  %22 = getelementptr inbounds ptr, ptr %21, i64 %.01623.us
  %23 = load ptr, ptr %22, align 8, !tbaa !19
  %24 = getelementptr inbounds double, ptr %23, i64 %.022.us
  store double %20, ptr %24, align 8, !tbaa !16
  %25 = or disjoint i64 %.022.us, 1
  %26 = getelementptr double, ptr %18, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !16
  %28 = load ptr, ptr %15, align 8, !tbaa !18
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.01623.us
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = getelementptr inbounds double, ptr %30, i64 %25
  store double %27, ptr %31, align 8, !tbaa !16
  %32 = or disjoint i64 %.022.us, 2
  %33 = getelementptr double, ptr %18, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !16
  %35 = load ptr, ptr %15, align 8, !tbaa !18
  %36 = getelementptr inbounds ptr, ptr %35, i64 %.01623.us
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %38 = getelementptr inbounds double, ptr %37, i64 %32
  store double %34, ptr %38, align 8, !tbaa !16
  %39 = or disjoint i64 %.022.us, 3
  %40 = getelementptr double, ptr %18, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !16
  %42 = load ptr, ptr %15, align 8, !tbaa !18
  %43 = getelementptr inbounds ptr, ptr %42, i64 %.01623.us
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = getelementptr inbounds double, ptr %44, i64 %39
  store double %41, ptr %45, align 8, !tbaa !16
  %46 = add nuw nsw i64 %.022.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 %.preheader.us.new, !llvm.loop !20

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

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.022.us.epil = phi i64 [ %53, %.epil.preheader ], [ %.022.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %47 = getelementptr double, ptr %18, i64 %.022.us.epil
  %48 = load double, ptr %47, align 8, !tbaa !16
  %49 = load ptr, ptr %15, align 8, !tbaa !18
  %50 = getelementptr inbounds ptr, ptr %49, i64 %.01623.us
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  %52 = getelementptr inbounds double, ptr %51, i64 %.022.us.epil
  store double %48, ptr %52, align 8, !tbaa !16
  %53 = add nuw nsw i64 %.022.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 !22

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %54 = add nuw nsw i64 %.01623.us, 1
  %exitcond25.not = icmp eq i64 %54, %1
  br i1 %exitcond25.not, label %.loopexit, label %.preheader.us, !llvm.loop !24

.loopexit:                                        ; preds = %._crit_edge.us, %.preheader.lr.ph, %4, %8, %10
  ret void
}

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

!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 = !{!"_ZTSN6alglib17ae_matrix_wrapperE", !7, i64 8, !10, i64 16, !12, i64 96}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN11alglib_impl9ae_matrixE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !8, i64 72}
!11 = !{!"long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!14 = !{!10, !11, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = !{!8, !8, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.unroll.disable"}
!24 = distinct !{!24, !21}


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