; 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_destruct(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.XsArray, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %56

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XsArray, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !12
  %14 = and i64 %13, 1
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %56

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.XsArray, ptr %17, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %19, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %51

23:                                               ; preds = %16
  store i64 0, ptr %4, align 8, !tbaa !16
  br label %24

24:                                               ; preds = %47, %23
  %25 = load i64, ptr %4, align 8, !tbaa !16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XsArray, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !17
  %29 = icmp ult i64 %25, %28
  br i1 %29, label %30, label %50

30:                                               ; preds = %24
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.XsArray, ptr %31, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XsArray, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = load i64, ptr %4, align 8, !tbaa !16
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XsArray, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !18
  %45 = mul i64 %39, %44
  %46 = getelementptr inbounds i8, ptr %38, i64 %45
  call void %35(ptr noundef %46)
  br label %47

47:                                               ; preds = %30
  %48 = load i64, ptr %4, align 8, !tbaa !16
  %49 = add i64 %48, 1
  store i64 %49, ptr %4, align 8, !tbaa !16
  br label %24, !llvm.loop !19

50:                                               ; preds = %24
  br label %51

51:                                               ; preds = %50, %16
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XsArray, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  call void @free(ptr noundef %54) #4
  %55 = call i32 @XsArray_incFreeCount()
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %56

56:                                               ; preds = %51, %10, %1
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.XsArray, ptr %57, i32 0, i32 0
  store ptr null, ptr %58, align 8, !tbaa !5
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.XsArray, ptr %59, i32 0, i32 1
  store i64 0, ptr %60, align 8, !tbaa !16
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.XsArray, ptr %61, i32 0, i32 2
  store i64 0, ptr %62, align 8, !tbaa !16
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XsArray, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !12
  %66 = and i64 %65, 3
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.XsArray, ptr %67, i32 0, i32 3
  store i64 %66, ptr %68, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @XsArray_incFreeCount() #3

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 "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 = { inlinehint 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 #4 = { 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, !6, i64 0}
!10 = !{!"XsArray", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 24}
!13 = !{!10, !6, i64 32}
!14 = !{!15, !6, i64 32}
!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 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 16}
!18 = !{!15, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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_destruct(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %26, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = and i64 %5, 1
  %.not16 = icmp eq i64 %6, 0
  br i1 %.not16, label %26, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %.not17 = icmp eq ptr %11, null
  br i1 %.not17, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %.not19 = icmp eq i64 %13, 0
  br i1 %.not19, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.018 = phi i64 [ %21, %.lr.ph ], [ 0, %.preheader ]
  %14 = load ptr, ptr %8, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %14, i64 32
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = load i64, ptr %14, align 8, !tbaa !16
  %19 = mul i64 %18, %.018
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  tail call void %16(ptr noundef %20) #4
  %21 = add nuw i64 %.018, 1
  %22 = load i64, ptr %12, align 8, !tbaa !15
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph, label %.loopexit.loopexit, !llvm.loop !17

.loopexit.loopexit:                               ; preds = %.lr.ph
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.preheader, %7
  %24 = phi ptr [ %.pre, %.loopexit.loopexit ], [ %2, %.preheader ], [ %2, %7 ]
  tail call void @free(ptr noundef %24) #4
  %25 = tail call i32 @XsArray_incFreeCount()
  br label %26

26:                                               ; preds = %.loopexit, %3, %1
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, i8 0, i64 24, i1 false)
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = and i64 %28, 3
  store i64 %29, ptr %27, align 8, !tbaa !19
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @XsArray_incFreeCount() local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !7, i64 0}
!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, !10, i64 24}
!12 = !{!6, !7, i64 32}
!13 = !{!14, !7, i64 32}
!14 = !{!"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}
!15 = !{!6, !10, i64 16}
!16 = !{!14, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !10, i64 0}


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