; LLVM IR from kala13x/libxutils :: src/data (str)

; 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.XString = type { ptr, i64, i64, i16, i8, i8 }

@.str.33 = external hidden unnamed_addr constant [5 x i8], align 1

; 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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XString_Status(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XString_Add(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @XString_AddString(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @XString_Color(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XString, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %24, label %19

19:                                               ; preds = %4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XString, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !14
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %19, %4
  store i32 -1, ptr %5, align 4
  br label %122

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XString, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !14
  %30 = icmp ult i64 %26, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  %32 = load i64, ptr %8, align 8, !tbaa !9
  br label %37

33:                                               ; preds = %25
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.XString, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !14
  br label %37

37:                                               ; preds = %33, %31
  %38 = phi i64 [ %32, %31 ], [ %36, %33 ]
  store i64 %38, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = add i64 %39, %40
  store i64 %41, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XString, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !14
  %45 = load i64, ptr %11, align 8, !tbaa !9
  %46 = sub i64 %44, %45
  store i64 %46, ptr %12, align 8, !tbaa !9
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XString, ptr %48, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !14
  %51 = icmp uge i64 %47, %50
  br i1 %51, label %58, label %52

52:                                               ; preds = %37
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.XString, ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !14
  %57 = icmp ugt i64 %53, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %52, %37
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %121

59:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.XString, ptr %60, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !14
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XString, ptr %63, i32 0, i32 5
  %65 = load i8, ptr %64, align 1, !tbaa !15
  %66 = call ptr @XString_New(i64 noundef %62, i8 noundef zeroext %65)
  store ptr %66, ptr %14, align 8, !tbaa !5
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = icmp eq ptr %67, null
  br i1 %68, label %69, label %70

69:                                               ; preds = %59
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %120

70:                                               ; preds = %59
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.XString, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = load i64, ptr %10, align 8, !tbaa !9
  %76 = call i32 @XString_Add(ptr noundef %71, ptr noundef %74, i64 noundef %75)
  %77 = icmp eq i32 %76, -1
  br i1 %77, label %109, label %78

78:                                               ; preds = %70
  %79 = load ptr, ptr %14, align 8, !tbaa !5
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = call i64 @strnlen(ptr noundef %81, i64 noundef 32) #4
  %83 = call i32 @XString_Add(ptr noundef %79, ptr noundef %80, i64 noundef %82)
  %84 = icmp eq i32 %83, -1
  br i1 %84, label %109, label %85

85:                                               ; preds = %78
  %86 = load ptr, ptr %14, align 8, !tbaa !5
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.XString, ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !11
  %90 = load i64, ptr %10, align 8, !tbaa !9
  %91 = getelementptr inbounds i8, ptr %89, i64 %90
  %92 = load i64, ptr %9, align 8, !tbaa !9
  %93 = call i32 @XString_Add(ptr noundef %86, ptr noundef %91, i64 noundef %92)
  %94 = icmp eq i32 %93, -1
  br i1 %94, label %109, label %95

95:                                               ; preds = %85
  %96 = load ptr, ptr %14, align 8, !tbaa !5
  %97 = call i32 @XString_Add(ptr noundef %96, ptr noundef @.str.33, i64 noundef 4)
  %98 = icmp eq i32 %97, -1
  br i1 %98, label %109, label %99

99:                                               ; preds = %95
  %100 = load ptr, ptr %14, align 8, !tbaa !5
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.XString, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !11
  %104 = load i64, ptr %11, align 8, !tbaa !9
  %105 = getelementptr inbounds i8, ptr %103, i64 %104
  %106 = load i64, ptr %12, align 8, !tbaa !9
  %107 = call i32 @XString_Add(ptr noundef %100, ptr noundef %105, i64 noundef %106)
  %108 = icmp eq i32 %107, -1
  br i1 %108, label %109, label %111

109:                                              ; preds = %99, %95, %85, %78, %70
  %110 = load ptr, ptr %14, align 8, !tbaa !5
  call void @XString_Clear(ptr noundef %110)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %120

111:                                              ; preds = %99
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.XString, ptr %112, i32 0, i32 1
  store i64 0, ptr %113, align 8, !tbaa !14
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = load ptr, ptr %14, align 8, !tbaa !5
  %116 = call i32 @XString_AddString(ptr noundef %114, ptr noundef %115)
  %117 = load ptr, ptr %14, align 8, !tbaa !5
  call void @XString_Clear(ptr noundef %117)
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = call i32 @XString_Status(ptr noundef %118)
  store i32 %119, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %120

120:                                              ; preds = %111, %109, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %121

121:                                              ; preds = %120, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %122

122:                                              ; preds = %121, %24
  %123 = load i32, ptr %5, align 4
  ret i32 %123
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @XString_New(i64 noundef, i8 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 }
attributes #4 = { 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 = !{!12, !6, i64 0}
!12 = !{!"XString", !6, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !7, i64 26, !7, i64 27}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !7, i64 27}


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

@.str.33 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XString_Status(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XString_Add(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XString_AddString(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XString_Color(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %44, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %44, label %10

10:                                               ; preds = %7
  %. = tail call i64 @llvm.umin.i64(i64 %9, i64 %2)
  %11 = add i64 %., %3
  %12 = sub i64 %9, %11
  %.not44 = icmp ule i64 %9, %2
  %13 = icmp ugt i64 %11, %9
  %or.cond = or i1 %.not44, %13
  br i1 %or.cond, label %44, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 27
  %16 = load i8, ptr %15, align 1, !tbaa !13
  %17 = tail call ptr @XString_New(i64 noundef %9, i8 noundef zeroext %16)
  %18 = icmp eq ptr %17, null
  br i1 %18, label %44, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %0, align 8, !tbaa !5
  %21 = tail call i32 @XString_Add(ptr noundef nonnull %17, ptr noundef %20, i64 noundef %.)
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %40, label %23

23:                                               ; preds = %19
  %24 = tail call i64 @strnlen(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 32) #3
  %25 = tail call i32 @XString_Add(ptr noundef nonnull %17, ptr noundef %1, i64 noundef %24)
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %40, label %27

27:                                               ; preds = %23
  %28 = load ptr, ptr %0, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 %.
  %30 = tail call i32 @XString_Add(ptr noundef nonnull %17, ptr noundef %29, i64 noundef %3)
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %40, label %32

32:                                               ; preds = %27
  %33 = tail call i32 @XString_Add(ptr noundef nonnull %17, ptr noundef nonnull @.str.33, i64 noundef 4)
  %34 = icmp eq i32 %33, -1
  br i1 %34, label %40, label %35

35:                                               ; preds = %32
  %36 = load ptr, ptr %0, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 %11
  %38 = tail call i32 @XString_Add(ptr noundef nonnull %17, ptr noundef %37, i64 noundef %12)
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %40, label %41

40:                                               ; preds = %35, %32, %27, %23, %19
  tail call void @XString_Clear(ptr noundef nonnull %17)
  br label %44

41:                                               ; preds = %35
  store i64 0, ptr %8, align 8, !tbaa !12
  %42 = tail call i32 @XString_AddString(ptr noundef nonnull %0, ptr noundef nonnull %17)
  tail call void @XString_Clear(ptr noundef nonnull %17)
  %43 = tail call i32 @XString_Status(ptr noundef nonnull %0)
  br label %44

44:                                               ; preds = %10, %14, %41, %40, %4, %7
  %.2 = phi i32 [ -1, %7 ], [ -1, %4 ], [ -1, %10 ], [ -1, %40 ], [ %43, %41 ], [ -1, %14 ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @XString_New(i64 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

attributes #0 = { 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 #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 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, !7, i64 0}
!6 = !{!"XString", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !8, i64 26, !8, i64 27}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !8, i64 27}


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