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

declare void @XsArray_destruct(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @XsStringArray_join(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, 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 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XsStringArray, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XsStringArray, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = sub i64 %18, 1
  br label %21

20:                                               ; preds = %3
  br label %21

21:                                               ; preds = %20, %15
  %22 = phi i64 [ %19, %15 ], [ 0, %20 ]
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XsString, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !12
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XsString, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !12
  %31 = sub i64 %30, 1
  br label %33

32:                                               ; preds = %21
  br label %33

33:                                               ; preds = %32, %27
  %34 = phi i64 [ %31, %27 ], [ 0, %32 ]
  %35 = mul i64 %22, %34
  store i64 %35, ptr %8, align 8, !tbaa !14
  store i64 0, ptr %7, align 8, !tbaa !14
  br label %36

36:                                               ; preds = %58, %33
  %37 = load i64, ptr %7, align 8, !tbaa !14
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XsStringArray, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = icmp ult i64 %37, %40
  br i1 %41, label %42, label %61

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !14
  %45 = call ptr @XsArray_at(ptr noundef %43, i64 noundef %44)
  %46 = getelementptr inbounds %struct.XsString, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !12
  store i64 %47, ptr %9, align 8, !tbaa !14
  %48 = load i64, ptr %9, align 8, !tbaa !14
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %42
  %51 = load i64, ptr %9, align 8, !tbaa !14
  %52 = sub i64 %51, 1
  br label %54

53:                                               ; preds = %42
  br label %54

54:                                               ; preds = %53, %50
  %55 = phi i64 [ %52, %50 ], [ 0, %53 ]
  %56 = load i64, ptr %8, align 8, !tbaa !14
  %57 = add i64 %56, %55
  store i64 %57, ptr %8, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %58

58:                                               ; preds = %54
  %59 = load i64, ptr %7, align 8, !tbaa !14
  %60 = add i64 %59, 1
  store i64 %60, ptr %7, align 8, !tbaa !14
  br label %36, !llvm.loop !15

61:                                               ; preds = %36
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  call void @XsArray_destruct(ptr noundef %62)
  %63 = load i64, ptr %8, align 8, !tbaa !14
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %99

65:                                               ; preds = %61
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i64, ptr %8, align 8, !tbaa !14
  %68 = add i64 %67, 1
  call void @XsArray_reserve(ptr noundef %66, i64 noundef %68)
  store i64 0, ptr %7, align 8, !tbaa !14
  br label %69

69:                                               ; preds = %95, %65
  %70 = load i64, ptr %7, align 8, !tbaa !14
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.XsStringArray, ptr %71, i32 0, i32 1
  %73 = load i64, ptr %72, align 8, !tbaa !9
  %74 = icmp ult i64 %70, %73
  br i1 %74, label %75, label %98

75:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = load i64, ptr %7, align 8, !tbaa !14
  %78 = call ptr @XsArray_at(ptr noundef %76, i64 noundef %77)
  store ptr %78, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.XsString, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !12
  %82 = icmp ugt i64 %81, 1
  br i1 %82, label %83, label %94

83:                                               ; preds = %75
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.XsString, ptr %84, i32 0, i32 1
  %86 = load i64, ptr %85, align 8, !tbaa !12
  %87 = icmp ugt i64 %86, 1
  br i1 %87, label %88, label %91

88:                                               ; preds = %83
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XsString_append(ptr noundef %89, ptr noundef %90)
  br label %91

91:                                               ; preds = %88, %83
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  call void @XsString_append(ptr noundef %92, ptr noundef %93)
  br label %94

94:                                               ; preds = %91, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %95

95:                                               ; preds = %94
  %96 = load i64, ptr %7, align 8, !tbaa !14
  %97 = add i64 %96, 1
  store i64 %97, ptr %7, align 8, !tbaa !14
  br label %69, !llvm.loop !17

98:                                               ; preds = %69
  br label %99

99:                                               ; preds = %98, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare ptr @XsArray_at(ptr noundef, i64 noundef) #0

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

declare void @XsString_append(ptr noundef, 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 = { nocallback nofree nosync 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 = { 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, !11, i64 8}
!10 = !{!"XsStringArray", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"XsString", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 void @XsArray_destruct(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XsStringArray_join(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %spec.select = tail call i64 @llvm.usub.sat.i64(i64 %5, i64 1)
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = tail call i64 @llvm.usub.sat.i64(i64 %7, i64 1)
  %9 = mul i64 %8, %spec.select
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.033 = phi i64 [ %15, %.lr.ph ], [ 0, %3 ]
  %.02632 = phi i64 [ %14, %.lr.ph ], [ %9, %3 ]
  %10 = tail call ptr @XsArray_at(ptr noundef nonnull %0, i64 noundef %.033) #3
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = tail call i64 @llvm.usub.sat.i64(i64 %12, i64 1)
  %14 = add i64 %13, %.02632
  %15 = add nuw i64 %.033, 1
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.026.lcssa = phi i64 [ %9, %3 ], [ %14, %.lr.ph ]
  tail call void @XsArray_destruct(ptr noundef %1) #3
  %.not30 = icmp eq i64 %.026.lcssa, 0
  br i1 %.not30, label %.loopexit, label %18

18:                                               ; preds = %._crit_edge
  %19 = add i64 %.026.lcssa, 1
  tail call void @XsArray_reserve(ptr noundef %1, i64 noundef %19) #3
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %.not37 = icmp eq i64 %20, 0
  br i1 %.not37, label %.loopexit, label %.lr.ph36

.lr.ph36:                                         ; preds = %18
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  br label %22

22:                                               ; preds = %.lr.ph36, %32
  %.134 = phi i64 [ 0, %.lr.ph36 ], [ %33, %32 ]
  %23 = tail call ptr @XsArray_at(ptr noundef nonnull %0, i64 noundef %.134) #3
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = icmp ugt i64 %25, 1
  br i1 %26, label %27, label %32

27:                                               ; preds = %22
  %28 = load i64, ptr %21, align 8, !tbaa !11
  %29 = icmp ugt i64 %28, 1
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  tail call void @XsString_append(ptr noundef nonnull %1, ptr noundef %2) #3
  br label %31

31:                                               ; preds = %30, %27
  tail call void @XsString_append(ptr noundef nonnull %1, ptr noundef nonnull %23) #3
  br label %32

32:                                               ; preds = %31, %22
  %33 = add nuw i64 %.134, 1
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %22, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %32, %18, %._crit_edge
  ret void
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #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 nosync nounwind speculatable willreturn memory(none) }
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 8}
!6 = !{!"XsStringArray", !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 = !{!12, !10, i64 8}
!12 = !{!"XsString", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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