; 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 ptr @XArray_Init(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @XArray_CheckSpace(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i64 0, ptr %2, align 8
  br label %59

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XArray_, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %39

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XArray_, ptr %16, i32 0, i32 6
  %18 = load i8, ptr %17, align 2, !tbaa !13
  store i8 %18, ptr %4, align 1, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XArray_, ptr %19, i32 0, i32 4
  %21 = load i8, ptr %20, align 8, !tbaa !15
  store i8 %21, ptr %5, align 1, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XArray_, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XArray_, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = call ptr @XArray_Init(ptr noundef %25, ptr noundef %28, i64 noundef 8, i8 noundef zeroext 0)
  %30 = load i8, ptr %5, align 1, !tbaa !14
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.XArray_, ptr %31, i32 0, i32 4
  store i8 %30, ptr %32, align 8, !tbaa !15
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.XArray_, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !16
  %36 = load i8, ptr %4, align 1, !tbaa !14
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XArray_, ptr %37, i32 0, i32 6
  store i8 %36, ptr %38, align 2, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  br label %51

39:                                               ; preds = %10
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XArray_, ptr %40, i32 0, i32 8
  %42 = load i64, ptr %41, align 8, !tbaa !18
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.XArray_, ptr %43, i32 0, i32 7
  %45 = load i64, ptr %44, align 8, !tbaa !19
  %46 = icmp uge i64 %42, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %39
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = call i64 @XArray_Realloc(ptr noundef %48)
  store i64 %49, ptr %2, align 8
  br label %59

50:                                               ; preds = %39
  br label %51

51:                                               ; preds = %50, %15
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XArray_, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = icmp eq ptr %54, null
  %56 = zext i1 %55 to i64
  %57 = select i1 %55, i32 0, i32 1
  %58 = sext i32 %57 to i64
  store i64 %58, ptr %2, align 8
  br label %59

59:                                               ; preds = %51, %47, %9
  %60 = load i64, ptr %2, align 8
  ret i64 %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, !6, i64 0}
!10 = !{!"XArray_", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !12, i64 40, !12, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !7, i64 34}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !7, i64 32}
!16 = !{!10, !6, i64 8}
!17 = !{!10, !6, i64 24}
!18 = !{!10, !12, i64 48}
!19 = !{!10, !12, i64 40}


; 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 ptr @XArray_Init(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @XArray_CheckSpace(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %25, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %18

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 34
  %8 = load i8, ptr %7, align 2, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load i8, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = tail call ptr @XArray_Init(ptr noundef nonnull %0, ptr noundef %14, i64 noundef 8, i8 noundef zeroext 0)
  store i8 %10, ptr %9, align 8, !tbaa !13
  store ptr %12, ptr %11, align 8, !tbaa !14
  store i8 %8, ptr %7, align 2, !tbaa !12
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  %16 = icmp ne ptr %.pre, null
  %17 = zext i1 %16 to i64
  br label %25

18:                                               ; preds = %3
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  %20 = load i64, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 40
  %22 = load i64, ptr %21, align 8, !tbaa !17
  %.not = icmp ult i64 %20, %22
  br i1 %.not, label %25, label %23

23:                                               ; preds = %18
  %24 = tail call i64 @XArray_Realloc(ptr noundef nonnull %0)
  br label %25

25:                                               ; preds = %6, %18, %1, %23
  %.0 = phi i64 [ %24, %23 ], [ 0, %1 ], [ 1, %18 ], [ %17, %6 ]
  ret i64 %.0
}

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, !7, i64 0}
!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, !8, i64 34}
!13 = !{!6, !8, i64 32}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !11, i64 48}
!17 = !{!6, !11, i64 40}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass