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

; 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_vector_wrapper" = type <{ ptr, ptr, %"struct.alglib_impl::ae_vector", i8, [7 x i8] }>
%"struct.alglib_impl::ae_vector" = type { i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon.0 }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, ptr }
%union.anon.0 = 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_vector_wrapper9setlengthEl(ptr noundef nonnull align 8 dereferenceable(81), i64 noundef) #1 align 2

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

14:                                               ; preds = %3
  %15 = getelementptr inbounds %"class.alglib::ae_vector_wrapper", ptr %9, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = icmp ne i64 %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %14, %3
  store i32 1, ptr %8, align 4
  br label %44

22:                                               ; preds = %14
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %40, %22
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %27, label %43

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !17, !range !18, !noundef !19
  %32 = trunc i8 %31 to i1
  %33 = getelementptr inbounds %"class.alglib::ae_vector_wrapper", ptr %9, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = zext i1 %32 to i8
  store i8 %39, ptr %38, align 1, !tbaa !17
  br label %40

40:                                               ; preds = %27
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = add nsw i64 %41, 1
  store i64 %42, ptr %7, align 8, !tbaa !9
  br label %23, !llvm.loop !21

43:                                               ; preds = %23
  store i32 0, ptr %8, align 4
  br label %44

44:                                               ; preds = %43, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %45 = load i32, ptr %8, align 4
  switch i32 %45, label %47 [
    i32 0, label %46
    i32 1, label %46
  ]

46:                                               ; preds = %44, %44
  ret void

47:                                               ; preds = %44
  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_vector_wrapperE", !6, i64 8, !13, i64 16, !14, i64 80}
!13 = !{!"_ZTSN11alglib_impl9ae_vectorE", !10, i64 0, !10, i64 8, !14, i64 16, !15, i64 24, !7, i64 56}
!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 = !{!14, !14, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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 uwtable
declare dso_local void @_ZN6alglib17ae_vector_wrapper9setlengthEl(ptr noundef nonnull align 8 dereferenceable(81), i64 noundef) local_unnamed_addr #0 align 2

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

7:                                                ; preds = %3
  %8 = load i64, ptr %5, align 8, !tbaa !14
  %.not = icmp eq i64 %8, %1
  %9 = icmp sgt i64 %1, 0
  %or.cond = and i1 %.not, %9
  br i1 %or.cond, label %.lr.ph, label %.loopexit

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

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

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

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

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader
  %.010.epil = phi i64 [ %37, %.epil.preheader ], [ %.010.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %33 = getelementptr inbounds i8, ptr %2, i64 %.010.epil
  %34 = load i8, ptr %33, align 1, !tbaa !15, !range !16, !noundef !17
  %35 = load ptr, ptr %10, align 8, !tbaa !18
  %36 = getelementptr inbounds i8, ptr %35, i64 %.010.epil
  store i8 %34, ptr %36, align 1, !tbaa !15
  %37 = add nuw nsw i64 %.010.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 %.loopexit, label %.epil.preheader, !llvm.loop !21

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %3, %7
  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_vector_wrapperE", !7, i64 8, !10, i64 16, !12, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN11alglib_impl9ae_vectorE", !11, i64 0, !11, i64 8, !12, i64 16, !13, i64 24, !8, i64 56}
!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 = !{!12, !12, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!8, !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.unroll.disable"}


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