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

; 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.XsString = type { ptr, i64, i64, i64, ptr }
%struct.XsStringArray = type { ptr, i64, i64, i64, ptr }

declare void @XsString_construct(ptr noundef) #0

declare void @XsArray_destruct(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @XsStringArray_fromSplicedString(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.XsString, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #4
  call void @XsString_construct(ptr noundef %7)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @XsArray_destruct(ptr noundef %11)
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.XsString, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp ugt i64 %14, 0
  br i1 %15, label %16, label %77

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.XsString, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = icmp ule i64 %19, 1
  br i1 %20, label %21, label %24

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  call void @XsArray_insert(ptr noundef %22, i64 noundef 0, i64 noundef 1, ptr noundef %23)
  br label %76

24:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XsString, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XsString, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  store ptr %30, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = call ptr @strpbrk(ptr noundef %31, ptr noundef %32) #5
  store ptr %33, ptr %10, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %59, %24
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %42

37:                                               ; preds = %34
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = sext i8 %39 to i32
  %41 = icmp ne i32 %40, 0
  br label %42

42:                                               ; preds = %37, %34
  %43 = phi i1 [ false, %34 ], [ %41, %37 ]
  br i1 %43, label %44, label %65

44:                                               ; preds = %42
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = icmp ne ptr %45, %46
  br i1 %47, label %48, label %59

48:                                               ; preds = %44
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = ptrtoint ptr %49 to i64
  %52 = ptrtoint ptr %50 to i64
  %53 = sub i64 %51, %52
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  call void @XsString_assign(ptr noundef %7, i64 noundef %53, ptr noundef %54)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.XsStringArray, ptr %56, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !14
  call void @XsArray_insert(ptr noundef %55, i64 noundef %58, i64 noundef 1, ptr noundef %7)
  br label %59

59:                                               ; preds = %48, %44
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 1
  store ptr %61, ptr %9, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = call ptr @strpbrk(ptr noundef %62, ptr noundef %63) #5
  store ptr %64, ptr %10, align 8, !tbaa !5
  br label %34, !llvm.loop !16

65:                                               ; preds = %42
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load i8, ptr %66, align 1, !tbaa !13
  %68 = icmp ne i8 %67, 0
  br i1 %68, label %69, label %75

69:                                               ; preds = %65
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  call void @XsString_assignCharArray(ptr noundef %7, ptr noundef %70)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.XsStringArray, ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 8, !tbaa !14
  call void @XsArray_insert(ptr noundef %71, i64 noundef %74, i64 noundef 1, ptr noundef %7)
  br label %75

75:                                               ; preds = %69, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %76

76:                                               ; preds = %75, %21
  br label %77

77:                                               ; preds = %76, %3
  call void @XsString_destruct(ptr noundef %7)
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

declare void @XsArray_insert(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strpbrk(ptr noundef, ptr noundef) #3

declare void @XsString_assign(ptr noundef, i64 noundef, ptr noundef) #0

declare void @XsString_assignCharArray(ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare void @XsString_destruct(ptr noundef) #0

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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, !11, i64 8}
!10 = !{!"XsString", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !11, i64 8}
!15 = !{!"XsStringArray", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.XsString = type { ptr, i64, i64, i64, ptr }

declare void @XsString_construct(ptr noundef) local_unnamed_addr #0

declare void @XsArray_destruct(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XsStringArray_fromSplicedString(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = alloca %struct.XsString, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #4
  call void @XsString_construct(ptr noundef nonnull %4) #4
  call void @XsArray_destruct(ptr noundef %0) #4
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %.critedge.thread, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = icmp ult i64 %9, 2
  br i1 %10, label %11, label %12

11:                                               ; preds = %7
  call void @XsArray_insert(ptr noundef %0, i64 noundef 0, i64 noundef 1, ptr noundef nonnull %1) #4
  br label %.critedge.thread

12:                                               ; preds = %7
  %13 = load ptr, ptr %2, align 8, !tbaa !11
  %14 = load ptr, ptr %1, align 8, !tbaa !11
  %15 = call ptr @strpbrk(ptr noundef %14, ptr noundef %13) #5
  %.not2632 = icmp eq ptr %15, null
  br i1 %.not2632, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  br label %17

17:                                               ; preds = %.lr.ph, %25
  %.034 = phi ptr [ %15, %.lr.ph ], [ %27, %25 ]
  %.02533 = phi ptr [ %14, %.lr.ph ], [ %26, %25 ]
  %18 = load i8, ptr %.02533, align 1, !tbaa !12
  %.not27 = icmp eq i8 %18, 0
  br i1 %.not27, label %.critedge.thread, label %19

19:                                               ; preds = %17
  %.not29 = icmp eq ptr %.034, %.02533
  br i1 %.not29, label %25, label %20

20:                                               ; preds = %19
  %21 = ptrtoint ptr %.034 to i64
  %22 = ptrtoint ptr %.02533 to i64
  %23 = sub i64 %21, %22
  call void @XsString_assign(ptr noundef nonnull %4, i64 noundef %23, ptr noundef nonnull %.02533) #4
  %24 = load i64, ptr %16, align 8, !tbaa !13
  call void @XsArray_insert(ptr noundef %0, i64 noundef %24, i64 noundef 1, ptr noundef nonnull %4) #4
  br label %25

25:                                               ; preds = %20, %19
  %26 = getelementptr inbounds i8, ptr %.034, i64 1
  %27 = call ptr @strpbrk(ptr noundef nonnull %26, ptr noundef %13) #5
  %.not26 = icmp eq ptr %27, null
  br i1 %.not26, label %.critedge, label %17, !llvm.loop !15

.critedge:                                        ; preds = %25, %12
  %.025.lcssa = phi ptr [ %14, %12 ], [ %26, %25 ]
  %.pr = load i8, ptr %.025.lcssa, align 1, !tbaa !12
  %.not28 = icmp eq i8 %.pr, 0
  br i1 %.not28, label %.critedge.thread, label %28

28:                                               ; preds = %.critedge
  call void @XsString_assignCharArray(ptr noundef nonnull %4, ptr noundef nonnull %.025.lcssa) #4
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load i64, ptr %29, align 8, !tbaa !13
  call void @XsArray_insert(ptr noundef %0, i64 noundef %30, i64 noundef 1, ptr noundef nonnull %4) #4
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %17, %.critedge, %28, %11, %3
  call void @XsString_destruct(ptr noundef nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

declare void @XsArray_insert(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strpbrk(ptr noundef, ptr nocapture noundef) local_unnamed_addr #3

declare void @XsString_assign(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare void @XsString_assignCharArray(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare void @XsString_destruct(ptr noundef) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 8}
!6 = !{!"XsString", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"XsStringArray", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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