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

@.str.38 = external hidden unnamed_addr constant [3 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @xstrncpys(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #3

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

; Function Attrs: nounwind uwtable
define dso_local ptr @xstrrep(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %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 i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i64 @strlen(ptr noundef %18) #5
  store i64 %19, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call i64 @strlen(ptr noundef %20) #5
  store i64 %21, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #5
  store i64 %23, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %32, %3
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = load i32, ptr %11, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i32 @xstrntokn(ptr noundef null, i64 noundef 0, ptr noundef %25, i64 noundef %26, i64 noundef %28, ptr noundef %29)
  store i32 %30, ptr %11, align 4, !tbaa !11
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %24
  %33 = load i32, ptr %12, align 4, !tbaa !11
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %12, align 4, !tbaa !11
  br label %24, !llvm.loop !13

35:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = sub i64 %36, %37
  %39 = load i32, ptr %12, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = mul i64 %38, %40
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = add i64 %41, %42
  %44 = add i64 %43, 1
  store i64 %44, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = call noalias ptr @malloc(i64 noundef %45) #6
  store ptr %46, ptr %14, align 8, !tbaa !5
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %50, label %49

49:                                               ; preds = %35
  store ptr null, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %108

50:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %51, ptr %16, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %101, %50
  %53 = load i32, ptr %12, align 4, !tbaa !11
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr %12, align 4, !tbaa !11
  %55 = icmp ne i32 %53, 0
  br i1 %55, label %56, label %102

56:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = call i32 @xstrsrc(ptr noundef %57, ptr noundef %58)
  store i32 %59, ptr %17, align 4, !tbaa !11
  %60 = load i32, ptr %17, align 4, !tbaa !11
  %61 = icmp slt i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %56
  store i32 5, ptr %15, align 4
  br label %99

63:                                               ; preds = %56
  %64 = load i32, ptr %17, align 4, !tbaa !11
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %81

66:                                               ; preds = %63
  %67 = load ptr, ptr %16, align 8, !tbaa !5
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load i32, ptr %17, align 4, !tbaa !11
  %71 = sext i32 %70 to i64
  %72 = call i64 @xstrncpys(ptr noundef %67, i64 noundef %68, ptr noundef %69, i64 noundef %71)
  %73 = load i32, ptr %17, align 4, !tbaa !11
  %74 = sext i32 %73 to i64
  %75 = load i64, ptr %13, align 8, !tbaa !9
  %76 = sub i64 %75, %74
  store i64 %76, ptr %13, align 8, !tbaa !9
  %77 = load i32, ptr %17, align 4, !tbaa !11
  %78 = load ptr, ptr %16, align 8, !tbaa !5
  %79 = sext i32 %77 to i64
  %80 = getelementptr inbounds i8, ptr %78, i64 %79
  store ptr %80, ptr %16, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %66, %63
  %82 = load ptr, ptr %16, align 8, !tbaa !5
  %83 = load i64, ptr %13, align 8, !tbaa !9
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load i64, ptr %9, align 8, !tbaa !9
  %86 = call i64 @xstrncpys(ptr noundef %82, i64 noundef %83, ptr noundef %84, i64 noundef %85)
  %87 = load i64, ptr %9, align 8, !tbaa !9
  %88 = load i64, ptr %13, align 8, !tbaa !9
  %89 = sub i64 %88, %87
  store i64 %89, ptr %13, align 8, !tbaa !9
  %90 = load i64, ptr %9, align 8, !tbaa !9
  %91 = load ptr, ptr %16, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i64 %90
  store ptr %92, ptr %16, align 8, !tbaa !5
  %93 = load i32, ptr %17, align 4, !tbaa !11
  %94 = sext i32 %93 to i64
  %95 = load i64, ptr %10, align 8, !tbaa !9
  %96 = add i64 %94, %95
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i64 %96
  store ptr %98, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %15, align 4
  br label %99

99:                                               ; preds = %81, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  %100 = load i32, ptr %15, align 4
  switch i32 %100, label %110 [
    i32 0, label %101
    i32 5, label %102
  ]

101:                                              ; preds = %99
  br label %52, !llvm.loop !15

102:                                              ; preds = %99, %52
  %103 = load ptr, ptr %16, align 8, !tbaa !5
  %104 = load i64, ptr %13, align 8, !tbaa !9
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %103, i64 noundef %104, ptr noundef @.str.38, ptr noundef %105)
  %107 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %107, ptr %4, align 8
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %108

108:                                              ; preds = %102, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  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
  %109 = load ptr, ptr %4, align 8
  ret ptr %109

110:                                              ; preds = %99
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind allocsize(0) }

!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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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.38 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @xstrrep(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #3
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  br label %7

7:                                                ; preds = %7, %3
  %.055 = phi i32 [ 0, %3 ], [ %9, %7 ]
  %.053 = phi i32 [ 0, %3 ], [ %11, %7 ]
  %8 = zext nneg i32 %.055 to i64
  %9 = tail call i32 @xstrntokn(ptr noundef null, i64 noundef 0, ptr noundef %0, i64 noundef %4, i64 noundef %8, ptr noundef %1)
  %10 = icmp sgt i32 %9, 0
  %11 = add nuw nsw i32 %.053, 1
  br i1 %10, label %7, label %12, !llvm.loop !5

12:                                               ; preds = %7
  %13 = sub i64 %5, %6
  %14 = zext nneg i32 %.053 to i64
  %15 = mul i64 %13, %14
  %16 = add i64 %4, 1
  %17 = add i64 %16, %15
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #4
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %34, label %.preheader

.preheader:                                       ; preds = %12
  %.not5966 = icmp eq i32 %.053, 0
  br i1 %.not5966, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %._crit_edge
  %.in = phi i32 [ %19, %._crit_edge ], [ %.053, %.preheader ]
  %.04469 = phi ptr [ %30, %._crit_edge ], [ %18, %.preheader ]
  %.04668 = phi ptr [ %32, %._crit_edge ], [ %0, %.preheader ]
  %.04967 = phi i64 [ %29, %._crit_edge ], [ %17, %.preheader ]
  %19 = add nsw i32 %.in, -1
  %20 = tail call i32 @xstrsrc(ptr noundef %.04668, ptr noundef %1)
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %.thread, label %22

22:                                               ; preds = %.lr.ph
  %.not60 = icmp eq i32 %20, 0
  br i1 %.not60, label %._crit_edge, label %23

23:                                               ; preds = %22
  %24 = zext nneg i32 %20 to i64
  %25 = tail call i64 @xstrncpys(ptr noundef %.04469, i64 noundef %.04967, ptr noundef %.04668, i64 noundef %24)
  %26 = sub i64 %.04967, %24
  %27 = getelementptr inbounds i8, ptr %.04469, i64 %24
  br label %._crit_edge

._crit_edge:                                      ; preds = %22, %23
  %.pre-phi = phi i64 [ %24, %23 ], [ 0, %22 ]
  %.150 = phi i64 [ %26, %23 ], [ %.04967, %22 ]
  %.1 = phi ptr [ %27, %23 ], [ %.04469, %22 ]
  %28 = tail call i64 @xstrncpys(ptr noundef %.1, i64 noundef %.150, ptr noundef %2, i64 noundef %5)
  %29 = sub i64 %.150, %5
  %30 = getelementptr inbounds i8, ptr %.1, i64 %5
  %31 = add i64 %6, %.pre-phi
  %32 = getelementptr inbounds i8, ptr %.04668, i64 %31
  %.not59 = icmp eq i32 %19, 0
  br i1 %.not59, label %.thread, label %.lr.ph

.thread:                                          ; preds = %._crit_edge, %.lr.ph, %.preheader
  %.049.lcssa = phi i64 [ %17, %.preheader ], [ %.04967, %.lr.ph ], [ %29, %._crit_edge ]
  %.046.lcssa = phi ptr [ %0, %.preheader ], [ %.04668, %.lr.ph ], [ %32, %._crit_edge ]
  %.044.lcssa = phi ptr [ %18, %.preheader ], [ %.04469, %.lr.ph ], [ %30, %._crit_edge ]
  %33 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %.044.lcssa, i64 noundef %.049.lcssa, ptr noundef nonnull @.str.38, ptr noundef %.046.lcssa)
  br label %34

34:                                               ; preds = %12, %.thread
  ret ptr %18
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 willreturn memory(read) }
attributes #4 = { nounwind allocsize(0) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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