; 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

declare ptr @xalloc(ptr noundef, i64 noundef) #1

; 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 ptr @XArray_Init(ptr noundef %0, ptr noundef %1, i64 noundef %2, i8 noundef zeroext %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i8 %3, ptr %9, align 1, !tbaa !11
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XArray_, ptr %11, i32 0, i32 2
  store i32 1, ptr %12, align 8, !tbaa !12
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XArray_, ptr %13, i32 0, i32 1
  store ptr null, ptr %14, align 8, !tbaa !15
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XArray_, ptr %15, i32 0, i32 0
  store ptr null, ptr %16, align 8, !tbaa !16
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XArray_, ptr %18, i32 0, i32 7
  store i64 %17, ptr %19, align 8, !tbaa !17
  %20 = load i8, ptr %9, align 1, !tbaa !11
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XArray_, ptr %21, i32 0, i32 5
  store i8 %20, ptr %22, align 1, !tbaa !18
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XArray_, ptr %23, i32 0, i32 6
  store i8 0, ptr %24, align 2, !tbaa !19
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XArray_, ptr %25, i32 0, i32 8
  store i64 0, ptr %26, align 8, !tbaa !20
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XArray_, ptr %28, i32 0, i32 3
  store ptr %27, ptr %29, align 8, !tbaa !21
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XArray_, ptr %30, i32 0, i32 4
  store i8 0, ptr %31, align 8, !tbaa !22
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %4
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = mul i64 %36, 8
  %38 = call ptr @xalloc(ptr noundef %35, i64 noundef %37)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XArray_, ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !16
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.XArray_, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %46

45:                                               ; preds = %34
  store ptr null, ptr %5, align 8
  br label %65

46:                                               ; preds = %34
  br label %47

47:                                               ; preds = %46, %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %58, %47
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %61

52:                                               ; preds = %48
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.XArray_, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = getelementptr inbounds ptr, ptr %55, i64 %56
  store ptr null, ptr %57, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %52
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %10, align 8, !tbaa !9
  br label %48, !llvm.loop !23

61:                                               ; preds = %48
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.XArray_, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  store ptr %64, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %65

65:                                               ; preds = %61, %45
  %66 = load ptr, ptr %5, align 8
  ret ptr %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 16}
!13 = !{!"XArray_", !6, i64 0, !6, i64 8, !14, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !10, i64 40, !10, i64 48}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !6, i64 8}
!16 = !{!13, !6, i64 0}
!17 = !{!13, !10, i64 40}
!18 = !{!13, !7, i64 33}
!19 = !{!13, !7, i64 34}
!20 = !{!13, !10, i64 48}
!21 = !{!13, !6, i64 24}
!22 = !{!13, !7, i64 32}
!23 = distinct !{!23, !24}
!24 = !{!"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"

declare ptr @xalloc(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @XArray_Init(ptr nocapture noundef %0, ptr noundef %1, i64 noundef %2, i8 noundef zeroext %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 1, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  store i64 %2, ptr %6, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 33
  store i8 %3, ptr %7, align 1, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 34
  store i8 0, ptr %8, align 2, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 0, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %1, ptr %10, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  store i8 0, ptr %11, align 8, !tbaa !17
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %12

12:                                               ; preds = %4
  %13 = shl i64 %2, 3
  %14 = tail call ptr @xalloc(ptr noundef %1, i64 noundef %13) #3
  store ptr %14, ptr %0, align 8, !tbaa !18
  %15 = icmp eq ptr %14, null
  br i1 %15, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %12
  %xtraiter = and i64 %2, 3
  %16 = icmp ult i64 %2, 4
  br i1 %16, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %2, -4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.025 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %28, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %17 = load ptr, ptr %0, align 8, !tbaa !18
  %18 = getelementptr inbounds ptr, ptr %17, i64 %.025
  store ptr null, ptr %18, align 8, !tbaa !19
  %19 = or disjoint i64 %.025, 1
  %20 = load ptr, ptr %0, align 8, !tbaa !18
  %21 = getelementptr inbounds ptr, ptr %20, i64 %19
  store ptr null, ptr %21, align 8, !tbaa !19
  %22 = or disjoint i64 %.025, 2
  %23 = load ptr, ptr %0, align 8, !tbaa !18
  %24 = getelementptr inbounds ptr, ptr %23, i64 %22
  store ptr null, ptr %24, align 8, !tbaa !19
  %25 = or disjoint i64 %.025, 3
  %26 = load ptr, ptr %0, align 8, !tbaa !18
  %27 = getelementptr inbounds ptr, ptr %26, i64 %25
  store ptr null, ptr %27, align 8, !tbaa !19
  %28 = add nuw i64 %.025, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !20

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.025.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %28, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.025.epil = phi i64 [ %31, %.lr.ph.epil ], [ %.025.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %29 = load ptr, ptr %0, align 8, !tbaa !18
  %30 = getelementptr inbounds ptr, ptr %29, i64 %.025.epil
  store ptr null, ptr %30, align 8, !tbaa !19
  %31 = add nuw i64 %.025.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.lr.ph.epil, !llvm.loop !22

._crit_edge.loopexit:                             ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa
  %.pre = load ptr, ptr %0, align 8, !tbaa !18
  br label %._crit_edge

._crit_edge:                                      ; preds = %4, %._crit_edge.loopexit, %12
  %.023 = phi ptr [ null, %12 ], [ %.pre, %._crit_edge.loopexit ], [ null, %4 ]
  ret ptr %.023
}

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

attributes #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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 16}
!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, !11, i64 40}
!13 = !{!6, !8, i64 33}
!14 = !{!6, !8, i64 34}
!15 = !{!6, !11, i64 48}
!16 = !{!6, !7, i64 24}
!17 = !{!6, !8, i64 32}
!18 = !{!6, !7, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.unroll.disable"}


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