; 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
declare dso_local void @XsArray_erase(ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XsArray_removeDuplicates(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.XsArray, ptr %7, i32 0, i32 1
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp ugt i64 %9, 1
  br i1 %10, label %11, label %70

11:                                               ; preds = %1
  store i64 0, ptr %3, align 8, !tbaa !12
  br label %12

12:                                               ; preds = %66, %11
  %13 = load i64, ptr %3, align 8, !tbaa !12
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.XsArray, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = sub i64 %16, 1
  %18 = icmp ult i64 %13, %17
  br i1 %18, label %19, label %69

19:                                               ; preds = %12
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XsArray, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = sub i64 %22, 1
  store i64 %23, ptr %4, align 8, !tbaa !12
  br label %24

24:                                               ; preds = %62, %19
  %25 = load i64, ptr %4, align 8, !tbaa !12
  %26 = load i64, ptr %3, align 8, !tbaa !12
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %28, label %65

28:                                               ; preds = %24
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XsArray, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.XsArray, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = load i64, ptr %3, align 8, !tbaa !12
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XsArray, ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !17
  %43 = mul i64 %37, %42
  %44 = getelementptr inbounds i8, ptr %36, i64 %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.XsArray, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = load i64, ptr %4, align 8, !tbaa !12
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XsArray, ptr %49, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  %52 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !17
  %54 = mul i64 %48, %53
  %55 = getelementptr inbounds i8, ptr %47, i64 %54
  %56 = call i32 %33(ptr noundef %44, ptr noundef %55)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %61, label %58

58:                                               ; preds = %28
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = load i64, ptr %4, align 8, !tbaa !12
  call void @XsArray_erase(ptr noundef %59, i64 noundef %60, i64 noundef 1)
  br label %61

61:                                               ; preds = %58, %28
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %4, align 8, !tbaa !12
  %64 = add i64 %63, -1
  store i64 %64, ptr %4, align 8, !tbaa !12
  br label %24, !llvm.loop !18

65:                                               ; preds = %24
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %3, align 8, !tbaa !12
  %68 = add i64 %67, 1
  store i64 %68, ptr %3, align 8, !tbaa !12
  br label %12, !llvm.loop !20

69:                                               ; preds = %12
  br label %70

70:                                               ; preds = %69, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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, !11, i64 8}
!10 = !{!"XsArray", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 32}
!14 = !{!15, !6, i64 48}
!15 = !{!"XsArrayDescriptor", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!16 = !{!10, !6, i64 0}
!17 = !{!15, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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
declare dso_local void @XsArray_erase(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XsArray_removeDuplicates(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp ugt i64 %3, 1
  br i1 %4, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %1
  %5 = add i64 %3, -1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %23
  %7 = phi i64 [ %5, %.preheader.lr.ph ], [ %26, %23 ]
  %.021 = phi i64 [ 0, %.preheader.lr.ph ], [ %24, %23 ]
  br label %8

8:                                                ; preds = %.preheader, %20
  %.01720 = phi i64 [ %7, %.preheader ], [ %21, %20 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 48
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = load ptr, ptr %0, align 8, !tbaa !14
  %13 = load i64, ptr %9, align 8, !tbaa !15
  %14 = mul i64 %13, %.021
  %15 = getelementptr inbounds i8, ptr %12, i64 %14
  %16 = mul i64 %13, %.01720
  %17 = getelementptr inbounds i8, ptr %12, i64 %16
  %18 = tail call i32 %11(ptr noundef %15, ptr noundef %17) #1
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %20

19:                                               ; preds = %8
  tail call void @XsArray_erase(ptr noundef nonnull %0, i64 noundef %.01720, i64 noundef 1)
  br label %20

20:                                               ; preds = %8, %19
  %21 = add i64 %.01720, -1
  %22 = icmp ugt i64 %21, %.021
  br i1 %22, label %8, label %23, !llvm.loop !16

23:                                               ; preds = %20
  %24 = add nuw i64 %.021, 1
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = add i64 %25, -1
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %.preheader, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %23, %1
  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 48}
!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 = distinct !{!18, !17}


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