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

; 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 }

; 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

declare void @XsArray_assign(ptr noundef, i64 noundef, ptr noundef) #1

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

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i64 @wcstombs(ptr noundef null, ptr noundef %10, i64 noundef 0) #4
  store i64 %11, ptr %5, align 8, !tbaa !9
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp ne i64 %12, -1
  br i1 %13, label %14, label %40

14:                                               ; preds = %9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp ugt i64 %15, 0
  br i1 %16, label %17, label %40

17:                                               ; preds = %14
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = add i64 %18, 1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XsString, ptr %20, i32 0, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = icmp ugt i64 %19, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = add i64 %26, 1
  call void @XsArray_reserve(ptr noundef %25, i64 noundef %27)
  br label %28

28:                                               ; preds = %24, %17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XsString, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = add i64 %33, 1
  %35 = call i64 @wcstombs(ptr noundef %31, ptr noundef %32, i64 noundef %34) #4
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = add i64 %36, 1
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XsString, ptr %38, i32 0, i32 1
  store i64 %37, ptr %39, align 8, !tbaa !9
  store i32 1, ptr %6, align 4
  br label %41

40:                                               ; preds = %14, %9
  store i32 0, ptr %6, align 4
  br label %41

41:                                               ; preds = %40, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %42 = load i32, ptr %6, align 4
  switch i32 %42, label %47 [
    i32 0, label %43
    i32 1, label %46
  ]

43:                                               ; preds = %41
  br label %44

44:                                               ; preds = %43, %2
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  call void @XsArray_assign(ptr noundef %45, i64 noundef 0, ptr noundef null)
  br label %46

46:                                               ; preds = %44, %41
  ret void

47:                                               ; preds = %41
  unreachable
}

; Function Attrs: nounwind
declare i64 @wcstombs(ptr noundef, ptr noundef, i64 noundef) #3

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

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 "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 = !{!"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 = !{!"XsString", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32}
!13 = !{!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 void @XsArray_assign(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XsString_assignWCharArray(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.thread, label %3

3:                                                ; preds = %2
  %4 = tail call i64 @wcstombs(ptr noundef null, ptr noundef nonnull %1, i64 noundef 0) #3
  %5 = add i64 %4, -1
  %or.cond = icmp ult i64 %5, -2
  br i1 %or.cond, label %6, label %.thread

6:                                                ; preds = %3
  %7 = add nuw i64 %4, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %.not18 = icmp ult i64 %4, %9
  br i1 %.not18, label %11, label %10

10:                                               ; preds = %6
  tail call void @XsArray_reserve(ptr noundef nonnull %0, i64 noundef %7) #3
  br label %11

11:                                               ; preds = %6, %10
  %12 = load ptr, ptr %0, align 8, !tbaa !11
  %13 = tail call i64 @wcstombs(ptr noundef %12, ptr noundef nonnull %1, i64 noundef %7) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %7, ptr %14, align 8, !tbaa !12
  br label %15

.thread:                                          ; preds = %3, %2
  tail call void @XsArray_assign(ptr noundef %0, i64 noundef 0, ptr noundef null) #3
  br label %15

15:                                               ; preds = %11, %.thread
  ret void
}

; Function Attrs: nounwind
declare i64 @wcstombs(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @XsArray_reserve(ptr noundef, i64 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 = { nounwind "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, !10, i64 16}
!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 = !{!10, !10, i64 0}


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