; 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: nounwind uwtable
define dso_local void @XsString_assign(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = 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
  %7 = load i64, ptr %5, align 8, !tbaa !9
  %8 = icmp ne i64 %7, 0
  br i1 %8, label %16, label %9

9:                                                ; preds = %3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %16

12:                                               ; preds = %9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #5
  %15 = add i64 %14, 1
  store i64 %15, ptr %5, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %12, %9, %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %45

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = sub i64 %21, 1
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = icmp ne i8 %24, 0
  br i1 %25, label %26, label %40

26:                                               ; preds = %19
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = add i64 %28, 1
  call void @XsArray_assign(ptr noundef %27, i64 noundef %29, ptr noundef null)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XsString, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 %33, i64 %34, i1 false)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XsString, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  store i8 0, ptr %39, align 1, !tbaa !11
  br label %44

40:                                               ; preds = %19
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XsArray_assign(ptr noundef %41, i64 noundef %42, ptr noundef %43)
  br label %44

44:                                               ; preds = %40, %26
  br label %64

45:                                               ; preds = %16
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %61

48:                                               ; preds = %45
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = add i64 %50, 1
  call void @XsArray_assign(ptr noundef %49, i64 noundef %51, ptr noundef null)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XsString, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !12
  %55 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %54, i8 32, i64 %55, i1 false)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.XsString, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !12
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  store i8 0, ptr %60, align 1, !tbaa !11
  br label %63

61:                                               ; preds = %45
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  call void @XsArray_assign(ptr noundef %62, i64 noundef 0, ptr noundef null)
  br label %63

63:                                               ; preds = %61, %48
  br label %64

64:                                               ; preds = %63, %44
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

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

; 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) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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" }
attributes #1 = { 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 #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"XsString", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32}


; 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
define dso_local void @XsString_assign(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %1, 0
  %5 = icmp ne ptr %2, null
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %.thread, label %8

.thread:                                          ; preds = %3
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #5
  %7 = add i64 %6, 1
  br label %9

8:                                                ; preds = %3
  br i1 %5, label %9, label %19

9:                                                ; preds = %.thread, %8
  %.027 = phi i64 [ %7, %.thread ], [ %1, %8 ]
  %10 = getelementptr i8, ptr %2, i64 %.027
  %11 = getelementptr i8, ptr %10, i64 -1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not25 = icmp eq i8 %12, 0
  br i1 %.not25, label %18, label %13

13:                                               ; preds = %9
  %14 = add i64 %.027, 1
  tail call void @XsArray_assign(ptr noundef %0, i64 noundef %14, ptr noundef null) #6
  %15 = load ptr, ptr %0, align 8, !tbaa !8
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %15, ptr nonnull align 1 %2, i64 %.027, i1 false)
  %16 = load ptr, ptr %0, align 8, !tbaa !8
  %17 = getelementptr inbounds i8, ptr %16, i64 %.027
  store i8 0, ptr %17, align 1, !tbaa !5
  br label %26

18:                                               ; preds = %9
  tail call void @XsArray_assign(ptr noundef %0, i64 noundef %.027, ptr noundef nonnull %2) #6
  br label %26

19:                                               ; preds = %8
  br i1 %4, label %25, label %20

20:                                               ; preds = %19
  %21 = add i64 %1, 1
  tail call void @XsArray_assign(ptr noundef %0, i64 noundef %21, ptr noundef null) #6
  %22 = load ptr, ptr %0, align 8, !tbaa !8
  tail call void @llvm.memset.p0.i64(ptr align 1 %22, i8 32, i64 %1, i1 false)
  %23 = load ptr, ptr %0, align 8, !tbaa !8
  %24 = getelementptr inbounds i8, ptr %23, i64 %1
  store i8 0, ptr %24, align 1, !tbaa !5
  br label %26

25:                                               ; preds = %19
  tail call void @XsArray_assign(ptr noundef %0, i64 noundef 0, ptr noundef null) #6
  br label %26

26:                                               ; preds = %20, %25, %13, %18
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

declare void @XsArray_assign(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; 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) #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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" }
attributes #1 = { 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 #2 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"XsString", !10, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !10, i64 32}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"long", !6, i64 0}


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