; LLVM IR from kala13x/libxutils :: src/data (array)

; 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.XArray_ = type { ptr, ptr, i32, ptr, i8, i8, i8, i64, i64 }

; 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 @XArray_ClearData(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @XArray_Realloc(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @XArray_Get(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XArray_Delete(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = call ptr @XArray_Get(ptr noundef %7, i64 noundef %8)
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  call void @XArray_ClearData(ptr noundef %13, ptr noundef %14)
  br label %15

15:                                               ; preds = %12, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %16 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %16, ptr %6, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %44, %15
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XArray_, ptr %19, i32 0, i32 8
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp ult i64 %18, %21
  br i1 %22, label %23, label %47

23:                                               ; preds = %17
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = add i64 %24, 1
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XArray_, ptr %26, i32 0, i32 8
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = icmp uge i64 %25, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  br label %47

31:                                               ; preds = %23
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XArray_, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = add i64 %35, 1
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XArray_, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  store ptr %38, ptr %43, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %31
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %6, align 8, !tbaa !9
  br label %17, !llvm.loop !15

47:                                               ; preds = %30, %17
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XArray_, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XArray_, ptr %51, i32 0, i32 8
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = add i64 %53, -1
  store i64 %54, ptr %52, align 8, !tbaa !11
  %55 = getelementptr inbounds ptr, ptr %50, i64 %54
  store ptr null, ptr %55, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = call i64 @XArray_Realloc(ptr noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"XArray_", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !10, i64 40, !10, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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
declare dso_local void @XArray_ClearData(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @XArray_Realloc(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @XArray_Get(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XArray_Delete(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @XArray_Get(ptr noundef %0, i64 noundef %1)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %2
  tail call void @XArray_ClearData(ptr noundef %0, ptr noundef nonnull %3)
  br label %5

5:                                                ; preds = %4, %2
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp ule i64 %7, %1
  %9 = add i64 %7, -1
  %exitcond.not25 = icmp eq i64 %9, %1
  %or.cond = or i1 %8, %exitcond.not25
  br i1 %or.cond, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %10 = xor i64 %1, -1
  %11 = add i64 %7, %10
  %12 = add i64 %7, -2
  %13 = sub i64 %12, %1
  %xtraiter = and i64 %11, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.02226.prol = phi i64 [ %14, %.lr.ph.prol ], [ %1, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %14 = add nuw i64 %.02226.prol, 1
  %15 = load ptr, ptr %0, align 8, !tbaa !12
  %16 = getelementptr inbounds ptr, ptr %15, i64 %14
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = getelementptr inbounds ptr, ptr %15, i64 %.02226.prol
  store ptr %17, ptr %18, align 8, !tbaa !13
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !14

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.02226.unr = phi i64 [ %1, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %19 = icmp ult i64 %13, 3
  br i1 %19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.02226 = phi i64 [ %35, %.lr.ph ], [ %.02226.unr, %.lr.ph.prol.loopexit ]
  %20 = add nuw i64 %.02226, 1
  %21 = load ptr, ptr %0, align 8, !tbaa !12
  %22 = getelementptr inbounds ptr, ptr %21, i64 %20
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds ptr, ptr %21, i64 %.02226
  store ptr %23, ptr %24, align 8, !tbaa !13
  %25 = add nuw i64 %.02226, 2
  %26 = load ptr, ptr %0, align 8, !tbaa !12
  %27 = getelementptr inbounds ptr, ptr %26, i64 %25
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds ptr, ptr %26, i64 %20
  store ptr %28, ptr %29, align 8, !tbaa !13
  %30 = add nuw i64 %.02226, 3
  %31 = load ptr, ptr %0, align 8, !tbaa !12
  %32 = getelementptr inbounds ptr, ptr %31, i64 %30
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds ptr, ptr %31, i64 %25
  store ptr %33, ptr %34, align 8, !tbaa !13
  %35 = add nuw i64 %.02226, 4
  %36 = load ptr, ptr %0, align 8, !tbaa !12
  %37 = getelementptr inbounds ptr, ptr %36, i64 %35
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = getelementptr inbounds ptr, ptr %36, i64 %30
  store ptr %38, ptr %39, align 8, !tbaa !13
  %exitcond.not.3 = icmp eq i64 %35, %9
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %5
  %40 = load ptr, ptr %0, align 8, !tbaa !12
  store i64 %9, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds ptr, ptr %40, i64 %9
  store ptr null, ptr %41, align 8, !tbaa !13
  %42 = tail call i64 @XArray_Realloc(ptr noundef nonnull %0)
  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" }

!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, !11, i64 48}
!6 = !{!"XArray_", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !8, i64 32, !8, i64 33, !8, i64 34, !11, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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