; LLVM IR from Dimandragon/non-parametric-dsp :: alglib-cpp/src/ap.ll (ZN11alglib_impl18ae_obj_array_clearEPNS_12ae_obj_arrayE)

; 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_obj_array" = type { i64, i64, i8, ptr, ptr, ptr, ptr, %"struct.alglib_impl::ae_lock", %"struct.alglib_impl::ae_dyn_block" }
%"struct.alglib_impl::ae_lock" = type { ptr, %"struct.alglib_impl::ae_dyn_block", i8 }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, 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 nounwind uwtable
declare dso_local void @_ZN11alglib_impl7ae_freeEPv(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl18ae_obj_array_clearEPNS_12ae_obj_arrayE(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %4

4:                                                ; preds = %58, %1
  %5 = load i64, ptr %3, align 8, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %6, i32 0, i32 0
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = icmp slt i64 %5, %8
  br i1 %9, label %10, label %61

10:                                               ; preds = %4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = getelementptr inbounds ptr, ptr %13, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %57

18:                                               ; preds = %10
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %22 = load i64, ptr %3, align 8, !tbaa !9
  %23 = getelementptr inbounds ptr, ptr %21, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load i64, ptr %3, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %27, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  call void %24(ptr noundef %30)
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = getelementptr inbounds ptr, ptr %33, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  call void @_ZN11alglib_impl7ae_freeEPv(ptr noundef %36)
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = load i64, ptr %3, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %39, i64 %40
  store ptr null, ptr %41, align 8, !tbaa !5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = load i64, ptr %3, align 8, !tbaa !9
  %46 = getelementptr inbounds i64, ptr %44, i64 %45
  store i64 0, ptr %46, align 8, !tbaa !9
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %47, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !19
  %50 = load i64, ptr %3, align 8, !tbaa !9
  %51 = getelementptr inbounds ptr, ptr %49, i64 %50
  store ptr null, ptr %51, align 8, !tbaa !5
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %52, i32 0, i32 6
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load i64, ptr %3, align 8, !tbaa !9
  %56 = getelementptr inbounds ptr, ptr %54, i64 %55
  store ptr null, ptr %56, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %18, %10
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %3, align 8, !tbaa !9
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %3, align 8, !tbaa !9
  br label %4, !llvm.loop !20

61:                                               ; preds = %4
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.alglib_impl::ae_obj_array", ptr %62, i32 0, i32 0
  store i64 0, ptr %63, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"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, !10, i64 0}
!12 = !{!"_ZTSN11alglib_impl12ae_obj_arrayE", !10, i64 0, !10, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !14, i64 56, !15, i64 104}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN11alglib_impl7ae_lockE", !6, i64 0, !15, i64 8, !13, i64 40}
!15 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!12, !6, i64 24}
!17 = !{!12, !6, i64 48}
!18 = !{!12, !6, i64 32}
!19 = !{!12, !6, i64 40}
!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 nounwind uwtable
declare dso_local void @_ZN11alglib_impl7ae_freeEPv(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl18ae_obj_array_clearEPNS_12ae_obj_arrayE(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = load i64, ptr %0, align 8, !tbaa !5
  %3 = icmp sgt i64 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  br label %8

8:                                                ; preds = %.lr.ph, %28
  %9 = phi i64 [ %2, %.lr.ph ], [ %29, %28 ]
  %.020 = phi i64 [ 0, %.lr.ph ], [ %30, %28 ]
  %10 = load ptr, ptr %4, align 8, !tbaa !14
  %11 = getelementptr inbounds ptr, ptr %10, i64 %.020
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %28, label %13

13:                                               ; preds = %8
  %14 = load ptr, ptr %5, align 8, !tbaa !16
  %15 = getelementptr inbounds ptr, ptr %14, i64 %.020
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  tail call void %16(ptr noundef nonnull %12)
  %17 = load ptr, ptr %4, align 8, !tbaa !14
  %18 = getelementptr inbounds ptr, ptr %17, i64 %.020
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  tail call void @_ZN11alglib_impl7ae_freeEPv(ptr noundef %19)
  %20 = load ptr, ptr %4, align 8, !tbaa !14
  %21 = getelementptr inbounds ptr, ptr %20, i64 %.020
  store ptr null, ptr %21, align 8, !tbaa !15
  %22 = load ptr, ptr %6, align 8, !tbaa !17
  %23 = getelementptr inbounds i64, ptr %22, i64 %.020
  store i64 0, ptr %23, align 8, !tbaa !18
  %24 = load ptr, ptr %7, align 8, !tbaa !19
  %25 = getelementptr inbounds ptr, ptr %24, i64 %.020
  store ptr null, ptr %25, align 8, !tbaa !15
  %26 = load ptr, ptr %5, align 8, !tbaa !16
  %27 = getelementptr inbounds ptr, ptr %26, i64 %.020
  store ptr null, ptr %27, align 8, !tbaa !15
  %.pre = load i64, ptr %0, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %8, %13
  %29 = phi i64 [ %9, %8 ], [ %.pre, %13 ]
  %30 = add nuw nsw i64 %.020, 1
  %31 = icmp slt i64 %30, %29
  br i1 %31, label %8, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %28, %1
  store i64 0, ptr %0, align 8, !tbaa !5
  ret void
}

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

!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 0}
!6 = !{!"_ZTSN11alglib_impl12ae_obj_arrayE", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !13, i64 104}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_ZTSN11alglib_impl7ae_lockE", !11, i64 0, !13, i64 8, !10, i64 40}
!13 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!14 = !{!6, !11, i64 24}
!15 = !{!11, !11, i64 0}
!16 = !{!6, !11, i64 48}
!17 = !{!6, !11, i64 32}
!18 = !{!7, !7, i64 0}
!19 = !{!6, !11, i64 40}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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