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

; 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 @_ZN6alglib16boolean_2d_array10setcontentEllPKb(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 %71

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

34:                                               ; preds = %67, %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 %70

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

39:                                               ; preds = %63, %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 %66

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 i8, ptr %44, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !18, !range !19, !noundef !20
  %52 = trunc i8 %51 to i1
  %53 = getelementptr inbounds %"class.alglib::ae_matrix_wrapper", ptr %12, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = getelementptr inbounds %"struct.alglib_impl::ae_matrix", ptr %54, i32 0, i32 6
  %56 = load ptr, ptr %55, align 8, !tbaa !21
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = getelementptr inbounds ptr, ptr %56, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  %62 = zext i1 %52 to i8
  store i8 %62, ptr %61, align 1, !tbaa !18
  br label %63

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

66:                                               ; preds = %39
  br label %67

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

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

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

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

74:                                               ; preds = %71
  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 = !{!14, !14, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!7, !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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 @_ZN6alglib16boolean_2d_array10setcontentEllPKb(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 i8, 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 i8, ptr %18, i64 %.022.us
  %20 = load i8, ptr %19, align 1, !tbaa !16, !range !17, !noundef !18
  %21 = load ptr, ptr %15, align 8, !tbaa !19
  %22 = getelementptr inbounds ptr, ptr %21, i64 %.01623.us
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %23, i64 %.022.us
  store i8 %20, ptr %24, align 1, !tbaa !16
  %25 = or disjoint i64 %.022.us, 1
  %26 = getelementptr i8, ptr %18, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !16, !range !17, !noundef !18
  %28 = load ptr, ptr %15, align 8, !tbaa !19
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.01623.us
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %31 = getelementptr inbounds i8, ptr %30, i64 %25
  store i8 %27, ptr %31, align 1, !tbaa !16
  %32 = or disjoint i64 %.022.us, 2
  %33 = getelementptr i8, ptr %18, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !16, !range !17, !noundef !18
  %35 = load ptr, ptr %15, align 8, !tbaa !19
  %36 = getelementptr inbounds ptr, ptr %35, i64 %.01623.us
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  %38 = getelementptr inbounds i8, ptr %37, i64 %32
  store i8 %34, ptr %38, align 1, !tbaa !16
  %39 = or disjoint i64 %.022.us, 3
  %40 = getelementptr i8, ptr %18, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !16, !range !17, !noundef !18
  %42 = load ptr, ptr %15, align 8, !tbaa !19
  %43 = getelementptr inbounds ptr, ptr %42, i64 %.01623.us
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = getelementptr inbounds i8, ptr %44, i64 %39
  store i8 %41, ptr %45, align 1, !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 !21

._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 i8, ptr %18, i64 %.022.us.epil
  %48 = load i8, ptr %47, align 1, !tbaa !16, !range !17, !noundef !18
  %49 = load ptr, ptr %15, align 8, !tbaa !19
  %50 = getelementptr inbounds ptr, ptr %49, i64 %.01623.us
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = getelementptr inbounds i8, ptr %51, i64 %.022.us.epil
  store i8 %48, ptr %52, align 1, !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 !23

._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 !25

.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 = !{!12, !12, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!8, !8, i64 0}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.unroll.disable"}
!25 = distinct !{!25, !22}


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