; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsvector)

; 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.XsVector = type { ptr, 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 @xsAlignedMalloc(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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @XsVector_assign(ptr noundef %0, i64 noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.XsVector, ptr %8, i32 0, i32 2
  %10 = load i64, ptr %9, align 1, !tbaa !11
  %11 = icmp eq i64 %10, 2
  br i1 %11, label %12, label %25

12:                                               ; preds = %3
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XsVector, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 1, !tbaa !9
  %19 = or i64 %18, 4
  store i64 %19, ptr %17, align 1, !tbaa !9
  br label %65

20:                                               ; preds = %12
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XsVector, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 1, !tbaa !9
  %24 = and i64 %23, -5
  store i64 %24, ptr %22, align 1, !tbaa !9
  br label %25

25:                                               ; preds = %20, %3
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XsVector, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 1, !tbaa !13
  %30 = icmp ugt i64 %26, %29
  br i1 %30, label %34, label %31

31:                                               ; preds = %25
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %49

34:                                               ; preds = %31, %25
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  call void @XsVector_destruct(ptr noundef %35)
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %48

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = mul i64 %39, 8
  %41 = call ptr @xsAlignedMalloc(i64 noundef %40)
  store ptr %41, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.XsVector, ptr %43, i32 0, i32 0
  store ptr %42, ptr %44, align 1, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.XsVector, ptr %45, i32 0, i32 2
  store i64 1, ptr %46, align 1, !tbaa !9
  %47 = call i32 @XsVector_incAllocCount()
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %48

48:                                               ; preds = %38, %34
  br label %49

49:                                               ; preds = %48, %31
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XsVector, ptr %51, i32 0, i32 1
  store i64 %50, ptr %52, align 1, !tbaa !9
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %65

55:                                               ; preds = %49
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %58, label %65

58:                                               ; preds = %55
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.XsVector, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 1, !tbaa !14
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i64, ptr %5, align 8, !tbaa !9
  %64 = mul i64 %63, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %61, ptr align 8 %62, i64 %64, i1 false)
  br label %65

65:                                               ; preds = %58, %55, %49, %15
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @XsVector_destruct(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @XsVector_incAllocCount() #4

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { 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 #5 = { 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 16}
!12 = !{!"XsVector", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 0}


; 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 @xsAlignedMalloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local void @XsVector_assign(ptr noundef %0, i64 noundef %1, ptr noundef readonly %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 1, !tbaa !5
  %6 = icmp eq i64 %5, 2
  br i1 %6, label %7, label %11

7:                                                ; preds = %3
  %8 = icmp eq i64 %1, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %7
  store i64 6, ptr %4, align 1, !tbaa !5
  br label %24

10:                                               ; preds = %7
  store i64 2, ptr %4, align 1, !tbaa !5
  br label %11

11:                                               ; preds = %10, %3
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i64, ptr %12, align 1, !tbaa !9
  %14 = add i64 %1, -1
  %or.cond.not = icmp ult i64 %14, %13
  br i1 %or.cond.not, label %20, label %15

15:                                               ; preds = %11
  tail call void @XsVector_destruct(ptr noundef nonnull %0)
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.thread, label %16

.thread:                                          ; preds = %15
  store i64 0, ptr %12, align 1, !tbaa !5
  br label %24

16:                                               ; preds = %15
  %17 = shl i64 %1, 3
  %18 = tail call ptr @xsAlignedMalloc(i64 noundef %17) #4
  store ptr %18, ptr %0, align 1, !tbaa !12
  store i64 1, ptr %4, align 1, !tbaa !5
  %19 = tail call i32 @XsVector_incAllocCount()
  br label %20

20:                                               ; preds = %16, %11
  store i64 %1, ptr %12, align 1, !tbaa !5
  %.not25 = icmp eq ptr %2, null
  br i1 %.not25, label %24, label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %0, align 1, !tbaa !13
  %23 = shl i64 %1, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr nonnull align 8 %2, i64 %23, i1 false)
  br label %24

24:                                               ; preds = %.thread, %21, %20, %9
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @XsVector_destruct(ptr noundef) local_unnamed_addr #2

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

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"XsVector", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 0}


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