; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsarray)

; 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.XsArray = type { ptr, i64, i64, i64, ptr }
%struct.XsArrayDescriptor = type { i64, ptr, ptr, ptr, 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: nounwind uwtable
define dso_local void @XsArray_erase(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %3
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XsArray, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp uge i64 %15, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %14, %3
  store i32 1, ptr %10, align 4
  br label %83

21:                                               ; preds = %14
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = add i64 %22, %23
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XsArray, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = icmp ugt i64 %24, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %21
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XsArray, ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = sub i64 %32, %33
  store i64 %34, ptr %6, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %29, %21
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XsArray, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = sub i64 %38, %39
  store i64 %40, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %41, ptr %7, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %76, %35
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = icmp ult i64 %43, %44
  br i1 %45, label %46, label %79

46:                                               ; preds = %42
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XsArray, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XsArray, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.XsArray, ptr %56, i32 0, i32 4
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %58, i32 0, i32 0
  %60 = load i64, ptr %59, align 8, !tbaa !17
  %61 = mul i64 %55, %60
  %62 = getelementptr inbounds i8, ptr %54, i64 %61
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XsArray, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !16
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = add i64 %66, %67
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.XsArray, ptr %69, i32 0, i32 4
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %71, i32 0, i32 0
  %73 = load i64, ptr %72, align 8, !tbaa !17
  %74 = mul i64 %68, %73
  %75 = getelementptr inbounds i8, ptr %65, i64 %74
  call void %51(ptr noundef %62, ptr noundef %75)
  br label %76

76:                                               ; preds = %46
  %77 = load i64, ptr %7, align 8, !tbaa !9
  %78 = add i64 %77, 1
  store i64 %78, ptr %7, align 8, !tbaa !9
  br label %42, !llvm.loop !18

79:                                               ; preds = %42
  %80 = load i64, ptr %8, align 8, !tbaa !9
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.XsArray, ptr %81, i32 0, i32 1
  store i64 %80, ptr %82, align 8, !tbaa !9
  store i32 0, ptr %10, align 4
  br label %83

83:                                               ; preds = %79, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %84 = load i32, ptr %10, align 4
  switch i32 %84, label %86 [
    i32 0, label %85
    i32 1, label %85
  ]

85:                                               ; preds = %83, %83
  ret void

86:                                               ; preds = %83
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"XsArray", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 32}
!14 = !{!15, !6, i64 8}
!15 = !{!"XsArrayDescriptor", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!16 = !{!12, !6, i64 0}
!17 = !{!15, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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: nounwind uwtable
define dso_local void @XsArray_erase(ptr nocapture noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %2, 0
  br i1 %4, label %28, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %.not = icmp ugt i64 %7, %1
  br i1 %.not, label %8, label %28

8:                                                ; preds = %5
  %9 = add i64 %2, %1
  %10 = icmp ugt i64 %9, %7
  %11 = sub i64 %7, %1
  %spec.select = select i1 %10, i64 %11, i64 %2
  %12 = sub i64 %7, %spec.select
  %13 = icmp ugt i64 %12, %1
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  br label %15

15:                                               ; preds = %.lr.ph, %15
  %.02429 = phi i64 [ %1, %.lr.ph ], [ %26, %15 ]
  %16 = load ptr, ptr %14, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %0, align 8, !tbaa !14
  %20 = load i64, ptr %16, align 8, !tbaa !15
  %21 = mul i64 %20, %.02429
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  %23 = add i64 %.02429, %spec.select
  %24 = mul i64 %20, %23
  %25 = getelementptr inbounds i8, ptr %19, i64 %24
  tail call void %18(ptr noundef %22, ptr noundef %25) #1
  %26 = add nuw i64 %.02429, 1
  %27 = icmp ult i64 %26, %12
  br i1 %27, label %15, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %15, %8
  store i64 %12, ptr %6, align 8, !tbaa !18
  br label %28

28:                                               ; preds = %3, %5, %._crit_edge
  ret void
}

attributes #0 = { 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 = { 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, !10, i64 8}
!6 = !{!"XsArray", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 32}
!12 = !{!13, !7, i64 8}
!13 = !{!"XsArrayDescriptor", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!14 = !{!6, !7, i64 0}
!15 = !{!13, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !10, i64 0}


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