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

; 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 @_ZN6alglib13real_1d_array10setcontentElPKd(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 %42

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

23:                                               ; preds = %38, %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 %41

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

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

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

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

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

45:                                               ; preds = %42
  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 = !{!18, !18, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 @_ZN6alglib13real_1d_array10setcontentElPKd(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 double, ptr %2, i64 %.010
  %14 = load double, ptr %13, align 8, !tbaa !15
  %15 = load ptr, ptr %10, align 8, !tbaa !17
  %16 = getelementptr inbounds double, ptr %15, i64 %.010
  store double %14, ptr %16, align 8, !tbaa !15
  %17 = or disjoint i64 %.010, 1
  %18 = getelementptr inbounds double, ptr %2, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !15
  %20 = load ptr, ptr %10, align 8, !tbaa !17
  %21 = getelementptr inbounds double, ptr %20, i64 %17
  store double %19, ptr %21, align 8, !tbaa !15
  %22 = or disjoint i64 %.010, 2
  %23 = getelementptr inbounds double, ptr %2, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !15
  %25 = load ptr, ptr %10, align 8, !tbaa !17
  %26 = getelementptr inbounds double, ptr %25, i64 %22
  store double %24, ptr %26, align 8, !tbaa !15
  %27 = or disjoint i64 %.010, 3
  %28 = getelementptr inbounds double, ptr %2, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %10, align 8, !tbaa !17
  %31 = getelementptr inbounds double, ptr %30, i64 %27
  store double %29, ptr %31, align 8, !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 !18

.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 double, ptr %2, i64 %.010.epil
  %34 = load double, ptr %33, align 8, !tbaa !15
  %35 = load ptr, ptr %10, align 8, !tbaa !17
  %36 = getelementptr inbounds double, ptr %35, i64 %.010.epil
  store double %34, ptr %36, align 8, !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 !20

.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 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}


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