; 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 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 ptr @XArray_Remove(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = call ptr @XArray_Get(ptr noundef %9, i64 noundef %10)
  store ptr %11, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %59

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

17:                                               ; preds = %44, %15
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %4, 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 %8, align 8, !tbaa !9
  %25 = add i64 %24, 1
  %26 = load ptr, ptr %4, 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 %4, 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 %8, 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 %4, 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 %8, 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 %8, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %8, align 8, !tbaa !9
  br label %17, !llvm.loop !15

47:                                               ; preds = %30, %17
  %48 = load ptr, ptr %4, 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 %4, 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 %4, align 8, !tbaa !5
  %57 = call i64 @XArray_Realloc(ptr noundef %56)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %58, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %59

59:                                               ; preds = %47, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %60 = load ptr, ptr %3, align 8
  ret ptr %60
}

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 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 ptr @XArray_Remove(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @XArray_Get(ptr noundef %0, i64 noundef %1)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %42, label %.preheader

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

.lr.ph.preheader:                                 ; preds = %.preheader
  %9 = xor i64 %1, -1
  %10 = add i64 %6, %9
  %11 = add i64 %6, -2
  %12 = sub i64 %11, %1
  %xtraiter = and i64 %10, 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 [ %13, %.lr.ph.prol ], [ %1, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %13 = add nuw i64 %.02226.prol, 1
  %14 = load ptr, ptr %0, align 8, !tbaa !12
  %15 = getelementptr inbounds ptr, ptr %14, i64 %13
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds ptr, ptr %14, i64 %.02226.prol
  store ptr %16, ptr %17, 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 ], [ %13, %.lr.ph.prol ]
  %18 = icmp ult i64 %12, 3
  br i1 %18, label %._crit_edge, label %.lr.ph

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

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.preheader
  %39 = load ptr, ptr %0, align 8, !tbaa !12
  store i64 %8, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds ptr, ptr %39, i64 %8
  store ptr null, ptr %40, align 8, !tbaa !13
  %41 = tail call i64 @XArray_Realloc(ptr noundef nonnull %0)
  br label %42

42:                                               ; preds = %2, %._crit_edge
  ret ptr %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" }

!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